blob: c53b5462ed001ccb2dd541301ce3398210b2fa4a [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,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg53873f12016-05-03 16:52:04 +0300106 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee4772012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300152 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700170
Ying Xue7f2b8562014-01-15 10:23:45 +0800171 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200172 if (netdev) {
173 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800174 tmp = wiphy_to_rdev(
175 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200176 else
177 tmp = NULL;
178
Johannes Berg7fee4772012-06-15 14:09:58 +0200179 /* not wireless device -- return error */
180 if (!tmp)
181 return ERR_PTR(-EINVAL);
182
183 /* mismatch -- return error */
184 if (rdev && tmp != rdev)
185 return ERR_PTR(-EINVAL);
186
187 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
Johannes Berga9455402012-06-15 13:32:49 +0200189 }
190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (!rdev)
192 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200193
Johannes Berg4f7eff12012-06-15 14:14:22 +0200194 if (netns != wiphy_net(&rdev->wiphy))
195 return ERR_PTR(-ENODEV);
196
197 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200198}
199
200/*
201 * This function returns a pointer to the driver
202 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200203 *
204 * The result of this can be a PTR_ERR and hence must
205 * be checked with IS_ERR() for errors.
206 */
207static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200208cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200209{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200210 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200211}
212
Johannes Berg55682962007-09-20 13:09:35 -0400213/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300214static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400215 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
216 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700217 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200218 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200220 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530221 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100222 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
224 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
225
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200226 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
228 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
229 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100230 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200231 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400232
233 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
235 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100236
Eliad Pellere007b852011-11-24 18:13:56 +0200237 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
238 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100239
Johannes Bergb9454e82009-07-08 13:29:08 +0200240 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100241 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
242 .len = WLAN_MAX_KEY_LEN },
243 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
244 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
245 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200246 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200247 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100248
249 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
250 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
251 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
253 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100255 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
257 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
258 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
259 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100260 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100261 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200262 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800264 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100265 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700267 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
268 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
269
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300270 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
272 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200273 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
274 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100275 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300276
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800277 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700278 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700279
Johannes Berg6c739412011-11-03 09:27:01 +0100280 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200281
282 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
283 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
284 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100285 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
286 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200287
288 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_SSID_LEN },
290 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
291 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200292 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300293 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300294 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300295 [NL80211_ATTR_STA_FLAGS2] = {
296 .len = sizeof(struct nl80211_sta_flag_update),
297 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300298 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200301 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
302 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
303 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200304 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100305 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100306 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
307 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100308 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
309 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200310 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200311 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
313 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200314 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200315 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300316 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200317 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300318 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
319 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200320 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900321 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
322 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100323 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100324 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100325 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200326 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700327 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300328 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200329 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200330 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300331 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300332 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
334 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530336 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300337 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530338 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300339 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
343 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300344 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100345 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200346 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
347 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700348 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800349 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
351 .len = NL80211_HT_CAPABILITY_LEN
352 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100353 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530354 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530355 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200356 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700357 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300358 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000359 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700360 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100361 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
362 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530363 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
364 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200365 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
366 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100367 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100368 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
369 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
370 .len = NL80211_VHT_CAPABILITY_LEN,
371 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200372 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
373 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
374 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300375 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200376 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
377 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
378 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300379 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
380 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530381 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
382 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200383 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100384 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100385 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
387 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800388 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
389 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200390 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
391 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530392 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200393 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300394 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300395 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300396 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
397 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
398 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300399 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200400 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200401 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200402 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200403 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500404 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200405 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100406 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200407 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300408 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
409 .len = VHT_MUMIMO_GROUPS_DATA_LEN
410 },
411 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Johannes Berg55682962007-09-20 13:09:35 -0400412};
413
Johannes Berge31b8212010-10-05 19:39:30 +0200414/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000415static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200416 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200417 [NL80211_KEY_IDX] = { .type = NLA_U8 },
418 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200419 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200420 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200422 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100423 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
424};
425
426/* policy for the key default flags */
427static const struct nla_policy
428nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
429 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
430 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200431};
432
Johannes Bergff1b6e62011-05-04 15:37:28 +0200433/* policy for WoWLAN attributes */
434static const struct nla_policy
435nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
436 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
437 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
439 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200440 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
441 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
442 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
443 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100444 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300445 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100446};
447
448static const struct nla_policy
449nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
450 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
451 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
452 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
453 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
454 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
455 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
456 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
457 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
458 },
459 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
460 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
461 },
462 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
463 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
464 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200465};
466
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700467/* policy for coalesce rule attributes */
468static const struct nla_policy
469nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
470 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
471 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
472 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
473};
474
Johannes Berge5497d72011-07-05 16:35:40 +0200475/* policy for GTK rekey offload attributes */
476static const struct nla_policy
477nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
478 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
479 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
480 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
481};
482
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300483static const struct nla_policy
484nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200485 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300486 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700487 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300488};
489
Avraham Stern3b06d272015-10-12 09:51:34 +0300490static const struct nla_policy
491nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
492 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
493 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
494};
495
Arend van Spriel38de03d2016-03-02 20:37:18 +0100496static const struct nla_policy
497nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
498 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
499 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
500 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
501 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
502 },
503};
504
Johannes Berg97990a02013-04-19 01:02:55 +0200505static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
506 struct netlink_callback *cb,
507 struct cfg80211_registered_device **rdev,
508 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100509{
Johannes Berg67748892010-10-04 21:14:06 +0200510 int err;
511
Johannes Berg67748892010-10-04 21:14:06 +0200512 rtnl_lock();
513
Johannes Berg97990a02013-04-19 01:02:55 +0200514 if (!cb->args[0]) {
515 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
516 nl80211_fam.attrbuf, nl80211_fam.maxattr,
517 nl80211_policy);
518 if (err)
519 goto out_unlock;
520
521 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
522 nl80211_fam.attrbuf);
523 if (IS_ERR(*wdev)) {
524 err = PTR_ERR(*wdev);
525 goto out_unlock;
526 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800527 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200528 /* 0 is the first index - add 1 to parse only once */
529 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200530 cb->args[1] = (*wdev)->identifier;
531 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200532 /* subtract the 1 again here */
533 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200534 struct wireless_dev *tmp;
535
536 if (!wiphy) {
537 err = -ENODEV;
538 goto out_unlock;
539 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800540 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200541 *wdev = NULL;
542
Johannes Berg53873f12016-05-03 16:52:04 +0300543 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200544 if (tmp->identifier == cb->args[1]) {
545 *wdev = tmp;
546 break;
547 }
548 }
Johannes Berg97990a02013-04-19 01:02:55 +0200549
550 if (!*wdev) {
551 err = -ENODEV;
552 goto out_unlock;
553 }
Johannes Berg67748892010-10-04 21:14:06 +0200554 }
555
Johannes Berg67748892010-10-04 21:14:06 +0200556 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200557 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200558 rtnl_unlock();
559 return err;
560}
561
Johannes Berg97990a02013-04-19 01:02:55 +0200562static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200563{
Johannes Berg67748892010-10-04 21:14:06 +0200564 rtnl_unlock();
565}
566
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100567/* IE validation */
568static bool is_valid_ie_attr(const struct nlattr *attr)
569{
570 const u8 *pos;
571 int len;
572
573 if (!attr)
574 return true;
575
576 pos = nla_data(attr);
577 len = nla_len(attr);
578
579 while (len) {
580 u8 elemlen;
581
582 if (len < 2)
583 return false;
584 len -= 2;
585
586 elemlen = pos[1];
587 if (elemlen > len)
588 return false;
589
590 len -= elemlen;
591 pos += 2 + elemlen;
592 }
593
594 return true;
595}
596
Johannes Berg55682962007-09-20 13:09:35 -0400597/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000598static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400599 int flags, u8 cmd)
600{
601 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000602 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400603}
604
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400605static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100606 struct ieee80211_channel *chan,
607 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400608{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200609 /* Some channels must be completely excluded from the
610 * list to protect old user-space tools from breaking
611 */
612 if (!large && chan->flags &
613 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
614 return 0;
615
David S. Miller9360ffd2012-03-29 04:41:26 -0400616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
617 chan->center_freq))
618 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400619
David S. Miller9360ffd2012-03-29 04:41:26 -0400620 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
621 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
622 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200623 if (chan->flags & IEEE80211_CHAN_NO_IR) {
624 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
625 goto nla_put_failure;
626 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
627 goto nla_put_failure;
628 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100629 if (chan->flags & IEEE80211_CHAN_RADAR) {
630 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
631 goto nla_put_failure;
632 if (large) {
633 u32 time;
634
635 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
636
637 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
638 chan->dfs_state))
639 goto nla_put_failure;
640 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
641 time))
642 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100643 if (nla_put_u32(msg,
644 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
645 chan->dfs_cac_ms))
646 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100647 }
648 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400649
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100650 if (large) {
651 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
652 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
653 goto nla_put_failure;
654 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
655 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
656 goto nla_put_failure;
657 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
658 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
659 goto nla_put_failure;
660 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
661 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
662 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200663 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
664 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
665 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300666 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
667 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200668 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200669 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
670 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
671 goto nla_put_failure;
672 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
673 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
674 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100675 }
676
David S. Miller9360ffd2012-03-29 04:41:26 -0400677 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
678 DBM_TO_MBM(chan->max_power)))
679 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400680
681 return 0;
682
683 nla_put_failure:
684 return -ENOBUFS;
685}
686
Johannes Berg55682962007-09-20 13:09:35 -0400687/* netlink command implementations */
688
Johannes Bergb9454e82009-07-08 13:29:08 +0200689struct key_parse {
690 struct key_params p;
691 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200692 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200693 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100694 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200695};
696
697static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
698{
699 struct nlattr *tb[NL80211_KEY_MAX + 1];
700 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
701 nl80211_key_policy);
702 if (err)
703 return err;
704
705 k->def = !!tb[NL80211_KEY_DEFAULT];
706 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
707
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100708 if (k->def) {
709 k->def_uni = true;
710 k->def_multi = true;
711 }
712 if (k->defmgmt)
713 k->def_multi = true;
714
Johannes Bergb9454e82009-07-08 13:29:08 +0200715 if (tb[NL80211_KEY_IDX])
716 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
717
718 if (tb[NL80211_KEY_DATA]) {
719 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
720 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
721 }
722
723 if (tb[NL80211_KEY_SEQ]) {
724 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
725 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
726 }
727
728 if (tb[NL80211_KEY_CIPHER])
729 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
730
Johannes Berge31b8212010-10-05 19:39:30 +0200731 if (tb[NL80211_KEY_TYPE]) {
732 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
733 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
734 return -EINVAL;
735 }
736
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100737 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
738 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700739
Johannes Berg2da8f412012-01-20 13:52:37 +0100740 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
741 tb[NL80211_KEY_DEFAULT_TYPES],
742 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100743 if (err)
744 return err;
745
746 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
747 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
748 }
749
Johannes Bergb9454e82009-07-08 13:29:08 +0200750 return 0;
751}
752
753static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
754{
755 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
756 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
757 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
758 }
759
760 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
761 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
762 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
763 }
764
765 if (info->attrs[NL80211_ATTR_KEY_IDX])
766 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
767
768 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
769 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
770
771 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
772 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
773
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (k->def) {
775 k->def_uni = true;
776 k->def_multi = true;
777 }
778 if (k->defmgmt)
779 k->def_multi = true;
780
Johannes Berge31b8212010-10-05 19:39:30 +0200781 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
782 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
783 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
784 return -EINVAL;
785 }
786
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100787 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
788 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
789 int err = nla_parse_nested(
790 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
791 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
792 nl80211_key_default_policy);
793 if (err)
794 return err;
795
796 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
797 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
798 }
799
Johannes Bergb9454e82009-07-08 13:29:08 +0200800 return 0;
801}
802
803static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
804{
805 int err;
806
807 memset(k, 0, sizeof(*k));
808 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200809 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200810
811 if (info->attrs[NL80211_ATTR_KEY])
812 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
813 else
814 err = nl80211_parse_key_old(info, k);
815
816 if (err)
817 return err;
818
819 if (k->def && k->defmgmt)
820 return -EINVAL;
821
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100822 if (k->defmgmt) {
823 if (k->def_uni || !k->def_multi)
824 return -EINVAL;
825 }
826
Johannes Bergb9454e82009-07-08 13:29:08 +0200827 if (k->idx != -1) {
828 if (k->defmgmt) {
829 if (k->idx < 4 || k->idx > 5)
830 return -EINVAL;
831 } else if (k->def) {
832 if (k->idx < 0 || k->idx > 3)
833 return -EINVAL;
834 } else {
835 if (k->idx < 0 || k->idx > 5)
836 return -EINVAL;
837 }
838 }
839
840 return 0;
841}
842
Johannes Bergfffd0932009-07-08 14:22:54 +0200843static struct cfg80211_cached_keys *
844nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530845 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200846{
847 struct key_parse parse;
848 struct nlattr *key;
849 struct cfg80211_cached_keys *result;
850 int rem, err, def = 0;
851
852 result = kzalloc(sizeof(*result), GFP_KERNEL);
853 if (!result)
854 return ERR_PTR(-ENOMEM);
855
856 result->def = -1;
857 result->defmgmt = -1;
858
859 nla_for_each_nested(key, keys, rem) {
860 memset(&parse, 0, sizeof(parse));
861 parse.idx = -1;
862
863 err = nl80211_parse_key_new(key, &parse);
864 if (err)
865 goto error;
866 err = -EINVAL;
867 if (!parse.p.key)
868 goto error;
869 if (parse.idx < 0 || parse.idx > 4)
870 goto error;
871 if (parse.def) {
872 if (def)
873 goto error;
874 def = 1;
875 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100876 if (!parse.def_uni || !parse.def_multi)
877 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 } else if (parse.defmgmt)
879 goto error;
880 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200881 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 if (err)
883 goto error;
884 result->params[parse.idx].cipher = parse.p.cipher;
885 result->params[parse.idx].key_len = parse.p.key_len;
886 result->params[parse.idx].key = result->data[parse.idx];
887 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530888
889 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
890 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
891 if (no_ht)
892 *no_ht = true;
893 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200894 }
895
896 return result;
897 error:
898 kfree(result);
899 return ERR_PTR(err);
900}
901
902static int nl80211_key_allowed(struct wireless_dev *wdev)
903{
904 ASSERT_WDEV_LOCK(wdev);
905
Johannes Bergfffd0932009-07-08 14:22:54 +0200906 switch (wdev->iftype) {
907 case NL80211_IFTYPE_AP:
908 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200909 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700910 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200911 break;
912 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200913 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200914 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200915 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200916 return -ENOLINK;
917 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100918 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100919 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100920 case NL80211_IFTYPE_MONITOR:
921 case NL80211_IFTYPE_P2P_DEVICE:
922 case NL80211_IFTYPE_WDS:
923 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200924 return -EINVAL;
925 }
926
927 return 0;
928}
929
Jouni Malinen664834d2014-01-15 00:01:44 +0200930static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
931 struct nlattr *tb)
932{
933 struct ieee80211_channel *chan;
934
935 if (tb == NULL)
936 return NULL;
937 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
938 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
939 return NULL;
940 return chan;
941}
942
Johannes Berg7527a782011-05-13 10:58:57 +0200943static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
944{
945 struct nlattr *nl_modes = nla_nest_start(msg, attr);
946 int i;
947
948 if (!nl_modes)
949 goto nla_put_failure;
950
951 i = 0;
952 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400953 if ((ifmodes & 1) && nla_put_flag(msg, i))
954 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200955 ifmodes >>= 1;
956 i++;
957 }
958
959 nla_nest_end(msg, nl_modes);
960 return 0;
961
962nla_put_failure:
963 return -ENOBUFS;
964}
965
966static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100967 struct sk_buff *msg,
968 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200969{
970 struct nlattr *nl_combis;
971 int i, j;
972
973 nl_combis = nla_nest_start(msg,
974 NL80211_ATTR_INTERFACE_COMBINATIONS);
975 if (!nl_combis)
976 goto nla_put_failure;
977
978 for (i = 0; i < wiphy->n_iface_combinations; i++) {
979 const struct ieee80211_iface_combination *c;
980 struct nlattr *nl_combi, *nl_limits;
981
982 c = &wiphy->iface_combinations[i];
983
984 nl_combi = nla_nest_start(msg, i + 1);
985 if (!nl_combi)
986 goto nla_put_failure;
987
988 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
989 if (!nl_limits)
990 goto nla_put_failure;
991
992 for (j = 0; j < c->n_limits; j++) {
993 struct nlattr *nl_limit;
994
995 nl_limit = nla_nest_start(msg, j + 1);
996 if (!nl_limit)
997 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400998 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
999 c->limits[j].max))
1000 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001001 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1002 c->limits[j].types))
1003 goto nla_put_failure;
1004 nla_nest_end(msg, nl_limit);
1005 }
1006
1007 nla_nest_end(msg, nl_limits);
1008
David S. Miller9360ffd2012-03-29 04:41:26 -04001009 if (c->beacon_int_infra_match &&
1010 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1011 goto nla_put_failure;
1012 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1013 c->num_different_channels) ||
1014 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1015 c->max_interfaces))
1016 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001017 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001018 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1019 c->radar_detect_widths) ||
1020 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1021 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001022 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001023
1024 nla_nest_end(msg, nl_combi);
1025 }
1026
1027 nla_nest_end(msg, nl_combis);
1028
1029 return 0;
1030nla_put_failure:
1031 return -ENOBUFS;
1032}
1033
Johannes Berg3713b4e2013-02-14 16:19:38 +01001034#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001035static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1036 struct sk_buff *msg)
1037{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001038 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001039 struct nlattr *nl_tcp;
1040
1041 if (!tcp)
1042 return 0;
1043
1044 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1045 if (!nl_tcp)
1046 return -ENOBUFS;
1047
1048 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1049 tcp->data_payload_max))
1050 return -ENOBUFS;
1051
1052 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1053 tcp->data_payload_max))
1054 return -ENOBUFS;
1055
1056 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1057 return -ENOBUFS;
1058
1059 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1060 sizeof(*tcp->tok), tcp->tok))
1061 return -ENOBUFS;
1062
1063 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1064 tcp->data_interval_max))
1065 return -ENOBUFS;
1066
1067 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1068 tcp->wake_payload_max))
1069 return -ENOBUFS;
1070
1071 nla_nest_end(msg, nl_tcp);
1072 return 0;
1073}
1074
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001077 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078{
1079 struct nlattr *nl_wowlan;
1080
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001082 return 0;
1083
1084 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1085 if (!nl_wowlan)
1086 return -ENOBUFS;
1087
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001098 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001099 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001101 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001103 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1104 return -ENOBUFS;
1105
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001106 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001107 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001108 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1109 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1110 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1111 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001112 };
1113
1114 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1115 sizeof(pat), &pat))
1116 return -ENOBUFS;
1117 }
1118
Luciano Coelho75453cc2015-01-09 14:06:37 +02001119 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1120 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1121 rdev->wiphy.wowlan->max_nd_match_sets))
1122 return -ENOBUFS;
1123
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001124 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001125 return -ENOBUFS;
1126
Johannes Berg3713b4e2013-02-14 16:19:38 +01001127 nla_nest_end(msg, nl_wowlan);
1128
1129 return 0;
1130}
1131#endif
1132
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001133static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001135{
1136 struct nl80211_coalesce_rule_support rule;
1137
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001138 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001139 return 0;
1140
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001141 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1142 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1143 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1144 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1145 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1146 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001147
1148 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1149 return -ENOBUFS;
1150
1151 return 0;
1152}
1153
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1155 struct ieee80211_supported_band *sband)
1156{
1157 struct nlattr *nl_rates, *nl_rate;
1158 struct ieee80211_rate *rate;
1159 int i;
1160
1161 /* add HT info */
1162 if (sband->ht_cap.ht_supported &&
1163 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1164 sizeof(sband->ht_cap.mcs),
1165 &sband->ht_cap.mcs) ||
1166 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1167 sband->ht_cap.cap) ||
1168 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1169 sband->ht_cap.ampdu_factor) ||
1170 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1171 sband->ht_cap.ampdu_density)))
1172 return -ENOBUFS;
1173
1174 /* add VHT info */
1175 if (sband->vht_cap.vht_supported &&
1176 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1177 sizeof(sband->vht_cap.vht_mcs),
1178 &sband->vht_cap.vht_mcs) ||
1179 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1180 sband->vht_cap.cap)))
1181 return -ENOBUFS;
1182
1183 /* add bitrates */
1184 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1185 if (!nl_rates)
1186 return -ENOBUFS;
1187
1188 for (i = 0; i < sband->n_bitrates; i++) {
1189 nl_rate = nla_nest_start(msg, i);
1190 if (!nl_rate)
1191 return -ENOBUFS;
1192
1193 rate = &sband->bitrates[i];
1194 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1195 rate->bitrate))
1196 return -ENOBUFS;
1197 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1198 nla_put_flag(msg,
1199 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1200 return -ENOBUFS;
1201
1202 nla_nest_end(msg, nl_rate);
1203 }
1204
1205 nla_nest_end(msg, nl_rates);
1206
1207 return 0;
1208}
1209
1210static int
1211nl80211_send_mgmt_stypes(struct sk_buff *msg,
1212 const struct ieee80211_txrx_stypes *mgmt_stypes)
1213{
1214 u16 stypes;
1215 struct nlattr *nl_ftypes, *nl_ifs;
1216 enum nl80211_iftype ift;
1217 int i;
1218
1219 if (!mgmt_stypes)
1220 return 0;
1221
1222 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1223 if (!nl_ifs)
1224 return -ENOBUFS;
1225
1226 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1227 nl_ftypes = nla_nest_start(msg, ift);
1228 if (!nl_ftypes)
1229 return -ENOBUFS;
1230 i = 0;
1231 stypes = mgmt_stypes[ift].tx;
1232 while (stypes) {
1233 if ((stypes & 1) &&
1234 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1235 (i << 4) | IEEE80211_FTYPE_MGMT))
1236 return -ENOBUFS;
1237 stypes >>= 1;
1238 i++;
1239 }
1240 nla_nest_end(msg, nl_ftypes);
1241 }
1242
1243 nla_nest_end(msg, nl_ifs);
1244
1245 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1246 if (!nl_ifs)
1247 return -ENOBUFS;
1248
1249 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1250 nl_ftypes = nla_nest_start(msg, ift);
1251 if (!nl_ftypes)
1252 return -ENOBUFS;
1253 i = 0;
1254 stypes = mgmt_stypes[ift].rx;
1255 while (stypes) {
1256 if ((stypes & 1) &&
1257 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1258 (i << 4) | IEEE80211_FTYPE_MGMT))
1259 return -ENOBUFS;
1260 stypes >>= 1;
1261 i++;
1262 }
1263 nla_nest_end(msg, nl_ftypes);
1264 }
1265 nla_nest_end(msg, nl_ifs);
1266
1267 return 0;
1268}
1269
Johannes Berg86e8cf92013-06-19 10:57:22 +02001270struct nl80211_dump_wiphy_state {
1271 s64 filter_wiphy;
1272 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301273 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 bool split;
1275};
1276
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001278 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001280 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001281{
1282 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001283 struct nlattr *nl_bands, *nl_band;
1284 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001285 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001286 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001287 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001288 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001289 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001291 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001292
Johannes Berg3bb20552014-05-26 13:52:25 +02001293 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001294 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 return -ENOBUFS;
1296
Johannes Berg86e8cf92013-06-19 10:57:22 +02001297 if (WARN_ON(!state))
1298 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001299
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001303 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001305 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001306
Johannes Berg3bb20552014-05-26 13:52:25 +02001307 if (cmd != NL80211_CMD_NEW_WIPHY)
1308 goto finish;
1309
Johannes Berg86e8cf92013-06-19 10:57:22 +02001310 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 case 0:
1312 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001327 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001331 rdev->wiphy.max_match_sets) ||
1332 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1333 rdev->wiphy.max_sched_scan_plans) ||
1334 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1335 rdev->wiphy.max_sched_scan_plan_interval) ||
1336 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1337 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001338 goto nla_put_failure;
1339
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1342 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1345 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1348 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1351 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1354 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001356 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001357 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 state->split_start++;
1359 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 break;
1361 case 1:
1362 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001363 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1364 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001365 goto nla_put_failure;
1366
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001369 goto nla_put_failure;
1370
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1373 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001374
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001376 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001378 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001380
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001381 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001383 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001385
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001386 if ((rdev->wiphy.available_antennas_tx ||
1387 rdev->wiphy.available_antennas_rx) &&
1388 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 u32 tx_ant = 0, rx_ant = 0;
1390 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001391
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001392 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 if (!res) {
1394 if (nla_put_u32(msg,
1395 NL80211_ATTR_WIPHY_ANTENNA_TX,
1396 tx_ant) ||
1397 nla_put_u32(msg,
1398 NL80211_ATTR_WIPHY_ANTENNA_RX,
1399 rx_ant))
1400 goto nla_put_failure;
1401 }
Johannes Bergee688b002008-01-24 19:38:39 +01001402 }
1403
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->split_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 case 2:
1408 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001409 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001411 state->split_start++;
1412 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 break;
1414 case 3:
1415 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1416 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001417 goto nla_put_failure;
1418
Johannes Berg86e8cf92013-06-19 10:57:22 +02001419 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001420 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 struct ieee80211_supported_band *sband;
1422
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001423 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424
1425 if (!sband)
1426 continue;
1427
1428 nl_band = nla_nest_start(msg, band);
1429 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001430 goto nla_put_failure;
1431
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 case 0:
1434 if (nl80211_send_band_rateinfo(msg, sband))
1435 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 state->chan_start++;
1437 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 break;
1439 default:
1440 /* add frequencies */
1441 nl_freqs = nla_nest_start(
1442 msg, NL80211_BAND_ATTR_FREQS);
1443 if (!nl_freqs)
1444 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001445
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 i < sband->n_channels;
1448 i++) {
1449 nl_freq = nla_nest_start(msg, i);
1450 if (!nl_freq)
1451 goto nla_put_failure;
1452
1453 chan = &sband->channels[i];
1454
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 if (nl80211_msg_put_channel(
1456 msg, chan,
1457 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 goto nla_put_failure;
1459
1460 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001461 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 break;
1463 }
1464 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001465 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001467 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 nla_nest_end(msg, nl_freqs);
1469 }
1470
1471 nla_nest_end(msg, nl_band);
1472
Johannes Berg86e8cf92013-06-19 10:57:22 +02001473 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001475 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 band--;
1477 break;
1478 }
Johannes Bergee688b002008-01-24 19:38:39 +01001479 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001481
Johannes Berg57fbcce2016-04-12 15:56:15 +02001482 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001483 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001486
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001488 if (state->band_start == 0 && state->chan_start == 0)
1489 state->split_start++;
1490 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 break;
1492 case 4:
1493 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1494 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001495 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496
1497 i = 0;
1498#define CMD(op, n) \
1499 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001500 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 i++; \
1502 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1503 goto nla_put_failure; \
1504 } \
1505 } while (0)
1506
1507 CMD(add_virtual_intf, NEW_INTERFACE);
1508 CMD(change_virtual_intf, SET_INTERFACE);
1509 CMD(add_key, NEW_KEY);
1510 CMD(start_ap, START_AP);
1511 CMD(add_station, NEW_STATION);
1512 CMD(add_mpath, NEW_MPATH);
1513 CMD(update_mesh_config, SET_MESH_CONFIG);
1514 CMD(change_bss, SET_BSS);
1515 CMD(auth, AUTHENTICATE);
1516 CMD(assoc, ASSOCIATE);
1517 CMD(deauth, DEAUTHENTICATE);
1518 CMD(disassoc, DISASSOCIATE);
1519 CMD(join_ibss, JOIN_IBSS);
1520 CMD(join_mesh, JOIN_MESH);
1521 CMD(set_pmksa, SET_PMKSA);
1522 CMD(del_pmksa, DEL_PMKSA);
1523 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1526 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1527 CMD(mgmt_tx, FRAME);
1528 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 i++;
1531 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1532 goto nla_put_failure;
1533 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1535 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 i++;
1537 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1538 goto nla_put_failure;
1539 }
1540 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 CMD(tdls_mgmt, TDLS_MGMT);
1543 CMD(tdls_oper, TDLS_OPER);
1544 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 CMD(sched_scan_start, START_SCHED_SCAN);
1547 CMD(probe_client, PROBE_CLIENT);
1548 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550 i++;
1551 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1552 goto nla_put_failure;
1553 }
1554 CMD(start_p2p_device, START_P2P_DEVICE);
1555 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001556#ifdef CONFIG_NL80211_TESTMODE
1557 CMD(testmode_cmd, TESTMODE);
1558#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001560 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1561 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001563 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001564 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001565 if (rdev->wiphy.features &
1566 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001567 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001568 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001569 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001570#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001571
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 i++;
1574 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001575 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001576 }
1577
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 i++;
1580 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1581 goto nla_put_failure;
1582 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001583
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001585 state->split_start++;
1586 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 break;
1588 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if (rdev->ops->remain_on_channel &&
1590 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 nla_put_u32(msg,
1592 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001594 goto nla_put_failure;
1595
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1598 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001599
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1601 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split_start++;
1603 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 break;
1605 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001606#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 state->split_start++;
1610 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 break;
1612#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001613 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001614#endif
1615 case 7:
1616 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001617 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001618 goto nla_put_failure;
1619
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001621 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001623
Johannes Berg86e8cf92013-06-19 10:57:22 +02001624 state->split_start++;
1625 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 break;
1627 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001628 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001631 goto nla_put_failure;
1632
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001634 /*
1635 * We can only add the per-channel limit information if the
1636 * dump is split, otherwise it makes it too big. Therefore
1637 * only advertise it in that case.
1638 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001639 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001640 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1641 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 goto nla_put_failure;
1643
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001644 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1647 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 goto nla_put_failure;
1649
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1651 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001652 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001654 goto nla_put_failure;
1655
1656 /*
1657 * Any information below this point is only available to
1658 * applications that can deal with it being split. This
1659 * helps ensure that newly added capabilities don't break
1660 * older tools by overrunning their buffers.
1661 *
1662 * We still increment split_start so that in the split
1663 * case we'll continue with more data in the next round,
1664 * but break unconditionally so unsplit data stops here.
1665 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001666 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001667 break;
1668 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001669 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001670 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 rdev->wiphy.extended_capabilities_len,
1672 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001673 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 rdev->wiphy.extended_capabilities_len,
1675 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001676 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001677
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001678 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001679 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1681 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001682 goto nla_put_failure;
1683
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001684 state->split_start++;
1685 break;
1686 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001687 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001688 goto nla_put_failure;
1689
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001691 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1692 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1693 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001694
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001695 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001696 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001697 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001698 goto nla_put_failure;
1699
Johannes Bergad7e7182013-11-13 13:37:47 +01001700 state->split_start++;
1701 break;
1702 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001704 const struct nl80211_vendor_cmd_info *info;
1705 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001706
Johannes Berg567ffc32013-12-18 14:43:31 +01001707 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1708 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001709 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001710
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1712 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001713 if (nla_put(msg, i + 1, sizeof(*info), info))
1714 goto nla_put_failure;
1715 }
1716 nla_nest_end(msg, nested);
1717 }
1718
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001719 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001720 const struct nl80211_vendor_cmd_info *info;
1721 struct nlattr *nested;
1722
1723 nested = nla_nest_start(msg,
1724 NL80211_ATTR_VENDOR_EVENTS);
1725 if (!nested)
1726 goto nla_put_failure;
1727
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001728 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1729 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001730 if (nla_put(msg, i + 1, sizeof(*info), info))
1731 goto nla_put_failure;
1732 }
1733 nla_nest_end(msg, nested);
1734 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001735 state->split_start++;
1736 break;
1737 case 12:
1738 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1739 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1740 rdev->wiphy.max_num_csa_counters))
1741 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001742
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001743 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1744 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1745 goto nla_put_failure;
1746
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001747 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1748 sizeof(rdev->wiphy.ext_features),
1749 rdev->wiphy.ext_features))
1750 goto nla_put_failure;
1751
Arend van Spriel38de03d2016-03-02 20:37:18 +01001752 if (rdev->wiphy.bss_select_support) {
1753 struct nlattr *nested;
1754 u32 bss_select_support = rdev->wiphy.bss_select_support;
1755
1756 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1757 if (!nested)
1758 goto nla_put_failure;
1759
1760 i = 0;
1761 while (bss_select_support) {
1762 if ((bss_select_support & 1) &&
1763 nla_put_flag(msg, i))
1764 goto nla_put_failure;
1765 i++;
1766 bss_select_support >>= 1;
1767 }
1768 nla_nest_end(msg, nested);
1769 }
1770
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301771 state->split_start++;
1772 break;
1773 case 13:
1774 if (rdev->wiphy.num_iftype_ext_capab &&
1775 rdev->wiphy.iftype_ext_capab) {
1776 struct nlattr *nested_ext_capab, *nested;
1777
1778 nested = nla_nest_start(msg,
1779 NL80211_ATTR_IFTYPE_EXT_CAPA);
1780 if (!nested)
1781 goto nla_put_failure;
1782
1783 for (i = state->capa_start;
1784 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1785 const struct wiphy_iftype_ext_capab *capab;
1786
1787 capab = &rdev->wiphy.iftype_ext_capab[i];
1788
1789 nested_ext_capab = nla_nest_start(msg, i);
1790 if (!nested_ext_capab ||
1791 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1792 capab->iftype) ||
1793 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1794 capab->extended_capabilities_len,
1795 capab->extended_capabilities) ||
1796 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1797 capab->extended_capabilities_len,
1798 capab->extended_capabilities_mask))
1799 goto nla_put_failure;
1800
1801 nla_nest_end(msg, nested_ext_capab);
1802 if (state->split)
1803 break;
1804 }
1805 nla_nest_end(msg, nested);
1806 if (i < rdev->wiphy.num_iftype_ext_capab) {
1807 state->capa_start = i + 1;
1808 break;
1809 }
1810 }
1811
Johannes Berg3713b4e2013-02-14 16:19:38 +01001812 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001815 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001816 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001817 genlmsg_end(msg, hdr);
1818 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001819
1820 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001821 genlmsg_cancel(msg, hdr);
1822 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001823}
1824
Johannes Berg86e8cf92013-06-19 10:57:22 +02001825static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1826 struct netlink_callback *cb,
1827 struct nl80211_dump_wiphy_state *state)
1828{
1829 struct nlattr **tb = nl80211_fam.attrbuf;
1830 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1831 tb, nl80211_fam.maxattr, nl80211_policy);
1832 /* ignore parse errors for backward compatibility */
1833 if (ret)
1834 return 0;
1835
1836 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1837 if (tb[NL80211_ATTR_WIPHY])
1838 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1839 if (tb[NL80211_ATTR_WDEV])
1840 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1841 if (tb[NL80211_ATTR_IFINDEX]) {
1842 struct net_device *netdev;
1843 struct cfg80211_registered_device *rdev;
1844 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1845
Ying Xue7f2b8562014-01-15 10:23:45 +08001846 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001847 if (!netdev)
1848 return -ENODEV;
1849 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001850 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001851 netdev->ieee80211_ptr->wiphy);
1852 state->filter_wiphy = rdev->wiphy_idx;
1853 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001854 }
1855
1856 return 0;
1857}
1858
Johannes Berg55682962007-09-20 13:09:35 -04001859static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1860{
Johannes Berg645e77d2013-03-01 14:03:49 +01001861 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001862 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001863 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001864
Johannes Berg5fe231e2013-05-08 21:45:15 +02001865 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001866 if (!state) {
1867 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001868 if (!state) {
1869 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001870 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001871 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001872 state->filter_wiphy = -1;
1873 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1874 if (ret) {
1875 kfree(state);
1876 rtnl_unlock();
1877 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001878 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001879 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001880 }
1881
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001882 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1883 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001884 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001885 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001886 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001887 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001888 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001889 continue;
1890 /* attempt to fit multiple wiphy data chunks into the skb */
1891 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001892 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1893 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001894 NETLINK_CB(cb->skb).portid,
1895 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001896 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001897 if (ret < 0) {
1898 /*
1899 * If sending the wiphy data didn't fit (ENOBUFS
1900 * or EMSGSIZE returned), this SKB is still
1901 * empty (so it's not too big because another
1902 * wiphy dataset is already in the skb) and
1903 * we've not tried to adjust the dump allocation
1904 * yet ... then adjust the alloc size to be
1905 * bigger, and return 1 but with the empty skb.
1906 * This results in an empty message being RX'ed
1907 * in userspace, but that is ignored.
1908 *
1909 * We can then retry with the larger buffer.
1910 */
1911 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001912 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001913 cb->min_dump_alloc < 4096) {
1914 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001915 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001916 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001917 return 1;
1918 }
1919 idx--;
1920 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001921 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001922 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001923 break;
Johannes Berg55682962007-09-20 13:09:35 -04001924 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001925 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001926
Johannes Berg86e8cf92013-06-19 10:57:22 +02001927 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001928
1929 return skb->len;
1930}
1931
Johannes Berg86e8cf92013-06-19 10:57:22 +02001932static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1933{
1934 kfree((void *)cb->args[0]);
1935 return 0;
1936}
1937
Johannes Berg55682962007-09-20 13:09:35 -04001938static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1939{
1940 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001942 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001943
Johannes Berg645e77d2013-03-01 14:03:49 +01001944 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001945 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001946 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001947
Johannes Berg3bb20552014-05-26 13:52:25 +02001948 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1949 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001950 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001951 nlmsg_free(msg);
1952 return -ENOBUFS;
1953 }
Johannes Berg55682962007-09-20 13:09:35 -04001954
Johannes Berg134e6372009-07-10 09:51:34 +00001955 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001956}
1957
Jouni Malinen31888482008-10-30 16:59:24 +02001958static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1959 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1960 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1961 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1962 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1963 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1964};
1965
1966static int parse_txq_params(struct nlattr *tb[],
1967 struct ieee80211_txq_params *txq_params)
1968{
Johannes Berga3304b02012-03-28 11:04:24 +02001969 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001970 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1971 !tb[NL80211_TXQ_ATTR_AIFS])
1972 return -EINVAL;
1973
Johannes Berga3304b02012-03-28 11:04:24 +02001974 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001975 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1976 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1977 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1978 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1979
Johannes Berga3304b02012-03-28 11:04:24 +02001980 if (txq_params->ac >= NL80211_NUM_ACS)
1981 return -EINVAL;
1982
Jouni Malinen31888482008-10-30 16:59:24 +02001983 return 0;
1984}
1985
Johannes Bergf444de02010-05-05 15:25:02 +02001986static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1987{
1988 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001989 * You can only set the channel explicitly for WDS interfaces,
1990 * all others have their channel managed via their respective
1991 * "establish a connection" command (connect, join, ...)
1992 *
1993 * For AP/GO and mesh mode, the channel can be set with the
1994 * channel userspace API, but is only stored and passed to the
1995 * low-level driver when the AP starts or the mesh is joined.
1996 * This is for backward compatibility, userspace can also give
1997 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001998 *
1999 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002000 * whatever else is going on, so they have their own special
2001 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002002 */
2003 return !wdev ||
2004 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002005 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002006 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2007 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002008}
2009
Johannes Berg683b6d32012-11-08 21:25:48 +01002010static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2011 struct genl_info *info,
2012 struct cfg80211_chan_def *chandef)
2013{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302014 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002015
2016 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2017 return -EINVAL;
2018
2019 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2020
2021 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002022 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2023 chandef->center_freq1 = control_freq;
2024 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002025
2026 /* Primary channel not allowed */
2027 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2028 return -EINVAL;
2029
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002030 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2031 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002032
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002033 chantype = nla_get_u32(
2034 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2035
2036 switch (chantype) {
2037 case NL80211_CHAN_NO_HT:
2038 case NL80211_CHAN_HT20:
2039 case NL80211_CHAN_HT40PLUS:
2040 case NL80211_CHAN_HT40MINUS:
2041 cfg80211_chandef_create(chandef, chandef->chan,
2042 chantype);
2043 break;
2044 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002045 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002046 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002047 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2048 chandef->width =
2049 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2050 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2051 chandef->center_freq1 =
2052 nla_get_u32(
2053 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2054 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2055 chandef->center_freq2 =
2056 nla_get_u32(
2057 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2058 }
2059
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002060 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002061 return -EINVAL;
2062
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002063 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2064 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002065 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002066
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002067 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2068 chandef->width == NL80211_CHAN_WIDTH_10) &&
2069 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2070 return -EINVAL;
2071
Johannes Berg683b6d32012-11-08 21:25:48 +01002072 return 0;
2073}
2074
Johannes Bergf444de02010-05-05 15:25:02 +02002075static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002076 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002077 struct genl_info *info)
2078{
Johannes Berg683b6d32012-11-08 21:25:48 +01002079 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002080 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002081 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002082 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002083
Jouni Malinene16821b2014-04-28 11:22:08 +03002084 if (dev)
2085 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002086 if (!nl80211_can_set_dev_channel(wdev))
2087 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002088 if (wdev)
2089 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002090
Johannes Berg683b6d32012-11-08 21:25:48 +01002091 result = nl80211_parse_chandef(rdev, info, &chandef);
2092 if (result)
2093 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002094
Johannes Berge8c9bd52012-06-06 08:18:22 +02002095 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002096 case NL80211_IFTYPE_AP:
2097 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002098 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2099 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002100 result = -EINVAL;
2101 break;
2102 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002103 if (wdev->beacon_interval) {
2104 if (!dev || !rdev->ops->set_ap_chanwidth ||
2105 !(rdev->wiphy.features &
2106 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2107 result = -EBUSY;
2108 break;
2109 }
2110
2111 /* Only allow dynamic channel width changes */
2112 if (chandef.chan != wdev->preset_chandef.chan) {
2113 result = -EBUSY;
2114 break;
2115 }
2116 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2117 if (result)
2118 break;
2119 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002120 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002121 result = 0;
2122 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002123 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002124 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002125 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002126 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002127 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002128 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002129 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002130 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002131 }
Johannes Bergf444de02010-05-05 15:25:02 +02002132
2133 return result;
2134}
2135
2136static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2137{
Johannes Berg4c476992010-10-04 21:36:35 +02002138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2139 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002140
Jouni Malinene16821b2014-04-28 11:22:08 +03002141 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002142}
2143
Bill Jordane8347eb2010-10-01 13:54:28 -04002144static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2145{
Johannes Berg43b19952010-10-07 13:10:30 +02002146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2147 struct net_device *dev = info->user_ptr[1];
2148 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002149 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002150
2151 if (!info->attrs[NL80211_ATTR_MAC])
2152 return -EINVAL;
2153
Johannes Berg43b19952010-10-07 13:10:30 +02002154 if (netif_running(dev))
2155 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002156
Johannes Berg43b19952010-10-07 13:10:30 +02002157 if (!rdev->ops->set_wds_peer)
2158 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002159
Johannes Berg43b19952010-10-07 13:10:30 +02002160 if (wdev->iftype != NL80211_IFTYPE_WDS)
2161 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002162
2163 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002164 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002165}
2166
Johannes Berg55682962007-09-20 13:09:35 -04002167static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2168{
2169 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002170 struct net_device *netdev = NULL;
2171 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002172 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002173 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002174 u32 changed;
2175 u8 retry_short = 0, retry_long = 0;
2176 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002177 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002178
Johannes Berg5fe231e2013-05-08 21:45:15 +02002179 ASSERT_RTNL();
2180
Johannes Bergf444de02010-05-05 15:25:02 +02002181 /*
2182 * Try to find the wiphy and netdev. Normally this
2183 * function shouldn't need the netdev, but this is
2184 * done for backward compatibility -- previously
2185 * setting the channel was done per wiphy, but now
2186 * it is per netdev. Previous userland like hostapd
2187 * also passed a netdev to set_wiphy, so that it is
2188 * possible to let that go to the right netdev!
2189 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002190
Johannes Bergf444de02010-05-05 15:25:02 +02002191 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2192 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2193
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002195 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002196 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002197 else
Johannes Bergf444de02010-05-05 15:25:02 +02002198 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002199 }
2200
Johannes Bergf444de02010-05-05 15:25:02 +02002201 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002202 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2203 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002204 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002205 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002206 wdev = NULL;
2207 netdev = NULL;
2208 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002209 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002210 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002211
2212 /*
2213 * end workaround code, by now the rdev is available
2214 * and locked, and wdev may or may not be NULL.
2215 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002216
2217 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002218 result = cfg80211_dev_rename(
2219 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002220
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002221 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002222 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002223
Jouni Malinen31888482008-10-30 16:59:24 +02002224 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2225 struct ieee80211_txq_params txq_params;
2226 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2227
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 if (!rdev->ops->set_txq_params)
2229 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002230
Ying Xue7f2b8562014-01-15 10:23:45 +08002231 if (!netdev)
2232 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002233
Johannes Berg133a3ff2011-11-03 14:50:13 +01002234 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002235 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2236 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002237
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 if (!netif_running(netdev))
2239 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002240
Jouni Malinen31888482008-10-30 16:59:24 +02002241 nla_for_each_nested(nl_txq_params,
2242 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2243 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002244 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2245 nla_data(nl_txq_params),
2246 nla_len(nl_txq_params),
2247 txq_params_policy);
2248 if (result)
2249 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002250 result = parse_txq_params(tb, &txq_params);
2251 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002252 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002253
Hila Gonene35e4d22012-06-27 17:19:42 +03002254 result = rdev_set_txq_params(rdev, netdev,
2255 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002256 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002257 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002258 }
2259 }
2260
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002261 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002262 result = __nl80211_set_channel(
2263 rdev,
2264 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2265 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002266 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002267 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002268 }
2269
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002270 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002271 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002272 enum nl80211_tx_power_setting type;
2273 int idx, mbm = 0;
2274
Johannes Bergc8442112012-10-24 10:17:18 +02002275 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2276 txp_wdev = NULL;
2277
Ying Xue7f2b8562014-01-15 10:23:45 +08002278 if (!rdev->ops->set_tx_power)
2279 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002280
2281 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2282 type = nla_get_u32(info->attrs[idx]);
2283
2284 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002285 (type != NL80211_TX_POWER_AUTOMATIC))
2286 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002287
2288 if (type != NL80211_TX_POWER_AUTOMATIC) {
2289 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2290 mbm = nla_get_u32(info->attrs[idx]);
2291 }
2292
Johannes Bergc8442112012-10-24 10:17:18 +02002293 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002294 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002295 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002296 }
2297
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002298 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2299 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2300 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002301
Bruno Randolf7f531e02010-12-16 11:30:22 +09002302 if ((!rdev->wiphy.available_antennas_tx &&
2303 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002304 !rdev->ops->set_antenna)
2305 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002306
2307 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2308 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2309
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002310 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002311 * available antenna masks, except for the "all" mask */
2312 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002313 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2314 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002315
Bruno Randolf7f531e02010-12-16 11:30:22 +09002316 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2317 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002318
Hila Gonene35e4d22012-06-27 17:19:42 +03002319 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002320 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002322 }
2323
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002324 changed = 0;
2325
2326 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2327 retry_short = nla_get_u8(
2328 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 if (retry_short == 0)
2330 return -EINVAL;
2331
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002332 changed |= WIPHY_PARAM_RETRY_SHORT;
2333 }
2334
2335 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2336 retry_long = nla_get_u8(
2337 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002338 if (retry_long == 0)
2339 return -EINVAL;
2340
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002341 changed |= WIPHY_PARAM_RETRY_LONG;
2342 }
2343
2344 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2345 frag_threshold = nla_get_u32(
2346 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002347 if (frag_threshold < 256)
2348 return -EINVAL;
2349
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002350 if (frag_threshold != (u32) -1) {
2351 /*
2352 * Fragments (apart from the last one) are required to
2353 * have even length. Make the fragmentation code
2354 * simpler by stripping LSB should someone try to use
2355 * odd threshold value.
2356 */
2357 frag_threshold &= ~0x1;
2358 }
2359 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2360 }
2361
2362 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2363 rts_threshold = nla_get_u32(
2364 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2365 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2366 }
2367
Lukáš Turek81077e82009-12-21 22:50:47 +01002368 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002369 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2370 return -EINVAL;
2371
Lukáš Turek81077e82009-12-21 22:50:47 +01002372 coverage_class = nla_get_u8(
2373 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2374 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2375 }
2376
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002377 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2378 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2379 return -EOPNOTSUPP;
2380
2381 changed |= WIPHY_PARAM_DYN_ACK;
2382 }
2383
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002384 if (changed) {
2385 u8 old_retry_short, old_retry_long;
2386 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002387 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002388
Ying Xue7f2b8562014-01-15 10:23:45 +08002389 if (!rdev->ops->set_wiphy_params)
2390 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002391
2392 old_retry_short = rdev->wiphy.retry_short;
2393 old_retry_long = rdev->wiphy.retry_long;
2394 old_frag_threshold = rdev->wiphy.frag_threshold;
2395 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002396 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002397
2398 if (changed & WIPHY_PARAM_RETRY_SHORT)
2399 rdev->wiphy.retry_short = retry_short;
2400 if (changed & WIPHY_PARAM_RETRY_LONG)
2401 rdev->wiphy.retry_long = retry_long;
2402 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2403 rdev->wiphy.frag_threshold = frag_threshold;
2404 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2405 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002406 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2407 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002408
Hila Gonene35e4d22012-06-27 17:19:42 +03002409 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002410 if (result) {
2411 rdev->wiphy.retry_short = old_retry_short;
2412 rdev->wiphy.retry_long = old_retry_long;
2413 rdev->wiphy.frag_threshold = old_frag_threshold;
2414 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002415 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002416 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002417 }
2418 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002419 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002420}
2421
Johannes Berg71bbc992012-06-15 15:30:18 +02002422static inline u64 wdev_id(struct wireless_dev *wdev)
2423{
2424 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002425 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002426}
Johannes Berg55682962007-09-20 13:09:35 -04002427
Johannes Berg683b6d32012-11-08 21:25:48 +01002428static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002429 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002430{
Johannes Berg601555c2014-11-27 17:26:56 +01002431 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2432 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002433
Johannes Berg683b6d32012-11-08 21:25:48 +01002434 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2435 chandef->chan->center_freq))
2436 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002437 switch (chandef->width) {
2438 case NL80211_CHAN_WIDTH_20_NOHT:
2439 case NL80211_CHAN_WIDTH_20:
2440 case NL80211_CHAN_WIDTH_40:
2441 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2442 cfg80211_get_chandef_type(chandef)))
2443 return -ENOBUFS;
2444 break;
2445 default:
2446 break;
2447 }
2448 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2449 return -ENOBUFS;
2450 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2451 return -ENOBUFS;
2452 if (chandef->center_freq2 &&
2453 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002454 return -ENOBUFS;
2455 return 0;
2456}
2457
Eric W. Biederman15e47302012-09-07 20:12:54 +00002458static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002459 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002460 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002461{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002462 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002463 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002464 void *hdr;
2465
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002466 if (removal)
2467 cmd = NL80211_CMD_DEL_INTERFACE;
2468
2469 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002470 if (!hdr)
2471 return -1;
2472
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002473 if (dev &&
2474 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002475 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002476 goto nla_put_failure;
2477
2478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2479 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002480 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2481 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002482 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002483 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2484 rdev->devlist_generation ^
2485 (cfg80211_rdev_list_generation << 2)))
2486 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002487
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002488 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002489 int ret;
2490 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002491
Johannes Berg683b6d32012-11-08 21:25:48 +01002492 ret = rdev_get_channel(rdev, wdev, &chandef);
2493 if (ret == 0) {
2494 if (nl80211_send_chandef(msg, &chandef))
2495 goto nla_put_failure;
2496 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002497 }
2498
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002499 if (rdev->ops->get_tx_power) {
2500 int dbm, ret;
2501
2502 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2503 if (ret == 0 &&
2504 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2505 DBM_TO_MBM(dbm)))
2506 goto nla_put_failure;
2507 }
2508
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002509 if (wdev->ssid_len) {
2510 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2511 goto nla_put_failure;
2512 }
2513
Johannes Berg053c0952015-01-16 22:09:00 +01002514 genlmsg_end(msg, hdr);
2515 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002516
2517 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002518 genlmsg_cancel(msg, hdr);
2519 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002520}
2521
2522static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2523{
2524 int wp_idx = 0;
2525 int if_idx = 0;
2526 int wp_start = cb->args[0];
2527 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002528 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002529 struct wireless_dev *wdev;
2530
Johannes Berg5fe231e2013-05-08 21:45:15 +02002531 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002532 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2533 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002534 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002535 if (wp_idx < wp_start) {
2536 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002537 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002538 }
Johannes Berg55682962007-09-20 13:09:35 -04002539 if_idx = 0;
2540
Johannes Berg53873f12016-05-03 16:52:04 +03002541 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002542 if (if_idx < if_start) {
2543 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002544 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002545 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002546 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002547 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002548 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002549 goto out;
2550 }
2551 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002552 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002553
2554 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002555 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002556 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002557 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002558
2559 cb->args[0] = wp_idx;
2560 cb->args[1] = if_idx;
2561
2562 return skb->len;
2563}
2564
2565static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2566{
2567 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002569 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002570
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002571 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002572 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002573 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002574
Eric W. Biederman15e47302012-09-07 20:12:54 +00002575 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002576 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002577 nlmsg_free(msg);
2578 return -ENOBUFS;
2579 }
Johannes Berg55682962007-09-20 13:09:35 -04002580
Johannes Berg134e6372009-07-10 09:51:34 +00002581 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002582}
2583
Michael Wu66f7ac52008-01-31 19:48:22 +01002584static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2585 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2586 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2587 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2588 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2589 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002590 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002591};
2592
2593static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2594{
2595 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2596 int flag;
2597
2598 *mntrflags = 0;
2599
2600 if (!nla)
2601 return -EINVAL;
2602
2603 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2604 nla, mntr_flags_policy))
2605 return -EINVAL;
2606
2607 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2608 if (flags[flag])
2609 *mntrflags |= (1<<flag);
2610
2611 return 0;
2612}
2613
Johannes Berg9bc383d2009-11-19 11:55:19 +01002614static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002615 struct net_device *netdev, u8 use_4addr,
2616 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002617{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002618 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002619 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002620 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002621 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002622 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002623
2624 switch (iftype) {
2625 case NL80211_IFTYPE_AP_VLAN:
2626 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2627 return 0;
2628 break;
2629 case NL80211_IFTYPE_STATION:
2630 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2631 return 0;
2632 break;
2633 default:
2634 break;
2635 }
2636
2637 return -EOPNOTSUPP;
2638}
2639
Johannes Berg55682962007-09-20 13:09:35 -04002640static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2641{
Johannes Berg4c476992010-10-04 21:36:35 +02002642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002643 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002644 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002645 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002646 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002647 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002648 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002649
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002650 memset(&params, 0, sizeof(params));
2651
Johannes Berg04a773a2009-04-19 21:24:32 +02002652 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002653
Johannes Berg723b0382008-09-16 20:22:09 +02002654 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002655 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002656 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002657 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (ntype > NL80211_IFTYPE_MAX)
2659 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002660 }
2661
Johannes Berg92ffe052008-09-16 20:39:36 +02002662 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002663 struct wireless_dev *wdev = dev->ieee80211_ptr;
2664
Johannes Berg4c476992010-10-04 21:36:35 +02002665 if (ntype != NL80211_IFTYPE_MESH_POINT)
2666 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002667 if (netif_running(dev))
2668 return -EBUSY;
2669
2670 wdev_lock(wdev);
2671 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2672 IEEE80211_MAX_MESH_ID_LEN);
2673 wdev->mesh_id_up_len =
2674 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2675 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2676 wdev->mesh_id_up_len);
2677 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002678 }
2679
Felix Fietkau8b787642009-11-10 18:53:10 +01002680 if (info->attrs[NL80211_ATTR_4ADDR]) {
2681 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2682 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002683 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002684 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002685 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002686 } else {
2687 params.use_4addr = -1;
2688 }
2689
Johannes Berg92ffe052008-09-16 20:39:36 +02002690 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002691 if (ntype != NL80211_IFTYPE_MONITOR)
2692 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002693 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2694 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002695 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002696 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002697
2698 flags = &_flags;
2699 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002700 }
Johannes Berg3b858752009-03-12 09:55:09 +01002701
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002702 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2703 const u8 *mumimo_groups;
2704 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2705
2706 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2707 return -EOPNOTSUPP;
2708
2709 mumimo_groups =
2710 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2711
2712 /* bits 0 and 63 are reserved and must be zero */
2713 if ((mumimo_groups[0] & BIT(7)) ||
2714 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2715 return -EINVAL;
2716
2717 memcpy(params.vht_mumimo_groups, mumimo_groups,
2718 VHT_MUMIMO_GROUPS_DATA_LEN);
2719 change = true;
2720 }
2721
2722 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2723 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2724
2725 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2726 return -EOPNOTSUPP;
2727
2728 nla_memcpy(params.macaddr,
2729 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2730 ETH_ALEN);
2731 change = true;
2732 }
2733
Luciano Coelho18003292013-08-29 13:26:57 +03002734 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002735 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2736 return -EOPNOTSUPP;
2737
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002738 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002739 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002740 else
2741 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002742
Johannes Berg9bc383d2009-11-19 11:55:19 +01002743 if (!err && params.use_4addr != -1)
2744 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2745
Johannes Berg55682962007-09-20 13:09:35 -04002746 return err;
2747}
2748
2749static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2750{
Johannes Berg4c476992010-10-04 21:36:35 +02002751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002752 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002753 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002754 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002755 int err;
2756 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002757 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002758
Johannes Berg78f22b62014-03-24 17:57:27 +01002759 /* to avoid failing a new interface creation due to pending removal */
2760 cfg80211_destroy_ifaces(rdev);
2761
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002762 memset(&params, 0, sizeof(params));
2763
Johannes Berg55682962007-09-20 13:09:35 -04002764 if (!info->attrs[NL80211_ATTR_IFNAME])
2765 return -EINVAL;
2766
2767 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2768 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2769 if (type > NL80211_IFTYPE_MAX)
2770 return -EINVAL;
2771 }
2772
Johannes Berg79c97e92009-07-07 03:56:12 +02002773 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002774 !(rdev->wiphy.interface_modes & (1 << type)))
2775 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002776
Ben Greeare8f479b2014-10-22 12:23:05 -07002777 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2778 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2779 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002780 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2781 ETH_ALEN);
2782 if (!is_valid_ether_addr(params.macaddr))
2783 return -EADDRNOTAVAIL;
2784 }
2785
Johannes Berg9bc383d2009-11-19 11:55:19 +01002786 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002787 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002788 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002789 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002790 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002791 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002792
Michael Wu66f7ac52008-01-31 19:48:22 +01002793 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2794 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2795 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002796
Luciano Coelho18003292013-08-29 13:26:57 +03002797 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002798 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2799 return -EOPNOTSUPP;
2800
Johannes Berga18c7192015-02-24 10:56:42 +01002801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2802 if (!msg)
2803 return -ENOMEM;
2804
Hila Gonene35e4d22012-06-27 17:19:42 +03002805 wdev = rdev_add_virtual_intf(rdev,
2806 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002807 NET_NAME_USER, type, err ? NULL : &flags,
2808 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002809 if (WARN_ON(!wdev)) {
2810 nlmsg_free(msg);
2811 return -EPROTO;
2812 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002813 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002814 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002815 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002816
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002817 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002818 wdev->owner_nlportid = info->snd_portid;
2819
Johannes Berg98104fde2012-06-16 00:19:54 +02002820 switch (type) {
2821 case NL80211_IFTYPE_MESH_POINT:
2822 if (!info->attrs[NL80211_ATTR_MESH_ID])
2823 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002824 wdev_lock(wdev);
2825 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2826 IEEE80211_MAX_MESH_ID_LEN);
2827 wdev->mesh_id_up_len =
2828 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2829 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2830 wdev->mesh_id_up_len);
2831 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002832 break;
2833 case NL80211_IFTYPE_P2P_DEVICE:
2834 /*
2835 * P2P Device doesn't have a netdev, so doesn't go
2836 * through the netdev notifier and must be added here
2837 */
2838 mutex_init(&wdev->mtx);
2839 INIT_LIST_HEAD(&wdev->event_list);
2840 spin_lock_init(&wdev->event_lock);
2841 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2842 spin_lock_init(&wdev->mgmt_registrations_lock);
2843
Johannes Berg98104fde2012-06-16 00:19:54 +02002844 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002845 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002846 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002847 break;
2848 default:
2849 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002850 }
2851
Eric W. Biederman15e47302012-09-07 20:12:54 +00002852 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002853 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002854 nlmsg_free(msg);
2855 return -ENOBUFS;
2856 }
2857
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002858 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2859 if (event) {
2860 if (nl80211_send_iface(event, 0, 0, 0,
2861 rdev, wdev, false) < 0) {
2862 nlmsg_free(event);
2863 goto out;
2864 }
2865
2866 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2867 event, 0, NL80211_MCGRP_CONFIG,
2868 GFP_KERNEL);
2869 }
2870
2871out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002872 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002873}
2874
2875static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2876{
Johannes Berg4c476992010-10-04 21:36:35 +02002877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002878 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002879 struct sk_buff *msg;
2880 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002881
Johannes Berg4c476992010-10-04 21:36:35 +02002882 if (!rdev->ops->del_virtual_intf)
2883 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002884
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002885 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2886 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2887 nlmsg_free(msg);
2888 msg = NULL;
2889 }
2890
Johannes Berg84efbb82012-06-16 00:00:26 +02002891 /*
2892 * If we remove a wireless device without a netdev then clear
2893 * user_ptr[1] so that nl80211_post_doit won't dereference it
2894 * to check if it needs to do dev_put(). Otherwise it crashes
2895 * since the wdev has been freed, unlike with a netdev where
2896 * we need the dev_put() for the netdev to really be freed.
2897 */
2898 if (!wdev->netdev)
2899 info->user_ptr[1] = NULL;
2900
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002901 status = rdev_del_virtual_intf(rdev, wdev);
2902 if (status >= 0 && msg)
2903 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2904 msg, 0, NL80211_MCGRP_CONFIG,
2905 GFP_KERNEL);
2906 else
2907 nlmsg_free(msg);
2908
2909 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002910}
2911
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002912static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2913{
2914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2915 struct net_device *dev = info->user_ptr[1];
2916 u16 noack_map;
2917
2918 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2919 return -EINVAL;
2920
2921 if (!rdev->ops->set_noack_map)
2922 return -EOPNOTSUPP;
2923
2924 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2925
Hila Gonene35e4d22012-06-27 17:19:42 +03002926 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002927}
2928
Johannes Berg41ade002007-12-19 02:03:29 +01002929struct get_key_cookie {
2930 struct sk_buff *msg;
2931 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002932 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002933};
2934
2935static void get_key_callback(void *c, struct key_params *params)
2936{
Johannes Bergb9454e82009-07-08 13:29:08 +02002937 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002938 struct get_key_cookie *cookie = c;
2939
David S. Miller9360ffd2012-03-29 04:41:26 -04002940 if ((params->key &&
2941 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2942 params->key_len, params->key)) ||
2943 (params->seq &&
2944 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2945 params->seq_len, params->seq)) ||
2946 (params->cipher &&
2947 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2948 params->cipher)))
2949 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002950
Johannes Bergb9454e82009-07-08 13:29:08 +02002951 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2952 if (!key)
2953 goto nla_put_failure;
2954
David S. Miller9360ffd2012-03-29 04:41:26 -04002955 if ((params->key &&
2956 nla_put(cookie->msg, NL80211_KEY_DATA,
2957 params->key_len, params->key)) ||
2958 (params->seq &&
2959 nla_put(cookie->msg, NL80211_KEY_SEQ,
2960 params->seq_len, params->seq)) ||
2961 (params->cipher &&
2962 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2963 params->cipher)))
2964 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002965
David S. Miller9360ffd2012-03-29 04:41:26 -04002966 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2967 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002968
2969 nla_nest_end(cookie->msg, key);
2970
Johannes Berg41ade002007-12-19 02:03:29 +01002971 return;
2972 nla_put_failure:
2973 cookie->error = 1;
2974}
2975
2976static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2977{
Johannes Berg4c476992010-10-04 21:36:35 +02002978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002979 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002980 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002981 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002982 const u8 *mac_addr = NULL;
2983 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002984 struct get_key_cookie cookie = {
2985 .error = 0,
2986 };
2987 void *hdr;
2988 struct sk_buff *msg;
2989
2990 if (info->attrs[NL80211_ATTR_KEY_IDX])
2991 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2992
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002993 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002994 return -EINVAL;
2995
2996 if (info->attrs[NL80211_ATTR_MAC])
2997 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2998
Johannes Berge31b8212010-10-05 19:39:30 +02002999 pairwise = !!mac_addr;
3000 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3001 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003002
Johannes Berge31b8212010-10-05 19:39:30 +02003003 if (kt >= NUM_NL80211_KEYTYPES)
3004 return -EINVAL;
3005 if (kt != NL80211_KEYTYPE_GROUP &&
3006 kt != NL80211_KEYTYPE_PAIRWISE)
3007 return -EINVAL;
3008 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3009 }
3010
Johannes Berg4c476992010-10-04 21:36:35 +02003011 if (!rdev->ops->get_key)
3012 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003013
Johannes Berg0fa7b392015-01-23 11:10:12 +01003014 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3015 return -ENOENT;
3016
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003017 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003018 if (!msg)
3019 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003020
Eric W. Biederman15e47302012-09-07 20:12:54 +00003021 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003022 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003023 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003024 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003025
3026 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003027 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003028
David S. Miller9360ffd2012-03-29 04:41:26 -04003029 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3030 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3031 goto nla_put_failure;
3032 if (mac_addr &&
3033 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3034 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003035
Hila Gonene35e4d22012-06-27 17:19:42 +03003036 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3037 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003038
3039 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003040 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003041
3042 if (cookie.error)
3043 goto nla_put_failure;
3044
3045 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003046 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003047
3048 nla_put_failure:
3049 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003050 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003051 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003052 return err;
3053}
3054
3055static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3056{
Johannes Berg4c476992010-10-04 21:36:35 +02003057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003058 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003059 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003060 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003061
Johannes Bergb9454e82009-07-08 13:29:08 +02003062 err = nl80211_parse_key(info, &key);
3063 if (err)
3064 return err;
3065
3066 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003067 return -EINVAL;
3068
Johannes Bergb9454e82009-07-08 13:29:08 +02003069 /* only support setting default key */
3070 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003071 return -EINVAL;
3072
Johannes Bergfffd0932009-07-08 14:22:54 +02003073 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003074
3075 if (key.def) {
3076 if (!rdev->ops->set_default_key) {
3077 err = -EOPNOTSUPP;
3078 goto out;
3079 }
3080
3081 err = nl80211_key_allowed(dev->ieee80211_ptr);
3082 if (err)
3083 goto out;
3084
Hila Gonene35e4d22012-06-27 17:19:42 +03003085 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003086 key.def_uni, key.def_multi);
3087
3088 if (err)
3089 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003090
Johannes Berg3d23e342009-09-29 23:27:28 +02003091#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003092 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003093#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003094 } else {
3095 if (key.def_uni || !key.def_multi) {
3096 err = -EINVAL;
3097 goto out;
3098 }
3099
3100 if (!rdev->ops->set_default_mgmt_key) {
3101 err = -EOPNOTSUPP;
3102 goto out;
3103 }
3104
3105 err = nl80211_key_allowed(dev->ieee80211_ptr);
3106 if (err)
3107 goto out;
3108
Hila Gonene35e4d22012-06-27 17:19:42 +03003109 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003110 if (err)
3111 goto out;
3112
3113#ifdef CONFIG_CFG80211_WEXT
3114 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3115#endif
3116 }
3117
3118 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003119 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003120
Johannes Berg41ade002007-12-19 02:03:29 +01003121 return err;
3122}
3123
3124static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3125{
Johannes Berg4c476992010-10-04 21:36:35 +02003126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003127 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003128 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003129 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003130 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003131
Johannes Bergb9454e82009-07-08 13:29:08 +02003132 err = nl80211_parse_key(info, &key);
3133 if (err)
3134 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003135
Johannes Bergb9454e82009-07-08 13:29:08 +02003136 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003137 return -EINVAL;
3138
Johannes Berg41ade002007-12-19 02:03:29 +01003139 if (info->attrs[NL80211_ATTR_MAC])
3140 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3141
Johannes Berge31b8212010-10-05 19:39:30 +02003142 if (key.type == -1) {
3143 if (mac_addr)
3144 key.type = NL80211_KEYTYPE_PAIRWISE;
3145 else
3146 key.type = NL80211_KEYTYPE_GROUP;
3147 }
3148
3149 /* for now */
3150 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3151 key.type != NL80211_KEYTYPE_GROUP)
3152 return -EINVAL;
3153
Johannes Berg4c476992010-10-04 21:36:35 +02003154 if (!rdev->ops->add_key)
3155 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003156
Johannes Berge31b8212010-10-05 19:39:30 +02003157 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3158 key.type == NL80211_KEYTYPE_PAIRWISE,
3159 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003160 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003161
3162 wdev_lock(dev->ieee80211_ptr);
3163 err = nl80211_key_allowed(dev->ieee80211_ptr);
3164 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003165 err = rdev_add_key(rdev, dev, key.idx,
3166 key.type == NL80211_KEYTYPE_PAIRWISE,
3167 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003168 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003169
Johannes Berg41ade002007-12-19 02:03:29 +01003170 return err;
3171}
3172
3173static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3174{
Johannes Berg4c476992010-10-04 21:36:35 +02003175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003176 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003177 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003178 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003179 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003180
Johannes Bergb9454e82009-07-08 13:29:08 +02003181 err = nl80211_parse_key(info, &key);
3182 if (err)
3183 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003184
3185 if (info->attrs[NL80211_ATTR_MAC])
3186 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3187
Johannes Berge31b8212010-10-05 19:39:30 +02003188 if (key.type == -1) {
3189 if (mac_addr)
3190 key.type = NL80211_KEYTYPE_PAIRWISE;
3191 else
3192 key.type = NL80211_KEYTYPE_GROUP;
3193 }
3194
3195 /* for now */
3196 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3197 key.type != NL80211_KEYTYPE_GROUP)
3198 return -EINVAL;
3199
Johannes Berg4c476992010-10-04 21:36:35 +02003200 if (!rdev->ops->del_key)
3201 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003202
Johannes Bergfffd0932009-07-08 14:22:54 +02003203 wdev_lock(dev->ieee80211_ptr);
3204 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003205
Johannes Berg0fa7b392015-01-23 11:10:12 +01003206 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003207 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3208 err = -ENOENT;
3209
Johannes Bergfffd0932009-07-08 14:22:54 +02003210 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003211 err = rdev_del_key(rdev, dev, key.idx,
3212 key.type == NL80211_KEYTYPE_PAIRWISE,
3213 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003214
Johannes Berg3d23e342009-09-29 23:27:28 +02003215#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003216 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003217 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003218 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003219 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003220 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3221 }
3222#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003223 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003224
Johannes Berg41ade002007-12-19 02:03:29 +01003225 return err;
3226}
3227
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303228/* This function returns an error or the number of nested attributes */
3229static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3230{
3231 struct nlattr *attr;
3232 int n_entries = 0, tmp;
3233
3234 nla_for_each_nested(attr, nl_attr, tmp) {
3235 if (nla_len(attr) != ETH_ALEN)
3236 return -EINVAL;
3237
3238 n_entries++;
3239 }
3240
3241 return n_entries;
3242}
3243
3244/*
3245 * This function parses ACL information and allocates memory for ACL data.
3246 * On successful return, the calling function is responsible to free the
3247 * ACL buffer returned by this function.
3248 */
3249static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3250 struct genl_info *info)
3251{
3252 enum nl80211_acl_policy acl_policy;
3253 struct nlattr *attr;
3254 struct cfg80211_acl_data *acl;
3255 int i = 0, n_entries, tmp;
3256
3257 if (!wiphy->max_acl_mac_addrs)
3258 return ERR_PTR(-EOPNOTSUPP);
3259
3260 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3261 return ERR_PTR(-EINVAL);
3262
3263 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3264 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3265 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3266 return ERR_PTR(-EINVAL);
3267
3268 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3269 return ERR_PTR(-EINVAL);
3270
3271 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3272 if (n_entries < 0)
3273 return ERR_PTR(n_entries);
3274
3275 if (n_entries > wiphy->max_acl_mac_addrs)
3276 return ERR_PTR(-ENOTSUPP);
3277
3278 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3279 GFP_KERNEL);
3280 if (!acl)
3281 return ERR_PTR(-ENOMEM);
3282
3283 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3284 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3285 i++;
3286 }
3287
3288 acl->n_acl_entries = n_entries;
3289 acl->acl_policy = acl_policy;
3290
3291 return acl;
3292}
3293
3294static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3295{
3296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3297 struct net_device *dev = info->user_ptr[1];
3298 struct cfg80211_acl_data *acl;
3299 int err;
3300
3301 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3302 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3303 return -EOPNOTSUPP;
3304
3305 if (!dev->ieee80211_ptr->beacon_interval)
3306 return -EINVAL;
3307
3308 acl = parse_acl_data(&rdev->wiphy, info);
3309 if (IS_ERR(acl))
3310 return PTR_ERR(acl);
3311
3312 err = rdev_set_mac_acl(rdev, dev, acl);
3313
3314 kfree(acl);
3315
3316 return err;
3317}
3318
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003319static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003320 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003321{
Johannes Berg88600202012-02-13 15:17:18 +01003322 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003323
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003324 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3325 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3326 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3327 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003328 return -EINVAL;
3329
Johannes Berg88600202012-02-13 15:17:18 +01003330 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003331
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003332 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3333 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3334 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003335 if (!bcn->head_len)
3336 return -EINVAL;
3337 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003338 }
3339
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003340 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3341 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3342 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003343 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003344 }
3345
Johannes Berg4c476992010-10-04 21:36:35 +02003346 if (!haveinfo)
3347 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003348
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003349 if (attrs[NL80211_ATTR_IE]) {
3350 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3351 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003352 }
3353
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003354 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003355 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003356 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003357 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003358 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003359 }
3360
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003361 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003362 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003363 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003364 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003365 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003366 }
3367
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003368 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3369 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3370 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003371 }
3372
Johannes Berg88600202012-02-13 15:17:18 +01003373 return 0;
3374}
3375
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003376static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3377 struct cfg80211_ap_settings *params)
3378{
3379 struct wireless_dev *wdev;
3380 bool ret = false;
3381
Johannes Berg53873f12016-05-03 16:52:04 +03003382 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003383 if (wdev->iftype != NL80211_IFTYPE_AP &&
3384 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3385 continue;
3386
Johannes Berg683b6d32012-11-08 21:25:48 +01003387 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003388 continue;
3389
Johannes Berg683b6d32012-11-08 21:25:48 +01003390 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003391 ret = true;
3392 break;
3393 }
3394
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003395 return ret;
3396}
3397
Jouni Malinene39e5b52012-09-30 19:29:39 +03003398static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3399 enum nl80211_auth_type auth_type,
3400 enum nl80211_commands cmd)
3401{
3402 if (auth_type > NL80211_AUTHTYPE_MAX)
3403 return false;
3404
3405 switch (cmd) {
3406 case NL80211_CMD_AUTHENTICATE:
3407 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3408 auth_type == NL80211_AUTHTYPE_SAE)
3409 return false;
3410 return true;
3411 case NL80211_CMD_CONNECT:
3412 case NL80211_CMD_START_AP:
3413 /* SAE not supported yet */
3414 if (auth_type == NL80211_AUTHTYPE_SAE)
3415 return false;
3416 return true;
3417 default:
3418 return false;
3419 }
3420}
3421
Johannes Berg88600202012-02-13 15:17:18 +01003422static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3423{
3424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3425 struct net_device *dev = info->user_ptr[1];
3426 struct wireless_dev *wdev = dev->ieee80211_ptr;
3427 struct cfg80211_ap_settings params;
3428 int err;
3429
3430 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3431 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3432 return -EOPNOTSUPP;
3433
3434 if (!rdev->ops->start_ap)
3435 return -EOPNOTSUPP;
3436
3437 if (wdev->beacon_interval)
3438 return -EALREADY;
3439
3440 memset(&params, 0, sizeof(params));
3441
3442 /* these are required for START_AP */
3443 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3444 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3445 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3446 return -EINVAL;
3447
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003448 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003449 if (err)
3450 return err;
3451
3452 params.beacon_interval =
3453 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3454 params.dtim_period =
3455 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3456
3457 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3458 if (err)
3459 return err;
3460
3461 /*
3462 * In theory, some of these attributes should be required here
3463 * but since they were not used when the command was originally
3464 * added, keep them optional for old user space programs to let
3465 * them continue to work with drivers that do not need the
3466 * additional information -- drivers must check!
3467 */
3468 if (info->attrs[NL80211_ATTR_SSID]) {
3469 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3470 params.ssid_len =
3471 nla_len(info->attrs[NL80211_ATTR_SSID]);
3472 if (params.ssid_len == 0 ||
3473 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3474 return -EINVAL;
3475 }
3476
3477 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3478 params.hidden_ssid = nla_get_u32(
3479 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3480 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3481 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3482 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3483 return -EINVAL;
3484 }
3485
3486 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3487
3488 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3489 params.auth_type = nla_get_u32(
3490 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003491 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3492 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003493 return -EINVAL;
3494 } else
3495 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3496
3497 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3498 NL80211_MAX_NR_CIPHER_SUITES);
3499 if (err)
3500 return err;
3501
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303502 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3503 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3504 return -EOPNOTSUPP;
3505 params.inactivity_timeout = nla_get_u16(
3506 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3507 }
3508
Johannes Berg53cabad2012-11-14 15:17:28 +01003509 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3510 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3511 return -EINVAL;
3512 params.p2p_ctwindow =
3513 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3514 if (params.p2p_ctwindow > 127)
3515 return -EINVAL;
3516 if (params.p2p_ctwindow != 0 &&
3517 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3518 return -EINVAL;
3519 }
3520
3521 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3522 u8 tmp;
3523
3524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3525 return -EINVAL;
3526 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3527 if (tmp > 1)
3528 return -EINVAL;
3529 params.p2p_opp_ps = tmp;
3530 if (params.p2p_opp_ps != 0 &&
3531 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3532 return -EINVAL;
3533 }
3534
Johannes Bergaa430da2012-05-16 23:50:18 +02003535 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003536 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3537 if (err)
3538 return err;
3539 } else if (wdev->preset_chandef.chan) {
3540 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003541 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003542 return -EINVAL;
3543
Arik Nemtsov923b3522015-07-08 15:41:44 +03003544 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3545 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003546 return -EINVAL;
3547
Eliad Peller18998c32014-09-10 14:07:34 +03003548 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3549 params.smps_mode =
3550 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3551 switch (params.smps_mode) {
3552 case NL80211_SMPS_OFF:
3553 break;
3554 case NL80211_SMPS_STATIC:
3555 if (!(rdev->wiphy.features &
3556 NL80211_FEATURE_STATIC_SMPS))
3557 return -EINVAL;
3558 break;
3559 case NL80211_SMPS_DYNAMIC:
3560 if (!(rdev->wiphy.features &
3561 NL80211_FEATURE_DYNAMIC_SMPS))
3562 return -EINVAL;
3563 break;
3564 default:
3565 return -EINVAL;
3566 }
3567 } else {
3568 params.smps_mode = NL80211_SMPS_OFF;
3569 }
3570
Ola Olsson4baf6be2015-10-29 07:04:58 +01003571 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3572 params.acl = parse_acl_data(&rdev->wiphy, info);
3573 if (IS_ERR(params.acl))
3574 return PTR_ERR(params.acl);
3575 }
3576
Lior David34d50512016-01-28 10:58:25 +02003577 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02003578 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
Lior David34d50512016-01-28 10:58:25 +02003579 return -EOPNOTSUPP;
3580
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003581 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003582 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003583 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003584 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003585 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003586 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003587 wdev->ssid_len = params.ssid_len;
3588 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003589 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003590 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303591
3592 kfree(params.acl);
3593
Johannes Berg56d18932011-05-09 18:41:15 +02003594 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003595}
3596
Johannes Berg88600202012-02-13 15:17:18 +01003597static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3598{
3599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3600 struct net_device *dev = info->user_ptr[1];
3601 struct wireless_dev *wdev = dev->ieee80211_ptr;
3602 struct cfg80211_beacon_data params;
3603 int err;
3604
3605 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3606 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3607 return -EOPNOTSUPP;
3608
3609 if (!rdev->ops->change_beacon)
3610 return -EOPNOTSUPP;
3611
3612 if (!wdev->beacon_interval)
3613 return -EINVAL;
3614
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003615 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003616 if (err)
3617 return err;
3618
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003619 wdev_lock(wdev);
3620 err = rdev_change_beacon(rdev, dev, &params);
3621 wdev_unlock(wdev);
3622
3623 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003624}
3625
3626static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003627{
Johannes Berg4c476992010-10-04 21:36:35 +02003628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3629 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003630
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003631 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003632}
3633
Johannes Berg5727ef12007-12-19 02:03:34 +01003634static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3635 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3636 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3637 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003638 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003639 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003640 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003641};
3642
Johannes Bergeccb8e82009-05-11 21:57:56 +03003643static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003644 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003645 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003646{
3647 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003648 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003649 int flag;
3650
Johannes Bergeccb8e82009-05-11 21:57:56 +03003651 /*
3652 * Try parsing the new attribute first so userspace
3653 * can specify both for older kernels.
3654 */
3655 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3656 if (nla) {
3657 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003658
Johannes Bergeccb8e82009-05-11 21:57:56 +03003659 sta_flags = nla_data(nla);
3660 params->sta_flags_mask = sta_flags->mask;
3661 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003662 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003663 if ((params->sta_flags_mask |
3664 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3665 return -EINVAL;
3666 return 0;
3667 }
3668
3669 /* if present, parse the old attribute */
3670
3671 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003672 if (!nla)
3673 return 0;
3674
3675 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3676 nla, sta_flags_policy))
3677 return -EINVAL;
3678
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003679 /*
3680 * Only allow certain flags for interface types so that
3681 * other attributes are silently ignored. Remember that
3682 * this is backward compatibility code with old userspace
3683 * and shouldn't be hit in other cases anyway.
3684 */
3685 switch (iftype) {
3686 case NL80211_IFTYPE_AP:
3687 case NL80211_IFTYPE_AP_VLAN:
3688 case NL80211_IFTYPE_P2P_GO:
3689 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3691 BIT(NL80211_STA_FLAG_WME) |
3692 BIT(NL80211_STA_FLAG_MFP);
3693 break;
3694 case NL80211_IFTYPE_P2P_CLIENT:
3695 case NL80211_IFTYPE_STATION:
3696 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3697 BIT(NL80211_STA_FLAG_TDLS_PEER);
3698 break;
3699 case NL80211_IFTYPE_MESH_POINT:
3700 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_MFP) |
3702 BIT(NL80211_STA_FLAG_AUTHORIZED);
3703 default:
3704 return -EINVAL;
3705 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003706
Johannes Berg3383b5a2012-05-10 20:14:43 +02003707 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3708 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003709 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003710
Johannes Berg3383b5a2012-05-10 20:14:43 +02003711 /* no longer support new API additions in old API */
3712 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3713 return -EINVAL;
3714 }
3715 }
3716
Johannes Berg5727ef12007-12-19 02:03:34 +01003717 return 0;
3718}
3719
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003720static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3721 int attr)
3722{
3723 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003724 u32 bitrate;
3725 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003726 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003727
3728 rate = nla_nest_start(msg, attr);
3729 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003730 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003731
3732 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3733 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003734 /* report 16-bit bitrate only if we can */
3735 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003736 if (bitrate > 0 &&
3737 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3738 return false;
3739 if (bitrate_compat > 0 &&
3740 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3741 return false;
3742
Johannes Bergb51f3be2015-01-15 16:14:02 +01003743 switch (info->bw) {
3744 case RATE_INFO_BW_5:
3745 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3746 break;
3747 case RATE_INFO_BW_10:
3748 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3749 break;
3750 default:
3751 WARN_ON(1);
3752 /* fall through */
3753 case RATE_INFO_BW_20:
3754 rate_flg = 0;
3755 break;
3756 case RATE_INFO_BW_40:
3757 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3758 break;
3759 case RATE_INFO_BW_80:
3760 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3761 break;
3762 case RATE_INFO_BW_160:
3763 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3764 break;
3765 }
3766
3767 if (rate_flg && nla_put_flag(msg, rate_flg))
3768 return false;
3769
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003770 if (info->flags & RATE_INFO_FLAGS_MCS) {
3771 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3772 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003773 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3774 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3775 return false;
3776 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3777 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3778 return false;
3779 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3780 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003781 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3782 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3783 return false;
3784 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003785
3786 nla_nest_end(msg, rate);
3787 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003788}
3789
Felix Fietkau119363c2013-04-22 16:29:30 +02003790static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3791 int id)
3792{
3793 void *attr;
3794 int i = 0;
3795
3796 if (!mask)
3797 return true;
3798
3799 attr = nla_nest_start(msg, id);
3800 if (!attr)
3801 return false;
3802
3803 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3804 if (!(mask & BIT(i)))
3805 continue;
3806
3807 if (nla_put_u8(msg, i, signal[i]))
3808 return false;
3809 }
3810
3811 nla_nest_end(msg, attr);
3812
3813 return true;
3814}
3815
Johannes Bergcf5ead82014-11-14 17:14:00 +01003816static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3817 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003818 struct cfg80211_registered_device *rdev,
3819 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003820 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003821{
3822 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003823 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003824
Johannes Bergcf5ead82014-11-14 17:14:00 +01003825 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003826 if (!hdr)
3827 return -1;
3828
David S. Miller9360ffd2012-03-29 04:41:26 -04003829 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3830 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3831 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3832 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003833
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003834 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3835 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003836 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003837
3838#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003839 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303840 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003841 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3842 sinfo->memb)) \
3843 goto nla_put_failure; \
3844 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003845#define PUT_SINFO_U64(attr, memb) do { \
3846 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3847 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3848 sinfo->memb, NL80211_STA_INFO_PAD)) \
3849 goto nla_put_failure; \
3850 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003851
3852 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3853 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3854
3855 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3856 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003857 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003858 (u32)sinfo->rx_bytes))
3859 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003860
3861 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3862 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003863 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3864 (u32)sinfo->tx_bytes))
3865 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003866
Johannes Bergd686b922016-04-26 09:54:11 +02003867 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3868 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003869 PUT_SINFO(LLID, llid, u16);
3870 PUT_SINFO(PLID, plid, u16);
3871 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003872 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003873
John W. Linville66266b32012-03-15 13:25:41 -04003874 switch (rdev->wiphy.signal_type) {
3875 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003876 PUT_SINFO(SIGNAL, signal, u8);
3877 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003878 break;
3879 default:
3880 break;
3881 }
Johannes Berg319090b2014-11-17 14:08:11 +01003882 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003883 if (!nl80211_put_signal(msg, sinfo->chains,
3884 sinfo->chain_signal,
3885 NL80211_STA_INFO_CHAIN_SIGNAL))
3886 goto nla_put_failure;
3887 }
Johannes Berg319090b2014-11-17 14:08:11 +01003888 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003889 if (!nl80211_put_signal(msg, sinfo->chains,
3890 sinfo->chain_signal_avg,
3891 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3892 goto nla_put_failure;
3893 }
Johannes Berg319090b2014-11-17 14:08:11 +01003894 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003895 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3896 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003897 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003898 }
Johannes Berg319090b2014-11-17 14:08:11 +01003899 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003900 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3901 NL80211_STA_INFO_RX_BITRATE))
3902 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003903 }
Johannes Berg319090b2014-11-17 14:08:11 +01003904
3905 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3906 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3907 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3908 PUT_SINFO(TX_FAILED, tx_failed, u32);
3909 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3910 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3911 PUT_SINFO(LOCAL_PM, local_pm, u32);
3912 PUT_SINFO(PEER_PM, peer_pm, u32);
3913 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3914
3915 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003916 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3917 if (!bss_param)
3918 goto nla_put_failure;
3919
David S. Miller9360ffd2012-03-29 04:41:26 -04003920 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3921 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3922 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3923 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3924 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3925 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3926 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3927 sinfo->bss_param.dtim_period) ||
3928 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3929 sinfo->bss_param.beacon_interval))
3930 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003931
3932 nla_nest_end(msg, bss_param);
3933 }
Johannes Berg319090b2014-11-17 14:08:11 +01003934 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003935 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3936 sizeof(struct nl80211_sta_flag_update),
3937 &sinfo->sta_flags))
3938 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003939
Johannes Bergd686b922016-04-26 09:54:11 +02003940 PUT_SINFO_U64(T_OFFSET, t_offset);
3941 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3942 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003943 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003944
3945#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003946#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003947
3948 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3949 struct nlattr *tidsattr;
3950 int tid;
3951
3952 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3953 if (!tidsattr)
3954 goto nla_put_failure;
3955
3956 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3957 struct cfg80211_tid_stats *tidstats;
3958 struct nlattr *tidattr;
3959
3960 tidstats = &sinfo->pertid[tid];
3961
3962 if (!tidstats->filled)
3963 continue;
3964
3965 tidattr = nla_nest_start(msg, tid + 1);
3966 if (!tidattr)
3967 goto nla_put_failure;
3968
Johannes Bergd686b922016-04-26 09:54:11 +02003969#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003970 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003971 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3972 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003973 goto nla_put_failure; \
3974 } while (0)
3975
Johannes Bergd686b922016-04-26 09:54:11 +02003976 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
3977 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
3978 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
3979 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01003980
Johannes Bergd686b922016-04-26 09:54:11 +02003981#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003982 nla_nest_end(msg, tidattr);
3983 }
3984
3985 nla_nest_end(msg, tidsattr);
3986 }
3987
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003988 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003989
Johannes Berg319090b2014-11-17 14:08:11 +01003990 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003991 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3992 sinfo->assoc_req_ies))
3993 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003994
Johannes Berg053c0952015-01-16 22:09:00 +01003995 genlmsg_end(msg, hdr);
3996 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003997
3998 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003999 genlmsg_cancel(msg, hdr);
4000 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004001}
4002
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004003static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004004 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004005{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004006 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004007 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004008 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004009 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004010 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004011 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004012
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004013 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004014 if (err)
4015 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004016
Johannes Berg97990a02013-04-19 01:02:55 +02004017 if (!wdev->netdev) {
4018 err = -EINVAL;
4019 goto out_err;
4020 }
4021
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004022 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004023 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004024 goto out_err;
4025 }
4026
Johannes Bergbba95fe2008-07-29 13:22:51 +02004027 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004028 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004029 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004030 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004031 if (err == -ENOENT)
4032 break;
4033 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004034 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004035
Johannes Bergcf5ead82014-11-14 17:14:00 +01004036 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004037 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004038 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004039 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004040 &sinfo) < 0)
4041 goto out;
4042
4043 sta_idx++;
4044 }
4045
Johannes Bergbba95fe2008-07-29 13:22:51 +02004046 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004047 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004048 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004049 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004050 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004051
4052 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004053}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004054
Johannes Berg5727ef12007-12-19 02:03:34 +01004055static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4056{
Johannes Berg4c476992010-10-04 21:36:35 +02004057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4058 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004059 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004060 struct sk_buff *msg;
4061 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004062 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004063
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004064 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004065
4066 if (!info->attrs[NL80211_ATTR_MAC])
4067 return -EINVAL;
4068
4069 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4070
Johannes Berg4c476992010-10-04 21:36:35 +02004071 if (!rdev->ops->get_station)
4072 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004073
Hila Gonene35e4d22012-06-27 17:19:42 +03004074 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004075 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004076 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004077
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004078 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004079 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004080 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004081
Johannes Bergcf5ead82014-11-14 17:14:00 +01004082 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4083 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004084 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004085 nlmsg_free(msg);
4086 return -ENOBUFS;
4087 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004088
Johannes Berg4c476992010-10-04 21:36:35 +02004089 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004090}
4091
Johannes Berg77ee7c82013-02-15 00:48:33 +01004092int cfg80211_check_station_change(struct wiphy *wiphy,
4093 struct station_parameters *params,
4094 enum cfg80211_station_type statype)
4095{
Ayala Bekere4208422015-10-23 11:20:06 +03004096 if (params->listen_interval != -1 &&
4097 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004098 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004099
Ayala Beker17b94242016-03-17 15:41:38 +02004100 if (params->support_p2p_ps != -1 &&
4101 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4102 return -EINVAL;
4103
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004104 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004105 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4106 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004107 return -EINVAL;
4108
4109 /* When you run into this, adjust the code below for the new flag */
4110 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4111
4112 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004113 case CFG80211_STA_MESH_PEER_KERNEL:
4114 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004115 /*
4116 * No ignoring the TDLS flag here -- the userspace mesh
4117 * code doesn't have the bug of including TDLS in the
4118 * mask everywhere.
4119 */
4120 if (params->sta_flags_mask &
4121 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4122 BIT(NL80211_STA_FLAG_MFP) |
4123 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4124 return -EINVAL;
4125 break;
4126 case CFG80211_STA_TDLS_PEER_SETUP:
4127 case CFG80211_STA_TDLS_PEER_ACTIVE:
4128 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4129 return -EINVAL;
4130 /* ignore since it can't change */
4131 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4132 break;
4133 default:
4134 /* disallow mesh-specific things */
4135 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4136 return -EINVAL;
4137 if (params->local_pm)
4138 return -EINVAL;
4139 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4140 return -EINVAL;
4141 }
4142
4143 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4144 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4145 /* TDLS can't be set, ... */
4146 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4147 return -EINVAL;
4148 /*
4149 * ... but don't bother the driver with it. This works around
4150 * a hostapd/wpa_supplicant issue -- it always includes the
4151 * TLDS_PEER flag in the mask even for AP mode.
4152 */
4153 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4154 }
4155
Ayala Beker47edb112015-09-21 15:49:53 +03004156 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4157 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004158 /* reject other things that can't change */
4159 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4160 return -EINVAL;
4161 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4162 return -EINVAL;
4163 if (params->supported_rates)
4164 return -EINVAL;
4165 if (params->ext_capab || params->ht_capa || params->vht_capa)
4166 return -EINVAL;
4167 }
4168
Ayala Beker47edb112015-09-21 15:49:53 +03004169 if (statype != CFG80211_STA_AP_CLIENT &&
4170 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004171 if (params->vlan)
4172 return -EINVAL;
4173 }
4174
4175 switch (statype) {
4176 case CFG80211_STA_AP_MLME_CLIENT:
4177 /* Use this only for authorizing/unauthorizing a station */
4178 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4179 return -EOPNOTSUPP;
4180 break;
4181 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004182 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004183 /* accept only the listed bits */
4184 if (params->sta_flags_mask &
4185 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4186 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4187 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4188 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4189 BIT(NL80211_STA_FLAG_WME) |
4190 BIT(NL80211_STA_FLAG_MFP)))
4191 return -EINVAL;
4192
4193 /* but authenticated/associated only if driver handles it */
4194 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4195 params->sta_flags_mask &
4196 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4197 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4198 return -EINVAL;
4199 break;
4200 case CFG80211_STA_IBSS:
4201 case CFG80211_STA_AP_STA:
4202 /* reject any changes other than AUTHORIZED */
4203 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4204 return -EINVAL;
4205 break;
4206 case CFG80211_STA_TDLS_PEER_SETUP:
4207 /* reject any changes other than AUTHORIZED or WME */
4208 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4209 BIT(NL80211_STA_FLAG_WME)))
4210 return -EINVAL;
4211 /* force (at least) rates when authorizing */
4212 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4213 !params->supported_rates)
4214 return -EINVAL;
4215 break;
4216 case CFG80211_STA_TDLS_PEER_ACTIVE:
4217 /* reject any changes */
4218 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004219 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004220 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4221 return -EINVAL;
4222 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004223 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004224 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4225 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004226 return -EINVAL;
4227 break;
4228 }
4229
4230 return 0;
4231}
4232EXPORT_SYMBOL(cfg80211_check_station_change);
4233
Johannes Berg5727ef12007-12-19 02:03:34 +01004234/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004235 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004236 */
Johannes Berg80b99892011-11-18 16:23:01 +01004237static struct net_device *get_vlan(struct genl_info *info,
4238 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004239{
Johannes Berg463d0182009-07-14 00:33:35 +02004240 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004241 struct net_device *v;
4242 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004243
Johannes Berg80b99892011-11-18 16:23:01 +01004244 if (!vlanattr)
4245 return NULL;
4246
4247 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4248 if (!v)
4249 return ERR_PTR(-ENODEV);
4250
4251 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4252 ret = -EINVAL;
4253 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004254 }
Johannes Berg80b99892011-11-18 16:23:01 +01004255
Johannes Berg77ee7c82013-02-15 00:48:33 +01004256 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4257 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4258 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4259 ret = -EINVAL;
4260 goto error;
4261 }
4262
Johannes Berg80b99892011-11-18 16:23:01 +01004263 if (!netif_running(v)) {
4264 ret = -ENETDOWN;
4265 goto error;
4266 }
4267
4268 return v;
4269 error:
4270 dev_put(v);
4271 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004272}
4273
Johannes Berg94e860f2014-01-20 23:58:15 +01004274static const struct nla_policy
4275nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004276 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4277 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4278};
4279
Johannes Bergff276692013-02-15 00:09:01 +01004280static int nl80211_parse_sta_wme(struct genl_info *info,
4281 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004282{
Jouni Malinendf881292013-02-14 21:10:54 +02004283 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4284 struct nlattr *nla;
4285 int err;
4286
Jouni Malinendf881292013-02-14 21:10:54 +02004287 /* parse WME attributes if present */
4288 if (!info->attrs[NL80211_ATTR_STA_WME])
4289 return 0;
4290
4291 nla = info->attrs[NL80211_ATTR_STA_WME];
4292 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4293 nl80211_sta_wme_policy);
4294 if (err)
4295 return err;
4296
4297 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4298 params->uapsd_queues = nla_get_u8(
4299 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4300 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4301 return -EINVAL;
4302
4303 if (tb[NL80211_STA_WME_MAX_SP])
4304 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4305
4306 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4307 return -EINVAL;
4308
4309 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4310
4311 return 0;
4312}
4313
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304314static int nl80211_parse_sta_channel_info(struct genl_info *info,
4315 struct station_parameters *params)
4316{
4317 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4318 params->supported_channels =
4319 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4320 params->supported_channels_len =
4321 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4322 /*
4323 * Need to include at least one (first channel, number of
4324 * channels) tuple for each subband, and must have proper
4325 * tuples for the rest of the data as well.
4326 */
4327 if (params->supported_channels_len < 2)
4328 return -EINVAL;
4329 if (params->supported_channels_len % 2)
4330 return -EINVAL;
4331 }
4332
4333 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4334 params->supported_oper_classes =
4335 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4336 params->supported_oper_classes_len =
4337 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4338 /*
4339 * The value of the Length field of the Supported Operating
4340 * Classes element is between 2 and 253.
4341 */
4342 if (params->supported_oper_classes_len < 2 ||
4343 params->supported_oper_classes_len > 253)
4344 return -EINVAL;
4345 }
4346 return 0;
4347}
4348
Johannes Bergff276692013-02-15 00:09:01 +01004349static int nl80211_set_station_tdls(struct genl_info *info,
4350 struct station_parameters *params)
4351{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304352 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004353 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004354 if (info->attrs[NL80211_ATTR_PEER_AID])
4355 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004356 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4357 params->ht_capa =
4358 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4359 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4360 params->vht_capa =
4361 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4362
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304363 err = nl80211_parse_sta_channel_info(info, params);
4364 if (err)
4365 return err;
4366
Johannes Bergff276692013-02-15 00:09:01 +01004367 return nl80211_parse_sta_wme(info, params);
4368}
4369
Johannes Berg5727ef12007-12-19 02:03:34 +01004370static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4371{
Johannes Berg4c476992010-10-04 21:36:35 +02004372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004373 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004374 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004375 u8 *mac_addr;
4376 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004377
4378 memset(&params, 0, sizeof(params));
4379
Johannes Berg77ee7c82013-02-15 00:48:33 +01004380 if (!rdev->ops->change_station)
4381 return -EOPNOTSUPP;
4382
Ayala Bekere4208422015-10-23 11:20:06 +03004383 /*
4384 * AID and listen_interval properties can be set only for unassociated
4385 * station. Include these parameters here and will check them in
4386 * cfg80211_check_station_change().
4387 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004388 if (info->attrs[NL80211_ATTR_STA_AID])
4389 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004390
4391 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4392 params.listen_interval =
4393 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4394 else
4395 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004396
Ayala Beker17b94242016-03-17 15:41:38 +02004397 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4398 u8 tmp;
4399
4400 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4401 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4402 return -EINVAL;
4403
4404 params.support_p2p_ps = tmp;
4405 } else {
4406 params.support_p2p_ps = -1;
4407 }
4408
Johannes Berg5727ef12007-12-19 02:03:34 +01004409 if (!info->attrs[NL80211_ATTR_MAC])
4410 return -EINVAL;
4411
4412 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4413
4414 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4415 params.supported_rates =
4416 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4417 params.supported_rates_len =
4418 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4419 }
4420
Jouni Malinen9d62a982013-02-14 21:10:13 +02004421 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4422 params.capability =
4423 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4424 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4425 }
4426
4427 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4428 params.ext_capab =
4429 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4430 params.ext_capab_len =
4431 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4432 }
4433
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004434 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004435 return -EINVAL;
4436
Johannes Bergf8bacc22013-02-14 23:27:01 +01004437 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004438 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004439 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4440 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4441 return -EINVAL;
4442 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004443
Johannes Bergf8bacc22013-02-14 23:27:01 +01004444 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004445 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004446 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4447 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4448 return -EINVAL;
4449 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4450 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004451
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004452 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4453 enum nl80211_mesh_power_mode pm = nla_get_u32(
4454 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4455
4456 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4457 pm > NL80211_MESH_POWER_MAX)
4458 return -EINVAL;
4459
4460 params.local_pm = pm;
4461 }
4462
Johannes Berg77ee7c82013-02-15 00:48:33 +01004463 /* Include parameters for TDLS peer (will check later) */
4464 err = nl80211_set_station_tdls(info, &params);
4465 if (err)
4466 return err;
4467
4468 params.vlan = get_vlan(info, rdev);
4469 if (IS_ERR(params.vlan))
4470 return PTR_ERR(params.vlan);
4471
Johannes Berga97f4422009-06-18 17:23:43 +02004472 switch (dev->ieee80211_ptr->iftype) {
4473 case NL80211_IFTYPE_AP:
4474 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004475 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004476 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004477 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004478 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004479 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004480 break;
4481 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004482 err = -EOPNOTSUPP;
4483 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004484 }
4485
Johannes Berg77ee7c82013-02-15 00:48:33 +01004486 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004487 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004488
Johannes Berg77ee7c82013-02-15 00:48:33 +01004489 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004490 if (params.vlan)
4491 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004492
Johannes Berg5727ef12007-12-19 02:03:34 +01004493 return err;
4494}
4495
4496static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4497{
Johannes Berg4c476992010-10-04 21:36:35 +02004498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004499 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004500 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004501 struct station_parameters params;
4502 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004503 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4504 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004505
4506 memset(&params, 0, sizeof(params));
4507
Johannes Berg984c3112013-02-14 23:43:25 +01004508 if (!rdev->ops->add_station)
4509 return -EOPNOTSUPP;
4510
Johannes Berg5727ef12007-12-19 02:03:34 +01004511 if (!info->attrs[NL80211_ATTR_MAC])
4512 return -EINVAL;
4513
Johannes Berg5727ef12007-12-19 02:03:34 +01004514 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4515 return -EINVAL;
4516
4517 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4518 return -EINVAL;
4519
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004520 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4521 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004522 return -EINVAL;
4523
Johannes Berg5727ef12007-12-19 02:03:34 +01004524 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4525 params.supported_rates =
4526 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4527 params.supported_rates_len =
4528 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4529 params.listen_interval =
4530 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004531
Ayala Beker17b94242016-03-17 15:41:38 +02004532 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4533 u8 tmp;
4534
4535 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4536 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4537 return -EINVAL;
4538
4539 params.support_p2p_ps = tmp;
4540 } else {
4541 /*
4542 * if not specified, assume it's supported for P2P GO interface,
4543 * and is NOT supported for AP interface
4544 */
4545 params.support_p2p_ps =
4546 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4547 }
4548
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004549 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004550 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004551 else
4552 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004553 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4554 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004555
Jouni Malinen9d62a982013-02-14 21:10:13 +02004556 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4557 params.capability =
4558 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4559 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4560 }
4561
4562 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4563 params.ext_capab =
4564 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4565 params.ext_capab_len =
4566 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4567 }
4568
Jouni Malinen36aedc902008-08-25 11:58:58 +03004569 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4570 params.ht_capa =
4571 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004572
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004573 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4574 params.vht_capa =
4575 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4576
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004577 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4578 params.opmode_notif_used = true;
4579 params.opmode_notif =
4580 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4581 }
4582
Johannes Bergf8bacc22013-02-14 23:27:01 +01004583 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004584 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004585 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4586 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4587 return -EINVAL;
4588 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004589
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304590 err = nl80211_parse_sta_channel_info(info, &params);
4591 if (err)
4592 return err;
4593
Johannes Bergff276692013-02-15 00:09:01 +01004594 err = nl80211_parse_sta_wme(info, &params);
4595 if (err)
4596 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004597
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004598 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004599 return -EINVAL;
4600
Johannes Berg496fcc22015-03-12 08:53:27 +02004601 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4602 * as userspace might just pass through the capabilities from the IEs
4603 * directly, rather than enforcing this restriction and returning an
4604 * error in this case.
4605 */
4606 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4607 params.ht_capa = NULL;
4608 params.vht_capa = NULL;
4609 }
4610
Johannes Berg77ee7c82013-02-15 00:48:33 +01004611 /* When you run into this, adjust the code below for the new flag */
4612 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4613
Johannes Bergbdd90d52011-12-14 12:20:27 +01004614 switch (dev->ieee80211_ptr->iftype) {
4615 case NL80211_IFTYPE_AP:
4616 case NL80211_IFTYPE_AP_VLAN:
4617 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004618 /* ignore WME attributes if iface/sta is not capable */
4619 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4620 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4621 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004622
Johannes Bergbdd90d52011-12-14 12:20:27 +01004623 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004624 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4625 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004626 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004627 /* but don't bother the driver with it */
4628 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004629
Johannes Bergd582cff2012-10-26 17:53:44 +02004630 /* allow authenticated/associated only if driver handles it */
4631 if (!(rdev->wiphy.features &
4632 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004633 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004634 return -EINVAL;
4635
Johannes Bergbda95eb2015-11-26 16:26:13 +01004636 /* Older userspace, or userspace wanting to be compatible with
4637 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4638 * and assoc flags in the mask, but assumes the station will be
4639 * added as associated anyway since this was the required driver
4640 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4641 * introduced.
4642 * In order to not bother drivers with this quirk in the API
4643 * set the flags in both the mask and set for new stations in
4644 * this case.
4645 */
4646 if (!(params.sta_flags_mask & auth_assoc)) {
4647 params.sta_flags_mask |= auth_assoc;
4648 params.sta_flags_set |= auth_assoc;
4649 }
4650
Johannes Bergbdd90d52011-12-14 12:20:27 +01004651 /* must be last in here for error handling */
4652 params.vlan = get_vlan(info, rdev);
4653 if (IS_ERR(params.vlan))
4654 return PTR_ERR(params.vlan);
4655 break;
4656 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004657 /* ignore uAPSD data */
4658 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4659
Johannes Bergd582cff2012-10-26 17:53:44 +02004660 /* associated is disallowed */
4661 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4662 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004663 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004664 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4665 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004666 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004667 break;
4668 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004669 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004670 /* ignore uAPSD data */
4671 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4672
Johannes Berg77ee7c82013-02-15 00:48:33 +01004673 /* these are disallowed */
4674 if (params.sta_flags_mask &
4675 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4676 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004677 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004678 /* Only TDLS peers can be added */
4679 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4680 return -EINVAL;
4681 /* Can only add if TDLS ... */
4682 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4683 return -EOPNOTSUPP;
4684 /* ... with external setup is supported */
4685 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4686 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004687 /*
4688 * Older wpa_supplicant versions always mark the TDLS peer
4689 * as authorized, but it shouldn't yet be.
4690 */
4691 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004692 break;
4693 default:
4694 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004695 }
4696
Johannes Bergbdd90d52011-12-14 12:20:27 +01004697 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004698
Hila Gonene35e4d22012-06-27 17:19:42 +03004699 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004700
Johannes Berg5727ef12007-12-19 02:03:34 +01004701 if (params.vlan)
4702 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004703 return err;
4704}
4705
4706static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4707{
Johannes Berg4c476992010-10-04 21:36:35 +02004708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4709 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004710 struct station_del_parameters params;
4711
4712 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004713
4714 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004715 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004716
Johannes Berge80cf852009-05-11 14:43:13 +02004717 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004718 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004719 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004720 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4721 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004722
Johannes Berg4c476992010-10-04 21:36:35 +02004723 if (!rdev->ops->del_station)
4724 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004725
Jouni Malinen98856862014-10-20 13:20:45 +03004726 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4727 params.subtype =
4728 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4729 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4730 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4731 return -EINVAL;
4732 } else {
4733 /* Default to Deauthentication frame */
4734 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4735 }
4736
4737 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4738 params.reason_code =
4739 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4740 if (params.reason_code == 0)
4741 return -EINVAL; /* 0 is reserved */
4742 } else {
4743 /* Default to reason code 2 */
4744 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4745 }
4746
Jouni Malinen89c771e2014-10-10 20:52:40 +03004747 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004748}
4749
Eric W. Biederman15e47302012-09-07 20:12:54 +00004750static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004751 int flags, struct net_device *dev,
4752 u8 *dst, u8 *next_hop,
4753 struct mpath_info *pinfo)
4754{
4755 void *hdr;
4756 struct nlattr *pinfoattr;
4757
Henning Rogge1ef4c852014-11-04 16:14:58 +01004758 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004759 if (!hdr)
4760 return -1;
4761
David S. Miller9360ffd2012-03-29 04:41:26 -04004762 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4763 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4764 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4765 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4766 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004767
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004768 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4769 if (!pinfoattr)
4770 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004771 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4772 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4773 pinfo->frame_qlen))
4774 goto nla_put_failure;
4775 if (((pinfo->filled & MPATH_INFO_SN) &&
4776 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4777 ((pinfo->filled & MPATH_INFO_METRIC) &&
4778 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4779 pinfo->metric)) ||
4780 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4781 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4782 pinfo->exptime)) ||
4783 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4784 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4785 pinfo->flags)) ||
4786 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4787 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4788 pinfo->discovery_timeout)) ||
4789 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4790 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4791 pinfo->discovery_retries)))
4792 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004793
4794 nla_nest_end(msg, pinfoattr);
4795
Johannes Berg053c0952015-01-16 22:09:00 +01004796 genlmsg_end(msg, hdr);
4797 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004798
4799 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004800 genlmsg_cancel(msg, hdr);
4801 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004802}
4803
4804static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004805 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004806{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004807 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004808 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004809 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004810 u8 dst[ETH_ALEN];
4811 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004812 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004813 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004814
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004815 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004816 if (err)
4817 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004818
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004819 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004820 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004821 goto out_err;
4822 }
4823
Johannes Berg97990a02013-04-19 01:02:55 +02004824 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004825 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004826 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004827 }
4828
Johannes Bergbba95fe2008-07-29 13:22:51 +02004829 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004830 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004831 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004832 if (err == -ENOENT)
4833 break;
4834 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004835 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004836
Eric W. Biederman15e47302012-09-07 20:12:54 +00004837 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004838 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004839 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004840 &pinfo) < 0)
4841 goto out;
4842
4843 path_idx++;
4844 }
4845
Johannes Bergbba95fe2008-07-29 13:22:51 +02004846 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004847 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004848 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004849 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004850 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004851 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004852}
4853
4854static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4855{
Johannes Berg4c476992010-10-04 21:36:35 +02004856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004857 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004858 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004859 struct mpath_info pinfo;
4860 struct sk_buff *msg;
4861 u8 *dst = NULL;
4862 u8 next_hop[ETH_ALEN];
4863
4864 memset(&pinfo, 0, sizeof(pinfo));
4865
4866 if (!info->attrs[NL80211_ATTR_MAC])
4867 return -EINVAL;
4868
4869 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4870
Johannes Berg4c476992010-10-04 21:36:35 +02004871 if (!rdev->ops->get_mpath)
4872 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004873
Johannes Berg4c476992010-10-04 21:36:35 +02004874 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4875 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004876
Hila Gonene35e4d22012-06-27 17:19:42 +03004877 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004878 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004879 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004880
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004881 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004882 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004883 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004884
Eric W. Biederman15e47302012-09-07 20:12:54 +00004885 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004886 dev, dst, next_hop, &pinfo) < 0) {
4887 nlmsg_free(msg);
4888 return -ENOBUFS;
4889 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004890
Johannes Berg4c476992010-10-04 21:36:35 +02004891 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004892}
4893
4894static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4895{
Johannes Berg4c476992010-10-04 21:36:35 +02004896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4897 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004898 u8 *dst = NULL;
4899 u8 *next_hop = NULL;
4900
4901 if (!info->attrs[NL80211_ATTR_MAC])
4902 return -EINVAL;
4903
4904 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4905 return -EINVAL;
4906
4907 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4908 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4909
Johannes Berg4c476992010-10-04 21:36:35 +02004910 if (!rdev->ops->change_mpath)
4911 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004912
Johannes Berg4c476992010-10-04 21:36:35 +02004913 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4914 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004915
Hila Gonene35e4d22012-06-27 17:19:42 +03004916 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004917}
Johannes Berg4c476992010-10-04 21:36:35 +02004918
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004919static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4920{
Johannes Berg4c476992010-10-04 21:36:35 +02004921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4922 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004923 u8 *dst = NULL;
4924 u8 *next_hop = NULL;
4925
4926 if (!info->attrs[NL80211_ATTR_MAC])
4927 return -EINVAL;
4928
4929 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4930 return -EINVAL;
4931
4932 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4933 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4934
Johannes Berg4c476992010-10-04 21:36:35 +02004935 if (!rdev->ops->add_mpath)
4936 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004937
Johannes Berg4c476992010-10-04 21:36:35 +02004938 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4939 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004940
Hila Gonene35e4d22012-06-27 17:19:42 +03004941 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004942}
4943
4944static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4945{
Johannes Berg4c476992010-10-04 21:36:35 +02004946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4947 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004948 u8 *dst = NULL;
4949
4950 if (info->attrs[NL80211_ATTR_MAC])
4951 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4952
Johannes Berg4c476992010-10-04 21:36:35 +02004953 if (!rdev->ops->del_mpath)
4954 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004955
Hila Gonene35e4d22012-06-27 17:19:42 +03004956 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004957}
4958
Henning Rogge66be7d22014-09-12 08:58:49 +02004959static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4960{
4961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4962 int err;
4963 struct net_device *dev = info->user_ptr[1];
4964 struct mpath_info pinfo;
4965 struct sk_buff *msg;
4966 u8 *dst = NULL;
4967 u8 mpp[ETH_ALEN];
4968
4969 memset(&pinfo, 0, sizeof(pinfo));
4970
4971 if (!info->attrs[NL80211_ATTR_MAC])
4972 return -EINVAL;
4973
4974 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4975
4976 if (!rdev->ops->get_mpp)
4977 return -EOPNOTSUPP;
4978
4979 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4980 return -EOPNOTSUPP;
4981
4982 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4983 if (err)
4984 return err;
4985
4986 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4987 if (!msg)
4988 return -ENOMEM;
4989
4990 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4991 dev, dst, mpp, &pinfo) < 0) {
4992 nlmsg_free(msg);
4993 return -ENOBUFS;
4994 }
4995
4996 return genlmsg_reply(msg, info);
4997}
4998
4999static int nl80211_dump_mpp(struct sk_buff *skb,
5000 struct netlink_callback *cb)
5001{
5002 struct mpath_info pinfo;
5003 struct cfg80211_registered_device *rdev;
5004 struct wireless_dev *wdev;
5005 u8 dst[ETH_ALEN];
5006 u8 mpp[ETH_ALEN];
5007 int path_idx = cb->args[2];
5008 int err;
5009
5010 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5011 if (err)
5012 return err;
5013
5014 if (!rdev->ops->dump_mpp) {
5015 err = -EOPNOTSUPP;
5016 goto out_err;
5017 }
5018
5019 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5020 err = -EOPNOTSUPP;
5021 goto out_err;
5022 }
5023
5024 while (1) {
5025 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5026 mpp, &pinfo);
5027 if (err == -ENOENT)
5028 break;
5029 if (err)
5030 goto out_err;
5031
5032 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5033 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5034 wdev->netdev, dst, mpp,
5035 &pinfo) < 0)
5036 goto out;
5037
5038 path_idx++;
5039 }
5040
5041 out:
5042 cb->args[2] = path_idx;
5043 err = skb->len;
5044 out_err:
5045 nl80211_finish_wdev_dump(rdev);
5046 return err;
5047}
5048
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005049static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5050{
Johannes Berg4c476992010-10-04 21:36:35 +02005051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5052 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005053 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005054 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005055 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005056
5057 memset(&params, 0, sizeof(params));
5058 /* default to not changing parameters */
5059 params.use_cts_prot = -1;
5060 params.use_short_preamble = -1;
5061 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005062 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005063 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005064 params.p2p_ctwindow = -1;
5065 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005066
5067 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5068 params.use_cts_prot =
5069 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5070 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5071 params.use_short_preamble =
5072 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5073 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5074 params.use_short_slot_time =
5075 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005076 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5077 params.basic_rates =
5078 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5079 params.basic_rates_len =
5080 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5081 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005082 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5083 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005084 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5085 params.ht_opmode =
5086 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005087
Johannes Berg53cabad2012-11-14 15:17:28 +01005088 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5089 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5090 return -EINVAL;
5091 params.p2p_ctwindow =
5092 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5093 if (params.p2p_ctwindow < 0)
5094 return -EINVAL;
5095 if (params.p2p_ctwindow != 0 &&
5096 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5097 return -EINVAL;
5098 }
5099
5100 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5101 u8 tmp;
5102
5103 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5104 return -EINVAL;
5105 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5106 if (tmp > 1)
5107 return -EINVAL;
5108 params.p2p_opp_ps = tmp;
5109 if (params.p2p_opp_ps &&
5110 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5111 return -EINVAL;
5112 }
5113
Johannes Berg4c476992010-10-04 21:36:35 +02005114 if (!rdev->ops->change_bss)
5115 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005116
Johannes Berg074ac8d2010-09-16 14:58:22 +02005117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005118 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5119 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005120
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005121 wdev_lock(wdev);
5122 err = rdev_change_bss(rdev, dev, &params);
5123 wdev_unlock(wdev);
5124
5125 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005126}
5127
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005128static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5129{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005130 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005131 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005132 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005133 u32 owner_nlportid;
5134
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005135 /*
5136 * You should only get this when cfg80211 hasn't yet initialized
5137 * completely when built-in to the kernel right between the time
5138 * window between nl80211_init() and regulatory_init(), if that is
5139 * even possible.
5140 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005141 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005142 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005143
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005144 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5145 user_reg_hint_type =
5146 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5147 else
5148 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5149
5150 switch (user_reg_hint_type) {
5151 case NL80211_USER_REG_HINT_USER:
5152 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005153 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5154 return -EINVAL;
5155
5156 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5157 return regulatory_hint_user(data, user_reg_hint_type);
5158 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005159 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5160 owner_nlportid = info->snd_portid;
5161 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5162 } else {
5163 owner_nlportid = 0;
5164 is_indoor = true;
5165 }
5166
5167 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005168 default:
5169 return -EINVAL;
5170 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005171}
5172
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005173static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005174 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005175{
Johannes Berg4c476992010-10-04 21:36:35 +02005176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005177 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005178 struct wireless_dev *wdev = dev->ieee80211_ptr;
5179 struct mesh_config cur_params;
5180 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005181 void *hdr;
5182 struct nlattr *pinfoattr;
5183 struct sk_buff *msg;
5184
Johannes Berg29cbe682010-12-03 09:20:44 +01005185 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5186 return -EOPNOTSUPP;
5187
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005188 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005189 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005190
Johannes Berg29cbe682010-12-03 09:20:44 +01005191 wdev_lock(wdev);
5192 /* If not connected, get default parameters */
5193 if (!wdev->mesh_id_len)
5194 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5195 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005196 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005197 wdev_unlock(wdev);
5198
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005199 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005200 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005201
5202 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005203 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005204 if (!msg)
5205 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005206 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005207 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005208 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005209 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005210 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005211 if (!pinfoattr)
5212 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005213 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5214 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5215 cur_params.dot11MeshRetryTimeout) ||
5216 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5217 cur_params.dot11MeshConfirmTimeout) ||
5218 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5219 cur_params.dot11MeshHoldingTimeout) ||
5220 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5221 cur_params.dot11MeshMaxPeerLinks) ||
5222 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5223 cur_params.dot11MeshMaxRetries) ||
5224 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5225 cur_params.dot11MeshTTL) ||
5226 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5227 cur_params.element_ttl) ||
5228 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5229 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005230 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5231 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005232 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5233 cur_params.dot11MeshHWMPmaxPREQretries) ||
5234 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5235 cur_params.path_refresh_time) ||
5236 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5237 cur_params.min_discovery_timeout) ||
5238 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5239 cur_params.dot11MeshHWMPactivePathTimeout) ||
5240 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5241 cur_params.dot11MeshHWMPpreqMinInterval) ||
5242 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5243 cur_params.dot11MeshHWMPperrMinInterval) ||
5244 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5245 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5246 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5247 cur_params.dot11MeshHWMPRootMode) ||
5248 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5249 cur_params.dot11MeshHWMPRannInterval) ||
5250 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5251 cur_params.dot11MeshGateAnnouncementProtocol) ||
5252 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5253 cur_params.dot11MeshForwarding) ||
5254 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005255 cur_params.rssi_threshold) ||
5256 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005257 cur_params.ht_opmode) ||
5258 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5259 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5260 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005261 cur_params.dot11MeshHWMProotInterval) ||
5262 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005263 cur_params.dot11MeshHWMPconfirmationInterval) ||
5264 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5265 cur_params.power_mode) ||
5266 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005267 cur_params.dot11MeshAwakeWindowDuration) ||
5268 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5269 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005270 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005271 nla_nest_end(msg, pinfoattr);
5272 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005273 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005274
Johannes Berg3b858752009-03-12 09:55:09 +01005275 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005276 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005277 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005278 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005279 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005280}
5281
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005282static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005283 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5284 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5285 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5286 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5287 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5288 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005289 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005290 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005291 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005292 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5293 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5294 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5295 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5296 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005297 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005298 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005299 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005300 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005301 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005302 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005303 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5304 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005305 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5306 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005307 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005308 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5309 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005310 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005311};
5312
Javier Cardonac80d5452010-12-16 17:37:49 -08005313static const struct nla_policy
5314 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005315 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005316 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5317 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005318 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005319 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005320 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005321 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005322 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005323 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005324};
5325
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005326static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5327{
5328 u8 val = nla_get_u8(nla);
5329 if (val < min || val > max)
5330 return -EINVAL;
5331 *out = val;
5332 return 0;
5333}
5334
5335static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5336{
5337 u8 val = nla_get_u8(nla);
5338 if (val < min || val > max)
5339 return -EINVAL;
5340 *out = val;
5341 return 0;
5342}
5343
5344static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5345{
5346 u16 val = nla_get_u16(nla);
5347 if (val < min || val > max)
5348 return -EINVAL;
5349 *out = val;
5350 return 0;
5351}
5352
5353static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5354{
5355 u32 val = nla_get_u32(nla);
5356 if (val < min || val > max)
5357 return -EINVAL;
5358 *out = val;
5359 return 0;
5360}
5361
5362static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5363{
5364 s32 val = nla_get_s32(nla);
5365 if (val < min || val > max)
5366 return -EINVAL;
5367 *out = val;
5368 return 0;
5369}
5370
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005371static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005372 struct mesh_config *cfg,
5373 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005374{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005375 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005376 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005377
Marco Porschea54fba2013-01-07 16:04:48 +01005378#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5379do { \
5380 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005381 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005382 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005383 mask |= (1 << (attr - 1)); \
5384 } \
5385} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005386
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005387 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005388 return -EINVAL;
5389 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005390 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005391 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005392 return -EINVAL;
5393
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005394 /* This makes sure that there aren't more than 32 mesh config
5395 * parameters (otherwise our bitfield scheme would not work.) */
5396 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5397
5398 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005399 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005400 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005401 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005402 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005403 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005404 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005405 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005406 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005407 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005408 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005409 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005410 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005412 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005413 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005414 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005415 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005416 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005417 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005418 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005419 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005420 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005421 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005422 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5423 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005424 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005425 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005426 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005427 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005428 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005429 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005430 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005431 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005433 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005434 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5436 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005437 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005438 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005439 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005440 1, 65535, mask,
5441 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005442 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005443 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005444 1, 65535, mask,
5445 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005446 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005447 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005448 dot11MeshHWMPnetDiameterTraversalTime,
5449 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005450 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005451 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005452 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5453 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005454 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005455 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5456 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005457 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005458 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005459 dot11MeshGateAnnouncementProtocol, 0, 1,
5460 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005461 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005462 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005463 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005464 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005465 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005466 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005467 nl80211_check_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005468 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005469 mask, NL80211_MESHCONF_HT_OPMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005470 nl80211_check_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005471 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005472 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005473 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005474 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005475 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005476 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005477 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005478 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005479 dot11MeshHWMPconfirmationInterval,
5480 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005481 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005482 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005483 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5484 NL80211_MESH_POWER_ACTIVE,
5485 NL80211_MESH_POWER_MAX,
5486 mask, NL80211_MESHCONF_POWER_MODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005487 nl80211_check_u32);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005488 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5489 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005490 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005491 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005492 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005493 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005494 if (mask_out)
5495 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005496
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005497 return 0;
5498
5499#undef FILL_IN_MESH_PARAM_IF_SET
5500}
5501
Javier Cardonac80d5452010-12-16 17:37:49 -08005502static int nl80211_parse_mesh_setup(struct genl_info *info,
5503 struct mesh_setup *setup)
5504{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005506 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5507
5508 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5509 return -EINVAL;
5510 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5511 info->attrs[NL80211_ATTR_MESH_SETUP],
5512 nl80211_mesh_setup_params_policy))
5513 return -EINVAL;
5514
Javier Cardonad299a1f2012-03-31 11:31:33 -07005515 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5516 setup->sync_method =
5517 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5518 IEEE80211_SYNC_METHOD_VENDOR :
5519 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5520
Javier Cardonac80d5452010-12-16 17:37:49 -08005521 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5522 setup->path_sel_proto =
5523 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5524 IEEE80211_PATH_PROTOCOL_VENDOR :
5525 IEEE80211_PATH_PROTOCOL_HWMP;
5526
5527 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5528 setup->path_metric =
5529 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5530 IEEE80211_PATH_METRIC_VENDOR :
5531 IEEE80211_PATH_METRIC_AIRTIME;
5532
Javier Cardona581a8b02011-04-07 15:08:27 -07005533 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005534 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005535 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005536 if (!is_valid_ie_attr(ieattr))
5537 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005538 setup->ie = nla_data(ieattr);
5539 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005540 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005541 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5542 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5543 return -EINVAL;
5544 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005545 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5546 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005547 if (setup->is_secure)
5548 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005549
Colleen Twitty6e16d902013-05-08 11:45:59 -07005550 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5551 if (!setup->user_mpm)
5552 return -EINVAL;
5553 setup->auth_id =
5554 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5555 }
5556
Javier Cardonac80d5452010-12-16 17:37:49 -08005557 return 0;
5558}
5559
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005560static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005561 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005562{
5563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5564 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005565 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005566 struct mesh_config cfg;
5567 u32 mask;
5568 int err;
5569
Johannes Berg29cbe682010-12-03 09:20:44 +01005570 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5571 return -EOPNOTSUPP;
5572
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005573 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005574 return -EOPNOTSUPP;
5575
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005576 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005577 if (err)
5578 return err;
5579
Johannes Berg29cbe682010-12-03 09:20:44 +01005580 wdev_lock(wdev);
5581 if (!wdev->mesh_id_len)
5582 err = -ENOLINK;
5583
5584 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005585 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005586
5587 wdev_unlock(wdev);
5588
5589 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005590}
5591
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005592static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5593 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005594{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005595 struct nlattr *nl_reg_rules;
5596 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005597
Johannes Berg458f4f92012-12-06 15:47:38 +01005598 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5599 (regdom->dfs_region &&
5600 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005601 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005602
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005603 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5604 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005605 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005606
Johannes Berg458f4f92012-12-06 15:47:38 +01005607 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005608 struct nlattr *nl_reg_rule;
5609 const struct ieee80211_reg_rule *reg_rule;
5610 const struct ieee80211_freq_range *freq_range;
5611 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005612 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005613
Johannes Berg458f4f92012-12-06 15:47:38 +01005614 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005615 freq_range = &reg_rule->freq_range;
5616 power_rule = &reg_rule->power_rule;
5617
5618 nl_reg_rule = nla_nest_start(msg, i);
5619 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005620 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005621
Janusz Dziedzic97524822014-01-30 09:52:20 +01005622 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5623 if (!max_bandwidth_khz)
5624 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5625 reg_rule);
5626
David S. Miller9360ffd2012-03-29 04:41:26 -04005627 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5628 reg_rule->flags) ||
5629 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5630 freq_range->start_freq_khz) ||
5631 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5632 freq_range->end_freq_khz) ||
5633 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005634 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005635 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5636 power_rule->max_antenna_gain) ||
5637 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005638 power_rule->max_eirp) ||
5639 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5640 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005641 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005642
5643 nla_nest_end(msg, nl_reg_rule);
5644 }
5645
5646 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005647 return 0;
5648
5649nla_put_failure:
5650 return -EMSGSIZE;
5651}
5652
5653static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5654{
5655 const struct ieee80211_regdomain *regdom = NULL;
5656 struct cfg80211_registered_device *rdev;
5657 struct wiphy *wiphy = NULL;
5658 struct sk_buff *msg;
5659 void *hdr;
5660
5661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5662 if (!msg)
5663 return -ENOBUFS;
5664
5665 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5666 NL80211_CMD_GET_REG);
5667 if (!hdr)
5668 goto put_failure;
5669
5670 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005671 bool self_managed;
5672
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005673 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5674 if (IS_ERR(rdev)) {
5675 nlmsg_free(msg);
5676 return PTR_ERR(rdev);
5677 }
5678
5679 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005680 self_managed = wiphy->regulatory_flags &
5681 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005682 regdom = get_wiphy_regdom(wiphy);
5683
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005684 /* a self-managed-reg device must have a private regdom */
5685 if (WARN_ON(!regdom && self_managed)) {
5686 nlmsg_free(msg);
5687 return -EINVAL;
5688 }
5689
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005690 if (regdom &&
5691 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5692 goto nla_put_failure;
5693 }
5694
5695 if (!wiphy && reg_last_request_cell_base() &&
5696 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5697 NL80211_USER_REG_HINT_CELL_BASE))
5698 goto nla_put_failure;
5699
5700 rcu_read_lock();
5701
5702 if (!regdom)
5703 regdom = rcu_dereference(cfg80211_regdomain);
5704
5705 if (nl80211_put_regdom(regdom, msg))
5706 goto nla_put_failure_rcu;
5707
5708 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005709
5710 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005711 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005712
Johannes Berg458f4f92012-12-06 15:47:38 +01005713nla_put_failure_rcu:
5714 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005715nla_put_failure:
5716 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005717put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005718 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005719 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005720}
5721
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005722static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5723 u32 seq, int flags, struct wiphy *wiphy,
5724 const struct ieee80211_regdomain *regdom)
5725{
5726 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5727 NL80211_CMD_GET_REG);
5728
5729 if (!hdr)
5730 return -1;
5731
5732 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5733
5734 if (nl80211_put_regdom(regdom, msg))
5735 goto nla_put_failure;
5736
5737 if (!wiphy && reg_last_request_cell_base() &&
5738 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5739 NL80211_USER_REG_HINT_CELL_BASE))
5740 goto nla_put_failure;
5741
5742 if (wiphy &&
5743 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5744 goto nla_put_failure;
5745
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005746 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5747 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5748 goto nla_put_failure;
5749
Johannes Berg053c0952015-01-16 22:09:00 +01005750 genlmsg_end(msg, hdr);
5751 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005752
5753nla_put_failure:
5754 genlmsg_cancel(msg, hdr);
5755 return -EMSGSIZE;
5756}
5757
5758static int nl80211_get_reg_dump(struct sk_buff *skb,
5759 struct netlink_callback *cb)
5760{
5761 const struct ieee80211_regdomain *regdom = NULL;
5762 struct cfg80211_registered_device *rdev;
5763 int err, reg_idx, start = cb->args[2];
5764
5765 rtnl_lock();
5766
5767 if (cfg80211_regdomain && start == 0) {
5768 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5769 NLM_F_MULTI, NULL,
5770 rtnl_dereference(cfg80211_regdomain));
5771 if (err < 0)
5772 goto out_err;
5773 }
5774
5775 /* the global regdom is idx 0 */
5776 reg_idx = 1;
5777 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5778 regdom = get_wiphy_regdom(&rdev->wiphy);
5779 if (!regdom)
5780 continue;
5781
5782 if (++reg_idx <= start)
5783 continue;
5784
5785 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5786 NLM_F_MULTI, &rdev->wiphy, regdom);
5787 if (err < 0) {
5788 reg_idx--;
5789 break;
5790 }
5791 }
5792
5793 cb->args[2] = reg_idx;
5794 err = skb->len;
5795out_err:
5796 rtnl_unlock();
5797 return err;
5798}
5799
Johannes Bergb6863032015-10-15 09:25:18 +02005800#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5801static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5802 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5803 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5804 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5805 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5806 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5807 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5808 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5809};
5810
5811static int parse_reg_rule(struct nlattr *tb[],
5812 struct ieee80211_reg_rule *reg_rule)
5813{
5814 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5815 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5816
5817 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5818 return -EINVAL;
5819 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5820 return -EINVAL;
5821 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5822 return -EINVAL;
5823 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5824 return -EINVAL;
5825 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5826 return -EINVAL;
5827
5828 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5829
5830 freq_range->start_freq_khz =
5831 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5832 freq_range->end_freq_khz =
5833 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5834 freq_range->max_bandwidth_khz =
5835 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5836
5837 power_rule->max_eirp =
5838 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5839
5840 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5841 power_rule->max_antenna_gain =
5842 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5843
5844 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5845 reg_rule->dfs_cac_ms =
5846 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5847
5848 return 0;
5849}
5850
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005851static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5852{
5853 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5854 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005855 char *alpha2;
5856 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005857 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005858 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005859 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005860
5861 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5862 return -EINVAL;
5863
5864 if (!info->attrs[NL80211_ATTR_REG_RULES])
5865 return -EINVAL;
5866
5867 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5868
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005869 if (info->attrs[NL80211_ATTR_DFS_REGION])
5870 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5871
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005872 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005873 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005874 num_rules++;
5875 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005876 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005877 }
5878
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005879 if (!reg_is_valid_request(alpha2))
5880 return -EINVAL;
5881
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005882 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005883 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005884
5885 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005886 if (!rd)
5887 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005888
5889 rd->n_reg_rules = num_rules;
5890 rd->alpha2[0] = alpha2[0];
5891 rd->alpha2[1] = alpha2[1];
5892
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005893 /*
5894 * Disable DFS master mode if the DFS region was
5895 * not supported or known on this kernel.
5896 */
5897 if (reg_supported_dfs_region(dfs_region))
5898 rd->dfs_region = dfs_region;
5899
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005900 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005901 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005902 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5903 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5904 reg_rule_policy);
5905 if (r)
5906 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005907 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5908 if (r)
5909 goto bad_reg;
5910
5911 rule_idx++;
5912
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005913 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5914 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005915 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005916 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005917 }
5918
Johannes Berg06627992016-06-09 10:40:09 +02005919 /* set_regdom takes ownership of rd */
5920 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02005921 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005922 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005923 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005924}
Johannes Bergb6863032015-10-15 09:25:18 +02005925#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005926
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005927static int validate_scan_freqs(struct nlattr *freqs)
5928{
5929 struct nlattr *attr1, *attr2;
5930 int n_channels = 0, tmp1, tmp2;
5931
5932 nla_for_each_nested(attr1, freqs, tmp1) {
5933 n_channels++;
5934 /*
5935 * Some hardware has a limited channel list for
5936 * scanning, and it is pretty much nonsensical
5937 * to scan for a channel twice, so disallow that
5938 * and don't require drivers to check that the
5939 * channel list they get isn't longer than what
5940 * they can scan, as long as they can scan all
5941 * the channels they registered at once.
5942 */
5943 nla_for_each_nested(attr2, freqs, tmp2)
5944 if (attr1 != attr2 &&
5945 nla_get_u32(attr1) == nla_get_u32(attr2))
5946 return 0;
5947 }
5948
5949 return n_channels;
5950}
5951
Johannes Berg57fbcce2016-04-12 15:56:15 +02005952static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005953{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005954 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005955}
5956
5957static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5958 struct cfg80211_bss_selection *bss_select)
5959{
5960 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5961 struct nlattr *nest;
5962 int err;
5963 bool found = false;
5964 int i;
5965
5966 /* only process one nested attribute */
5967 nest = nla_data(nla);
5968 if (!nla_ok(nest, nla_len(nest)))
5969 return -EINVAL;
5970
5971 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5972 nla_len(nest), nl80211_bss_select_policy);
5973 if (err)
5974 return err;
5975
5976 /* only one attribute may be given */
5977 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
5978 if (attr[i]) {
5979 if (found)
5980 return -EINVAL;
5981 found = true;
5982 }
5983 }
5984
5985 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
5986
5987 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
5988 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
5989
5990 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
5991 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
5992 bss_select->param.band_pref =
5993 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
5994 if (!is_band_valid(wiphy, bss_select->param.band_pref))
5995 return -EINVAL;
5996 }
5997
5998 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
5999 struct nl80211_bss_select_rssi_adjust *adj_param;
6000
6001 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6002 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6003 bss_select->param.adjust.band = adj_param->band;
6004 bss_select->param.adjust.delta = adj_param->delta;
6005 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6006 return -EINVAL;
6007 }
6008
6009 /* user-space did not provide behaviour attribute */
6010 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6011 return -EINVAL;
6012
6013 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6014 return -EINVAL;
6015
6016 return 0;
6017}
6018
Johannes Bergad2b26a2014-06-12 21:39:05 +02006019static int nl80211_parse_random_mac(struct nlattr **attrs,
6020 u8 *mac_addr, u8 *mac_addr_mask)
6021{
6022 int i;
6023
6024 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006025 eth_zero_addr(mac_addr);
6026 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006027 mac_addr[0] = 0x2;
6028 mac_addr_mask[0] = 0x3;
6029
6030 return 0;
6031 }
6032
6033 /* need both or none */
6034 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6035 return -EINVAL;
6036
6037 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6038 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6039
6040 /* don't allow or configure an mcast address */
6041 if (!is_multicast_ether_addr(mac_addr_mask) ||
6042 is_multicast_ether_addr(mac_addr))
6043 return -EINVAL;
6044
6045 /*
6046 * allow users to pass a MAC address that has bits set outside
6047 * of the mask, but don't bother drivers with having to deal
6048 * with such bits
6049 */
6050 for (i = 0; i < ETH_ALEN; i++)
6051 mac_addr[i] &= mac_addr_mask[i];
6052
6053 return 0;
6054}
6055
Johannes Berg2a519312009-02-10 21:25:55 +01006056static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6057{
Johannes Berg4c476992010-10-04 21:36:35 +02006058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006059 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006060 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006061 struct nlattr *attr;
6062 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006063 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006064 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006065
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006066 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6067 return -EINVAL;
6068
Johannes Berg79c97e92009-07-07 03:56:12 +02006069 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006070
Johannes Berg4c476992010-10-04 21:36:35 +02006071 if (!rdev->ops->scan)
6072 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006073
Johannes Bergf9d15d12014-01-22 11:14:19 +02006074 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006075 err = -EBUSY;
6076 goto unlock;
6077 }
Johannes Berg2a519312009-02-10 21:25:55 +01006078
6079 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006080 n_channels = validate_scan_freqs(
6081 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006082 if (!n_channels) {
6083 err = -EINVAL;
6084 goto unlock;
6085 }
Johannes Berg2a519312009-02-10 21:25:55 +01006086 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006087 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006088 }
6089
6090 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6091 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6092 n_ssids++;
6093
Johannes Bergf9f47522013-03-19 15:04:07 +01006094 if (n_ssids > wiphy->max_scan_ssids) {
6095 err = -EINVAL;
6096 goto unlock;
6097 }
Johannes Berg2a519312009-02-10 21:25:55 +01006098
Jouni Malinen70692ad2009-02-16 19:39:13 +02006099 if (info->attrs[NL80211_ATTR_IE])
6100 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6101 else
6102 ie_len = 0;
6103
Johannes Bergf9f47522013-03-19 15:04:07 +01006104 if (ie_len > wiphy->max_scan_ie_len) {
6105 err = -EINVAL;
6106 goto unlock;
6107 }
Johannes Berg18a83652009-03-31 12:12:05 +02006108
Johannes Berg2a519312009-02-10 21:25:55 +01006109 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006110 + sizeof(*request->ssids) * n_ssids
6111 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006112 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006113 if (!request) {
6114 err = -ENOMEM;
6115 goto unlock;
6116 }
Johannes Berg2a519312009-02-10 21:25:55 +01006117
Johannes Berg2a519312009-02-10 21:25:55 +01006118 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006119 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006120 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006121 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006122 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006123 request->ie = (void *)(request->ssids + n_ssids);
6124 else
6125 request->ie = (void *)(request->channels + n_channels);
6126 }
Johannes Berg2a519312009-02-10 21:25:55 +01006127
Johannes Berg584991d2009-11-02 13:32:03 +01006128 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006129 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6130 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006131 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006132 struct ieee80211_channel *chan;
6133
6134 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6135
6136 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006137 err = -EINVAL;
6138 goto out_free;
6139 }
Johannes Berg584991d2009-11-02 13:32:03 +01006140
6141 /* ignore disabled channels */
6142 if (chan->flags & IEEE80211_CHAN_DISABLED)
6143 continue;
6144
6145 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006146 i++;
6147 }
6148 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006149 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006150
Johannes Berg2a519312009-02-10 21:25:55 +01006151 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006152 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006153 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006154
Johannes Berg2a519312009-02-10 21:25:55 +01006155 if (!wiphy->bands[band])
6156 continue;
6157 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006158 struct ieee80211_channel *chan;
6159
6160 chan = &wiphy->bands[band]->channels[j];
6161
6162 if (chan->flags & IEEE80211_CHAN_DISABLED)
6163 continue;
6164
6165 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006166 i++;
6167 }
6168 }
6169 }
6170
Johannes Berg584991d2009-11-02 13:32:03 +01006171 if (!i) {
6172 err = -EINVAL;
6173 goto out_free;
6174 }
6175
6176 request->n_channels = i;
6177
Johannes Berg2a519312009-02-10 21:25:55 +01006178 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006179 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006180 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006181 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006182 err = -EINVAL;
6183 goto out_free;
6184 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006185 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006186 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006187 i++;
6188 }
6189 }
6190
Jouni Malinen70692ad2009-02-16 19:39:13 +02006191 if (info->attrs[NL80211_ATTR_IE]) {
6192 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006193 memcpy((void *)request->ie,
6194 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006195 request->ie_len);
6196 }
6197
Johannes Berg57fbcce2016-04-12 15:56:15 +02006198 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006199 if (wiphy->bands[i])
6200 request->rates[i] =
6201 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006202
6203 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6204 nla_for_each_nested(attr,
6205 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6206 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006207 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006208
Johannes Berg57fbcce2016-04-12 15:56:15 +02006209 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006210 err = -EINVAL;
6211 goto out_free;
6212 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006213
6214 if (!wiphy->bands[band])
6215 continue;
6216
Johannes Berg34850ab2011-07-18 18:08:35 +02006217 err = ieee80211_get_ratemask(wiphy->bands[band],
6218 nla_data(attr),
6219 nla_len(attr),
6220 &request->rates[band]);
6221 if (err)
6222 goto out_free;
6223 }
6224 }
6225
Avraham Stern1d762502016-07-05 17:10:13 +03006226 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6227 if (!wiphy_ext_feature_isset(wiphy,
6228 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6229 err = -EOPNOTSUPP;
6230 goto out_free;
6231 }
6232
6233 request->duration =
6234 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6235 request->duration_mandatory =
6236 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6237 }
6238
Sam Leffler46856bb2012-10-11 21:03:32 -07006239 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006240 request->flags = nla_get_u32(
6241 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006242 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6243 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006244 err = -EOPNOTSUPP;
6245 goto out_free;
6246 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006247
6248 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6249 if (!(wiphy->features &
6250 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6251 err = -EOPNOTSUPP;
6252 goto out_free;
6253 }
6254
6255 if (wdev->current_bss) {
6256 err = -EOPNOTSUPP;
6257 goto out_free;
6258 }
6259
6260 err = nl80211_parse_random_mac(info->attrs,
6261 request->mac_addr,
6262 request->mac_addr_mask);
6263 if (err)
6264 goto out_free;
6265 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006266 }
Sam Lefflered4737712012-10-11 21:03:31 -07006267
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306268 request->no_cck =
6269 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6270
Jouni Malinen818965d2016-02-26 22:12:47 +02006271 if (info->attrs[NL80211_ATTR_MAC])
6272 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6273 ETH_ALEN);
6274 else
6275 eth_broadcast_addr(request->bssid);
6276
Johannes Bergfd014282012-06-18 19:17:03 +02006277 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006278 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006279 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006280
Johannes Berg79c97e92009-07-07 03:56:12 +02006281 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006282 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006283
Johannes Berg463d0182009-07-14 00:33:35 +02006284 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006285 nl80211_send_scan_start(rdev, wdev);
6286 if (wdev->netdev)
6287 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006288 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006289 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006290 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006291 kfree(request);
6292 }
Johannes Berg3b858752009-03-12 09:55:09 +01006293
Johannes Bergf9f47522013-03-19 15:04:07 +01006294 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006295 return err;
6296}
6297
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306298static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6299{
6300 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6301 struct wireless_dev *wdev = info->user_ptr[1];
6302
6303 if (!rdev->ops->abort_scan)
6304 return -EOPNOTSUPP;
6305
6306 if (rdev->scan_msg)
6307 return 0;
6308
6309 if (!rdev->scan_req)
6310 return -ENOENT;
6311
6312 rdev_abort_scan(rdev, wdev);
6313 return 0;
6314}
6315
Avraham Stern3b06d272015-10-12 09:51:34 +03006316static int
6317nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6318 struct cfg80211_sched_scan_request *request,
6319 struct nlattr **attrs)
6320{
6321 int tmp, err, i = 0;
6322 struct nlattr *attr;
6323
6324 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6325 u32 interval;
6326
6327 /*
6328 * If scan plans are not specified,
6329 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6330 * case one scan plan will be set with the specified scan
6331 * interval and infinite number of iterations.
6332 */
6333 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6334 return -EINVAL;
6335
6336 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6337 if (!interval)
6338 return -EINVAL;
6339
6340 request->scan_plans[0].interval =
6341 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6342 if (!request->scan_plans[0].interval)
6343 return -EINVAL;
6344
6345 if (request->scan_plans[0].interval >
6346 wiphy->max_sched_scan_plan_interval)
6347 request->scan_plans[0].interval =
6348 wiphy->max_sched_scan_plan_interval;
6349
6350 return 0;
6351 }
6352
6353 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6354 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6355
6356 if (WARN_ON(i >= n_plans))
6357 return -EINVAL;
6358
6359 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6360 nla_data(attr), nla_len(attr),
6361 nl80211_plan_policy);
6362 if (err)
6363 return err;
6364
6365 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6366 return -EINVAL;
6367
6368 request->scan_plans[i].interval =
6369 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6370 if (!request->scan_plans[i].interval ||
6371 request->scan_plans[i].interval >
6372 wiphy->max_sched_scan_plan_interval)
6373 return -EINVAL;
6374
6375 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6376 request->scan_plans[i].iterations =
6377 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6378 if (!request->scan_plans[i].iterations ||
6379 (request->scan_plans[i].iterations >
6380 wiphy->max_sched_scan_plan_iterations))
6381 return -EINVAL;
6382 } else if (i < n_plans - 1) {
6383 /*
6384 * All scan plans but the last one must specify
6385 * a finite number of iterations
6386 */
6387 return -EINVAL;
6388 }
6389
6390 i++;
6391 }
6392
6393 /*
6394 * The last scan plan must not specify the number of
6395 * iterations, it is supposed to run infinitely
6396 */
6397 if (request->scan_plans[n_plans - 1].iterations)
6398 return -EINVAL;
6399
6400 return 0;
6401}
6402
Luciano Coelho256da022014-11-10 16:13:46 +02006403static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006404nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006405 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006406{
6407 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006408 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006409 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006410 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006411 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006412 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006413 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006414
Luciano Coelho256da022014-11-10 16:13:46 +02006415 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6416 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006417
Luciano Coelho256da022014-11-10 16:13:46 +02006418 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006419 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006420 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006421 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006422 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006423 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006424 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006425 }
6426
Luciano Coelho256da022014-11-10 16:13:46 +02006427 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6428 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006429 tmp)
6430 n_ssids++;
6431
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006432 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006433 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006434
Johannes Bergea73cbc2014-01-24 10:53:53 +01006435 /*
6436 * First, count the number of 'real' matchsets. Due to an issue with
6437 * the old implementation, matchsets containing only the RSSI attribute
6438 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6439 * RSSI for all matchsets, rather than their own matchset for reporting
6440 * all APs with a strong RSSI. This is needed to be compatible with
6441 * older userspace that treated a matchset with only the RSSI as the
6442 * global RSSI for all other matchsets - if there are other matchsets.
6443 */
Luciano Coelho256da022014-11-10 16:13:46 +02006444 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006445 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006446 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006447 tmp) {
6448 struct nlattr *rssi;
6449
6450 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6451 nla_data(attr), nla_len(attr),
6452 nl80211_match_policy);
6453 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006454 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006455 /* add other standalone attributes here */
6456 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6457 n_match_sets++;
6458 continue;
6459 }
6460 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6461 if (rssi)
6462 default_match_rssi = nla_get_s32(rssi);
6463 }
6464 }
6465
6466 /* However, if there's no other matchset, add the RSSI one */
6467 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6468 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006469
6470 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006471 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006472
Luciano Coelho256da022014-11-10 16:13:46 +02006473 if (attrs[NL80211_ATTR_IE])
6474 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006475 else
6476 ie_len = 0;
6477
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006478 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006479 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006480
Avraham Stern3b06d272015-10-12 09:51:34 +03006481 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6482 /*
6483 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6484 * each scan plan already specifies its own interval
6485 */
6486 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6487 return ERR_PTR(-EINVAL);
6488
6489 nla_for_each_nested(attr,
6490 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6491 n_plans++;
6492 } else {
6493 /*
6494 * The scan interval attribute is kept for backward
6495 * compatibility. If no scan plans are specified and sched scan
6496 * interval is specified, one scan plan will be set with this
6497 * scan interval and infinite number of iterations.
6498 */
6499 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6500 return ERR_PTR(-EINVAL);
6501
6502 n_plans = 1;
6503 }
6504
6505 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6506 return ERR_PTR(-EINVAL);
6507
Luciano Coelho807f8a82011-05-11 17:09:35 +03006508 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006509 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006510 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006511 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006512 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006513 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006514 if (!request)
6515 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006516
6517 if (n_ssids)
6518 request->ssids = (void *)&request->channels[n_channels];
6519 request->n_ssids = n_ssids;
6520 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006521 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006522 request->ie = (void *)(request->ssids + n_ssids);
6523 else
6524 request->ie = (void *)(request->channels + n_channels);
6525 }
6526
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006527 if (n_match_sets) {
6528 if (request->ie)
6529 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006530 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006531 request->match_sets =
6532 (void *)(request->ssids + n_ssids);
6533 else
6534 request->match_sets =
6535 (void *)(request->channels + n_channels);
6536 }
6537 request->n_match_sets = n_match_sets;
6538
Avraham Stern3b06d272015-10-12 09:51:34 +03006539 if (n_match_sets)
6540 request->scan_plans = (void *)(request->match_sets +
6541 n_match_sets);
6542 else if (request->ie)
6543 request->scan_plans = (void *)(request->ie + ie_len);
6544 else if (n_ssids)
6545 request->scan_plans = (void *)(request->ssids + n_ssids);
6546 else
6547 request->scan_plans = (void *)(request->channels + n_channels);
6548
6549 request->n_scan_plans = n_plans;
6550
Luciano Coelho807f8a82011-05-11 17:09:35 +03006551 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006552 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006553 /* user specified, bail out if channel not found */
6554 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006555 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006556 tmp) {
6557 struct ieee80211_channel *chan;
6558
6559 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6560
6561 if (!chan) {
6562 err = -EINVAL;
6563 goto out_free;
6564 }
6565
6566 /* ignore disabled channels */
6567 if (chan->flags & IEEE80211_CHAN_DISABLED)
6568 continue;
6569
6570 request->channels[i] = chan;
6571 i++;
6572 }
6573 } else {
6574 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006575 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006576 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006577
Luciano Coelho807f8a82011-05-11 17:09:35 +03006578 if (!wiphy->bands[band])
6579 continue;
6580 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6581 struct ieee80211_channel *chan;
6582
6583 chan = &wiphy->bands[band]->channels[j];
6584
6585 if (chan->flags & IEEE80211_CHAN_DISABLED)
6586 continue;
6587
6588 request->channels[i] = chan;
6589 i++;
6590 }
6591 }
6592 }
6593
6594 if (!i) {
6595 err = -EINVAL;
6596 goto out_free;
6597 }
6598
6599 request->n_channels = i;
6600
6601 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006602 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006603 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006604 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006605 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006606 err = -EINVAL;
6607 goto out_free;
6608 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006609 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006610 memcpy(request->ssids[i].ssid, nla_data(attr),
6611 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006612 i++;
6613 }
6614 }
6615
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006616 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006617 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006618 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006619 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006620 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006621 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006622
Johannes Bergae811e22014-01-24 10:17:47 +01006623 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6624 nla_data(attr), nla_len(attr),
6625 nl80211_match_policy);
6626 if (err)
6627 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006628 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006629 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006630 if (WARN_ON(i >= n_match_sets)) {
6631 /* this indicates a programming error,
6632 * the loop above should have verified
6633 * things properly
6634 */
6635 err = -EINVAL;
6636 goto out_free;
6637 }
6638
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006639 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6640 err = -EINVAL;
6641 goto out_free;
6642 }
6643 memcpy(request->match_sets[i].ssid.ssid,
6644 nla_data(ssid), nla_len(ssid));
6645 request->match_sets[i].ssid.ssid_len =
6646 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07006647 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01006648 request->match_sets[i].rssi_thold =
6649 default_match_rssi;
6650 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6651 if (rssi)
6652 request->match_sets[i].rssi_thold =
6653 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006654 }
6655 i++;
6656 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006657
6658 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006659 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006660 request->match_sets[0].rssi_thold = default_match_rssi;
6661
6662 request->min_rssi_thold = INT_MAX;
6663 for (i = 0; i < n_match_sets; i++)
6664 request->min_rssi_thold =
6665 min(request->match_sets[i].rssi_thold,
6666 request->min_rssi_thold);
6667 } else {
6668 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006669 }
6670
Johannes Berg9900e482014-02-04 21:01:25 +01006671 if (ie_len) {
6672 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006673 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006674 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006675 request->ie_len);
6676 }
6677
Luciano Coelho256da022014-11-10 16:13:46 +02006678 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006679 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006680 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006681 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6682 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006683 err = -EOPNOTSUPP;
6684 goto out_free;
6685 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006686
6687 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6688 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6689
6690 if (!wdev) /* must be net-detect */
6691 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6692
6693 if (!(wiphy->features & flg)) {
6694 err = -EOPNOTSUPP;
6695 goto out_free;
6696 }
6697
6698 if (wdev && wdev->current_bss) {
6699 err = -EOPNOTSUPP;
6700 goto out_free;
6701 }
6702
6703 err = nl80211_parse_random_mac(attrs, 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
Luciano Coelho9c748932015-01-16 16:04:09 +02006710 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6711 request->delay =
6712 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6713
Avraham Stern3b06d272015-10-12 09:51:34 +03006714 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6715 if (err)
6716 goto out_free;
6717
Sam Leffler15d60302012-10-11 21:03:34 -07006718 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006719
Luciano Coelho256da022014-11-10 16:13:46 +02006720 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006721
6722out_free:
6723 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006724 return ERR_PTR(err);
6725}
6726
6727static int nl80211_start_sched_scan(struct sk_buff *skb,
6728 struct genl_info *info)
6729{
6730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6731 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006732 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006733 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006734 int err;
6735
6736 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6737 !rdev->ops->sched_scan_start)
6738 return -EOPNOTSUPP;
6739
6740 if (rdev->sched_scan_req)
6741 return -EINPROGRESS;
6742
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006743 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6744 info->attrs);
6745
6746 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006747 if (err)
6748 goto out_err;
6749
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006750 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006751 if (err)
6752 goto out_free;
6753
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006754 sched_scan_req->dev = dev;
6755 sched_scan_req->wiphy = &rdev->wiphy;
6756
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006757 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6758 sched_scan_req->owner_nlportid = info->snd_portid;
6759
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006760 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006761
6762 nl80211_send_sched_scan(rdev, dev,
6763 NL80211_CMD_START_SCHED_SCAN);
6764 return 0;
6765
6766out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006767 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006768out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006769 return err;
6770}
6771
6772static int nl80211_stop_sched_scan(struct sk_buff *skb,
6773 struct genl_info *info)
6774{
6775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6776
6777 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6778 !rdev->ops->sched_scan_stop)
6779 return -EOPNOTSUPP;
6780
Johannes Berg5fe231e2013-05-08 21:45:15 +02006781 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006782}
6783
Simon Wunderlich04f39042013-02-08 18:16:19 +01006784static int nl80211_start_radar_detection(struct sk_buff *skb,
6785 struct genl_info *info)
6786{
6787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6788 struct net_device *dev = info->user_ptr[1];
6789 struct wireless_dev *wdev = dev->ieee80211_ptr;
6790 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006791 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006792 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006793 int err;
6794
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006795 dfs_region = reg_get_dfs_region(wdev->wiphy);
6796 if (dfs_region == NL80211_DFS_UNSET)
6797 return -EINVAL;
6798
Simon Wunderlich04f39042013-02-08 18:16:19 +01006799 err = nl80211_parse_chandef(rdev, info, &chandef);
6800 if (err)
6801 return err;
6802
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006803 if (netif_carrier_ok(dev))
6804 return -EBUSY;
6805
Simon Wunderlich04f39042013-02-08 18:16:19 +01006806 if (wdev->cac_started)
6807 return -EBUSY;
6808
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006809 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006810 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006811 if (err < 0)
6812 return err;
6813
6814 if (err == 0)
6815 return -EINVAL;
6816
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006817 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006818 return -EINVAL;
6819
6820 if (!rdev->ops->start_radar_detection)
6821 return -EOPNOTSUPP;
6822
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006823 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6824 if (WARN_ON(!cac_time_ms))
6825 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6826
Ilan Peera1056b12015-10-22 22:27:46 +03006827 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006828 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006829 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006830 wdev->cac_started = true;
6831 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006832 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006833 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006834 return err;
6835}
6836
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006837static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6838{
6839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6840 struct net_device *dev = info->user_ptr[1];
6841 struct wireless_dev *wdev = dev->ieee80211_ptr;
6842 struct cfg80211_csa_settings params;
6843 /* csa_attrs is defined static to avoid waste of stack size - this
6844 * function is called under RTNL lock, so this should not be a problem.
6845 */
6846 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006847 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006848 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006849 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006850 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006851
6852 if (!rdev->ops->channel_switch ||
6853 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6854 return -EOPNOTSUPP;
6855
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006856 switch (dev->ieee80211_ptr->iftype) {
6857 case NL80211_IFTYPE_AP:
6858 case NL80211_IFTYPE_P2P_GO:
6859 need_new_beacon = true;
6860
6861 /* useless if AP is not running */
6862 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006863 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006864 break;
6865 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006866 if (!wdev->ssid_len)
6867 return -ENOTCONN;
6868 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006869 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006870 if (!wdev->mesh_id_len)
6871 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006872 break;
6873 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006874 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006875 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006876
6877 memset(&params, 0, sizeof(params));
6878
6879 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6880 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6881 return -EINVAL;
6882
6883 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006884 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006885 return -EINVAL;
6886
Luciano Coelho252e07c2014-10-08 09:48:34 +03006887 /* Even though the attribute is u32, the specification says
6888 * u8, so let's make sure we don't overflow.
6889 */
6890 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6891 if (cs_count > 255)
6892 return -EINVAL;
6893
6894 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006895
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006896 if (!need_new_beacon)
6897 goto skip_beacons;
6898
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006899 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6900 if (err)
6901 return err;
6902
6903 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6904 info->attrs[NL80211_ATTR_CSA_IES],
6905 nl80211_policy);
6906 if (err)
6907 return err;
6908
6909 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6910 if (err)
6911 return err;
6912
6913 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6914 return -EINVAL;
6915
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006916 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6917 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006918 return -EINVAL;
6919
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006920 params.n_counter_offsets_beacon = len / sizeof(u16);
6921 if (rdev->wiphy.max_num_csa_counters &&
6922 (params.n_counter_offsets_beacon >
6923 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006924 return -EINVAL;
6925
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006926 params.counter_offsets_beacon =
6927 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6928
6929 /* sanity checks - counters should fit and be the same */
6930 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6931 u16 offset = params.counter_offsets_beacon[i];
6932
6933 if (offset >= params.beacon_csa.tail_len)
6934 return -EINVAL;
6935
6936 if (params.beacon_csa.tail[offset] != params.count)
6937 return -EINVAL;
6938 }
6939
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006940 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006941 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6942 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006943 return -EINVAL;
6944
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006945 params.n_counter_offsets_presp = len / sizeof(u16);
6946 if (rdev->wiphy.max_num_csa_counters &&
6947 (params.n_counter_offsets_beacon >
6948 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006949 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006950
6951 params.counter_offsets_presp =
6952 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6953
6954 /* sanity checks - counters should fit and be the same */
6955 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6956 u16 offset = params.counter_offsets_presp[i];
6957
6958 if (offset >= params.beacon_csa.probe_resp_len)
6959 return -EINVAL;
6960
6961 if (params.beacon_csa.probe_resp[offset] !=
6962 params.count)
6963 return -EINVAL;
6964 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006965 }
6966
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006967skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006968 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6969 if (err)
6970 return err;
6971
Arik Nemtsov923b3522015-07-08 15:41:44 +03006972 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6973 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006974 return -EINVAL;
6975
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006976 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6977 &params.chandef,
6978 wdev->iftype);
6979 if (err < 0)
6980 return err;
6981
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006982 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006983 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006984
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006985 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6986 params.block_tx = true;
6987
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006988 wdev_lock(wdev);
6989 err = rdev_channel_switch(rdev, dev, &params);
6990 wdev_unlock(wdev);
6991
6992 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006993}
6994
Johannes Berg9720bb32011-06-21 09:45:33 +02006995static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6996 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006997 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006998 struct wireless_dev *wdev,
6999 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007000{
Johannes Berg48ab9052009-07-10 18:42:31 +02007001 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007002 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007003 void *hdr;
7004 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007005
7006 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007007
Eric W. Biederman15e47302012-09-07 20:12:54 +00007008 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007009 NL80211_CMD_NEW_SCAN_RESULTS);
7010 if (!hdr)
7011 return -1;
7012
Johannes Berg9720bb32011-06-21 09:45:33 +02007013 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7014
Johannes Berg97990a02013-04-19 01:02:55 +02007015 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7016 goto nla_put_failure;
7017 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007018 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7019 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007020 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7021 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007022 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007023
7024 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7025 if (!bss)
7026 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007027 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007028 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007029 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007030
7031 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007032 /* indicate whether we have probe response data or not */
7033 if (rcu_access_pointer(res->proberesp_ies) &&
7034 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7035 goto fail_unlock_rcu;
7036
7037 /* this pointer prefers to be pointed to probe response data
7038 * but is always valid
7039 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007040 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007041 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007042 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7043 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007044 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007045 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7046 ies->len, ies->data))
7047 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007048 }
Johannes Berg0e227082014-08-12 20:34:30 +02007049
7050 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007051 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007052 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007053 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7054 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007055 goto fail_unlock_rcu;
7056 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7057 ies->len, ies->data))
7058 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007059 }
7060 rcu_read_unlock();
7061
David S. Miller9360ffd2012-03-29 04:41:26 -04007062 if (res->beacon_interval &&
7063 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7064 goto nla_put_failure;
7065 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7066 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007067 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007068 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7069 jiffies_to_msecs(jiffies - intbss->ts)))
7070 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007071
Avraham Stern1d762502016-07-05 17:10:13 +03007072 if (intbss->parent_tsf &&
7073 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7074 intbss->parent_tsf, NL80211_BSS_PAD) ||
7075 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7076 intbss->parent_bssid)))
7077 goto nla_put_failure;
7078
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007079 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007080 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7081 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007082 goto nla_put_failure;
7083
Johannes Berg77965c92009-02-18 18:45:06 +01007084 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007085 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007086 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7087 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007088 break;
7089 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007090 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7091 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007092 break;
7093 default:
7094 break;
7095 }
7096
Johannes Berg48ab9052009-07-10 18:42:31 +02007097 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007098 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007099 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007100 if (intbss == wdev->current_bss &&
7101 nla_put_u32(msg, NL80211_BSS_STATUS,
7102 NL80211_BSS_STATUS_ASSOCIATED))
7103 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007104 break;
7105 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007106 if (intbss == wdev->current_bss &&
7107 nla_put_u32(msg, NL80211_BSS_STATUS,
7108 NL80211_BSS_STATUS_IBSS_JOINED))
7109 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007110 break;
7111 default:
7112 break;
7113 }
7114
Johannes Berg2a519312009-02-10 21:25:55 +01007115 nla_nest_end(msg, bss);
7116
Johannes Berg053c0952015-01-16 22:09:00 +01007117 genlmsg_end(msg, hdr);
7118 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007119
Johannes Berg8cef2c92013-02-05 16:54:31 +01007120 fail_unlock_rcu:
7121 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007122 nla_put_failure:
7123 genlmsg_cancel(msg, hdr);
7124 return -EMSGSIZE;
7125}
7126
Johannes Berg97990a02013-04-19 01:02:55 +02007127static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007128{
Johannes Berg48ab9052009-07-10 18:42:31 +02007129 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007130 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007131 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007132 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007133 int err;
7134
Johannes Berg97990a02013-04-19 01:02:55 +02007135 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007136 if (err)
7137 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007138
Johannes Berg48ab9052009-07-10 18:42:31 +02007139 wdev_lock(wdev);
7140 spin_lock_bh(&rdev->bss_lock);
7141 cfg80211_bss_expire(rdev);
7142
Johannes Berg9720bb32011-06-21 09:45:33 +02007143 cb->seq = rdev->bss_generation;
7144
Johannes Berg48ab9052009-07-10 18:42:31 +02007145 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007146 if (++idx <= start)
7147 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007148 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007149 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007150 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007151 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007152 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007153 }
7154 }
7155
Johannes Berg48ab9052009-07-10 18:42:31 +02007156 spin_unlock_bh(&rdev->bss_lock);
7157 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007158
Johannes Berg97990a02013-04-19 01:02:55 +02007159 cb->args[2] = idx;
7160 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007161
Johannes Berg67748892010-10-04 21:14:06 +02007162 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007163}
7164
Eric W. Biederman15e47302012-09-07 20:12:54 +00007165static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007166 int flags, struct net_device *dev,
7167 bool allow_radio_stats,
7168 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007169{
7170 void *hdr;
7171 struct nlattr *infoattr;
7172
Johannes Berg11f78ac2014-11-14 16:43:50 +01007173 /* skip radio stats if userspace didn't request them */
7174 if (!survey->channel && !allow_radio_stats)
7175 return 0;
7176
Eric W. Biederman15e47302012-09-07 20:12:54 +00007177 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007178 NL80211_CMD_NEW_SURVEY_RESULTS);
7179 if (!hdr)
7180 return -ENOMEM;
7181
David S. Miller9360ffd2012-03-29 04:41:26 -04007182 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7183 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007184
7185 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7186 if (!infoattr)
7187 goto nla_put_failure;
7188
Johannes Berg11f78ac2014-11-14 16:43:50 +01007189 if (survey->channel &&
7190 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007191 survey->channel->center_freq))
7192 goto nla_put_failure;
7193
7194 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7195 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7196 goto nla_put_failure;
7197 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7198 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7199 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007200 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007201 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7202 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007203 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007204 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007205 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7206 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007207 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007208 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007209 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7210 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007211 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007212 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007213 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7214 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007215 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007216 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007217 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7218 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007219 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007220 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007221 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7222 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007223 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007224
7225 nla_nest_end(msg, infoattr);
7226
Johannes Berg053c0952015-01-16 22:09:00 +01007227 genlmsg_end(msg, hdr);
7228 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007229
7230 nla_put_failure:
7231 genlmsg_cancel(msg, hdr);
7232 return -EMSGSIZE;
7233}
7234
Johannes Berg11f78ac2014-11-14 16:43:50 +01007235static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007236{
7237 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007238 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007239 struct wireless_dev *wdev;
7240 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007241 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007242 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007243
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007244 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007245 if (res)
7246 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007247
Johannes Berg11f78ac2014-11-14 16:43:50 +01007248 /* prepare_wdev_dump parsed the attributes */
7249 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7250
Johannes Berg97990a02013-04-19 01:02:55 +02007251 if (!wdev->netdev) {
7252 res = -EINVAL;
7253 goto out_err;
7254 }
7255
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007256 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007257 res = -EOPNOTSUPP;
7258 goto out_err;
7259 }
7260
7261 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007262 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007263 if (res == -ENOENT)
7264 break;
7265 if (res)
7266 goto out_err;
7267
Johannes Berg11f78ac2014-11-14 16:43:50 +01007268 /* don't send disabled channels, but do send non-channel data */
7269 if (survey.channel &&
7270 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007271 survey_idx++;
7272 continue;
7273 }
7274
Holger Schurig61fa7132009-11-11 12:25:40 +01007275 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007276 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007277 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007278 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007279 goto out;
7280 survey_idx++;
7281 }
7282
7283 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007284 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007285 res = skb->len;
7286 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007287 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007288 return res;
7289}
7290
Samuel Ortizb23aa672009-07-01 21:26:54 +02007291static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7292{
7293 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7294 NL80211_WPA_VERSION_2));
7295}
7296
Jouni Malinen636a5d32009-03-19 13:39:22 +02007297static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7298{
Johannes Berg4c476992010-10-04 21:36:35 +02007299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7300 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007301 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007302 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7303 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007304 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007305 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007306 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007307
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007308 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7309 return -EINVAL;
7310
7311 if (!info->attrs[NL80211_ATTR_MAC])
7312 return -EINVAL;
7313
Jouni Malinen17780922009-03-27 20:52:47 +02007314 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7315 return -EINVAL;
7316
Johannes Berg19957bb2009-07-02 17:20:43 +02007317 if (!info->attrs[NL80211_ATTR_SSID])
7318 return -EINVAL;
7319
7320 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7321 return -EINVAL;
7322
Johannes Bergfffd0932009-07-08 14:22:54 +02007323 err = nl80211_parse_key(info, &key);
7324 if (err)
7325 return err;
7326
7327 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007328 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7329 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007330 if (!key.p.key || !key.p.key_len)
7331 return -EINVAL;
7332 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7333 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7334 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7335 key.p.key_len != WLAN_KEY_LEN_WEP104))
7336 return -EINVAL;
7337 if (key.idx > 4)
7338 return -EINVAL;
7339 } else {
7340 key.p.key_len = 0;
7341 key.p.key = NULL;
7342 }
7343
Johannes Bergafea0b72010-08-10 09:46:42 +02007344 if (key.idx >= 0) {
7345 int i;
7346 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007347
Johannes Bergafea0b72010-08-10 09:46:42 +02007348 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7349 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7350 ok = true;
7351 break;
7352 }
7353 }
Johannes Berg4c476992010-10-04 21:36:35 +02007354 if (!ok)
7355 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007356 }
7357
Johannes Berg4c476992010-10-04 21:36:35 +02007358 if (!rdev->ops->auth)
7359 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007360
Johannes Berg074ac8d2010-09-16 14:58:22 +02007361 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007362 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7363 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007364
Johannes Berg19957bb2009-07-02 17:20:43 +02007365 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007366 chan = nl80211_get_valid_chan(&rdev->wiphy,
7367 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7368 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007369 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007370
Johannes Berg19957bb2009-07-02 17:20:43 +02007371 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7372 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7373
7374 if (info->attrs[NL80211_ATTR_IE]) {
7375 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7376 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7377 }
7378
7379 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007380 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007381 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007382
Jouni Malinene39e5b52012-09-30 19:29:39 +03007383 if (auth_type == NL80211_AUTHTYPE_SAE &&
7384 !info->attrs[NL80211_ATTR_SAE_DATA])
7385 return -EINVAL;
7386
7387 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7388 if (auth_type != NL80211_AUTHTYPE_SAE)
7389 return -EINVAL;
7390 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7391 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7392 /* need to include at least Auth Transaction and Status Code */
7393 if (sae_data_len < 4)
7394 return -EINVAL;
7395 }
7396
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007397 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7398
Johannes Berg95de8172012-01-20 13:55:25 +01007399 /*
7400 * Since we no longer track auth state, ignore
7401 * requests to only change local state.
7402 */
7403 if (local_state_change)
7404 return 0;
7405
Johannes Berg91bf9b22013-05-15 17:44:01 +02007406 wdev_lock(dev->ieee80211_ptr);
7407 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7408 ssid, ssid_len, ie, ie_len,
7409 key.p.key, key.p.key_len, key.idx,
7410 sae_data, sae_data_len);
7411 wdev_unlock(dev->ieee80211_ptr);
7412 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007413}
7414
Johannes Bergc0692b82010-08-27 14:26:53 +03007415static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7416 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007417 struct cfg80211_crypto_settings *settings,
7418 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007419{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007420 memset(settings, 0, sizeof(*settings));
7421
Samuel Ortizb23aa672009-07-01 21:26:54 +02007422 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7423
Johannes Bergc0692b82010-08-27 14:26:53 +03007424 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7425 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007426
Johannes Bergc0692b82010-08-27 14:26:53 +03007427 proto = nla_get_u16(
7428 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7429 settings->control_port_ethertype = cpu_to_be16(proto);
7430 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7431 proto != ETH_P_PAE)
7432 return -EINVAL;
7433 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7434 settings->control_port_no_encrypt = true;
7435 } else
7436 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7437
Samuel Ortizb23aa672009-07-01 21:26:54 +02007438 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7439 void *data;
7440 int len, i;
7441
7442 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7443 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7444 settings->n_ciphers_pairwise = len / sizeof(u32);
7445
7446 if (len % sizeof(u32))
7447 return -EINVAL;
7448
Johannes Berg3dc27d22009-07-02 21:36:37 +02007449 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007450 return -EINVAL;
7451
7452 memcpy(settings->ciphers_pairwise, data, len);
7453
7454 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007455 if (!cfg80211_supported_cipher_suite(
7456 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007457 settings->ciphers_pairwise[i]))
7458 return -EINVAL;
7459 }
7460
7461 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7462 settings->cipher_group =
7463 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007464 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7465 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007466 return -EINVAL;
7467 }
7468
7469 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7470 settings->wpa_versions =
7471 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7472 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7473 return -EINVAL;
7474 }
7475
7476 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7477 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007478 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007479
7480 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7481 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7482 settings->n_akm_suites = len / sizeof(u32);
7483
7484 if (len % sizeof(u32))
7485 return -EINVAL;
7486
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007487 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7488 return -EINVAL;
7489
Samuel Ortizb23aa672009-07-01 21:26:54 +02007490 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007491 }
7492
7493 return 0;
7494}
7495
Jouni Malinen636a5d32009-03-19 13:39:22 +02007496static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7497{
Johannes Berg4c476992010-10-04 21:36:35 +02007498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7499 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007500 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007501 struct cfg80211_assoc_request req = {};
7502 const u8 *bssid, *ssid;
7503 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007504
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007505 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7506 return -EINVAL;
7507
7508 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007509 !info->attrs[NL80211_ATTR_SSID] ||
7510 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007511 return -EINVAL;
7512
Johannes Berg4c476992010-10-04 21:36:35 +02007513 if (!rdev->ops->assoc)
7514 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007515
Johannes Berg074ac8d2010-09-16 14:58:22 +02007516 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007517 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7518 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007519
Johannes Berg19957bb2009-07-02 17:20:43 +02007520 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007521
Jouni Malinen664834d2014-01-15 00:01:44 +02007522 chan = nl80211_get_valid_chan(&rdev->wiphy,
7523 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7524 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007525 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007526
Johannes Berg19957bb2009-07-02 17:20:43 +02007527 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7528 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007529
7530 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007531 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7532 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007533 }
7534
Jouni Malinendc6382c2009-05-06 22:09:37 +03007535 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007536 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007537 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007538 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007539 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007540 else if (mfp != NL80211_MFP_NO)
7541 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007542 }
7543
Johannes Berg3e5d7642009-07-07 14:37:26 +02007544 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007545 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007546
Ben Greear7e7c8922011-11-18 11:31:59 -08007547 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007548 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007549
7550 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007551 memcpy(&req.ht_capa_mask,
7552 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7553 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007554
7555 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007556 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007557 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007558 memcpy(&req.ht_capa,
7559 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7560 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007561 }
7562
Johannes Bergee2aca32013-02-21 17:36:01 +01007563 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007564 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007565
7566 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007567 memcpy(&req.vht_capa_mask,
7568 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7569 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007570
7571 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007572 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007573 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007574 memcpy(&req.vht_capa,
7575 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7576 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007577 }
7578
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007579 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007580 if (!((rdev->wiphy.features &
7581 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7582 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7583 !wiphy_ext_feature_isset(&rdev->wiphy,
7584 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007585 return -EINVAL;
7586 req.flags |= ASSOC_REQ_USE_RRM;
7587 }
7588
Johannes Bergf62fab72013-02-21 20:09:09 +01007589 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007590 if (!err) {
7591 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007592 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7593 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007594 wdev_unlock(dev->ieee80211_ptr);
7595 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007596
Jouni Malinen636a5d32009-03-19 13:39:22 +02007597 return err;
7598}
7599
7600static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7601{
Johannes Berg4c476992010-10-04 21:36:35 +02007602 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7603 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007604 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007605 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007606 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007607 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007608
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007609 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7610 return -EINVAL;
7611
7612 if (!info->attrs[NL80211_ATTR_MAC])
7613 return -EINVAL;
7614
7615 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7616 return -EINVAL;
7617
Johannes Berg4c476992010-10-04 21:36:35 +02007618 if (!rdev->ops->deauth)
7619 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007620
Johannes Berg074ac8d2010-09-16 14:58:22 +02007621 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007622 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7623 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007624
Johannes Berg19957bb2009-07-02 17:20:43 +02007625 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007626
Johannes Berg19957bb2009-07-02 17:20:43 +02007627 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7628 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007629 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007630 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007631 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007632
7633 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007634 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7635 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007636 }
7637
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007638 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7639
Johannes Berg91bf9b22013-05-15 17:44:01 +02007640 wdev_lock(dev->ieee80211_ptr);
7641 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7642 local_state_change);
7643 wdev_unlock(dev->ieee80211_ptr);
7644 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007645}
7646
7647static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7648{
Johannes Berg4c476992010-10-04 21:36:35 +02007649 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7650 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007651 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007652 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007653 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007654 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007655
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007656 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7657 return -EINVAL;
7658
7659 if (!info->attrs[NL80211_ATTR_MAC])
7660 return -EINVAL;
7661
7662 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7663 return -EINVAL;
7664
Johannes Berg4c476992010-10-04 21:36:35 +02007665 if (!rdev->ops->disassoc)
7666 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007667
Johannes Berg074ac8d2010-09-16 14:58:22 +02007668 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007669 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7670 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007671
Johannes Berg19957bb2009-07-02 17:20:43 +02007672 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007673
Johannes Berg19957bb2009-07-02 17:20:43 +02007674 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7675 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007676 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007677 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007678 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007679
7680 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007681 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7682 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007683 }
7684
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007685 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7686
Johannes Berg91bf9b22013-05-15 17:44:01 +02007687 wdev_lock(dev->ieee80211_ptr);
7688 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7689 local_state_change);
7690 wdev_unlock(dev->ieee80211_ptr);
7691 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007692}
7693
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007694static bool
7695nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007696 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007697 int rateval)
7698{
7699 struct wiphy *wiphy = &rdev->wiphy;
7700 bool found = false;
7701 int band, i;
7702
Johannes Berg57fbcce2016-04-12 15:56:15 +02007703 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007704 struct ieee80211_supported_band *sband;
7705
7706 sband = wiphy->bands[band];
7707 if (!sband)
7708 continue;
7709
7710 for (i = 0; i < sband->n_bitrates; i++) {
7711 if (sband->bitrates[i].bitrate == rateval) {
7712 mcast_rate[band] = i + 1;
7713 found = true;
7714 break;
7715 }
7716 }
7717 }
7718
7719 return found;
7720}
7721
Johannes Berg04a773a2009-04-19 21:24:32 +02007722static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7723{
Johannes Berg4c476992010-10-04 21:36:35 +02007724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7725 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007726 struct cfg80211_ibss_params ibss;
7727 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007728 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007729 int err;
7730
Johannes Berg8e30bc52009-04-22 17:45:38 +02007731 memset(&ibss, 0, sizeof(ibss));
7732
Johannes Berg04a773a2009-04-19 21:24:32 +02007733 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7734 return -EINVAL;
7735
Johannes Berg683b6d32012-11-08 21:25:48 +01007736 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007737 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7738 return -EINVAL;
7739
Johannes Berg8e30bc52009-04-22 17:45:38 +02007740 ibss.beacon_interval = 100;
7741
7742 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7743 ibss.beacon_interval =
7744 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7745 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7746 return -EINVAL;
7747 }
7748
Johannes Berg4c476992010-10-04 21:36:35 +02007749 if (!rdev->ops->join_ibss)
7750 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007751
Johannes Berg4c476992010-10-04 21:36:35 +02007752 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7753 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007754
Johannes Berg79c97e92009-07-07 03:56:12 +02007755 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007756
Johannes Berg39193492011-09-16 13:45:25 +02007757 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007758 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007759
7760 if (!is_valid_ether_addr(ibss.bssid))
7761 return -EINVAL;
7762 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007763 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7764 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7765
7766 if (info->attrs[NL80211_ATTR_IE]) {
7767 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7768 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7769 }
7770
Johannes Berg683b6d32012-11-08 21:25:48 +01007771 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7772 if (err)
7773 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007774
Ilan Peer174e0cd2014-02-23 09:13:01 +02007775 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7776 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007777 return -EINVAL;
7778
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007779 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007780 case NL80211_CHAN_WIDTH_5:
7781 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007782 case NL80211_CHAN_WIDTH_20_NOHT:
7783 break;
7784 case NL80211_CHAN_WIDTH_20:
7785 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007786 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7787 return -EINVAL;
7788 break;
7789 case NL80211_CHAN_WIDTH_80:
7790 case NL80211_CHAN_WIDTH_80P80:
7791 case NL80211_CHAN_WIDTH_160:
7792 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7793 return -EINVAL;
7794 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7795 NL80211_EXT_FEATURE_VHT_IBSS))
7796 return -EINVAL;
7797 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007798 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007799 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007800 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007801
Johannes Berg04a773a2009-04-19 21:24:32 +02007802 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007803 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007804
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007805 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7806 u8 *rates =
7807 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7808 int n_rates =
7809 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7810 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007811 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007812
Johannes Berg34850ab2011-07-18 18:08:35 +02007813 err = ieee80211_get_ratemask(sband, rates, n_rates,
7814 &ibss.basic_rates);
7815 if (err)
7816 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007817 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007818
Simon Wunderlich803768f2013-06-28 10:39:58 +02007819 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7820 memcpy(&ibss.ht_capa_mask,
7821 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7822 sizeof(ibss.ht_capa_mask));
7823
7824 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7825 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7826 return -EINVAL;
7827 memcpy(&ibss.ht_capa,
7828 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7829 sizeof(ibss.ht_capa));
7830 }
7831
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007832 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7833 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7834 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7835 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007836
Johannes Berg4c476992010-10-04 21:36:35 +02007837 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307838 bool no_ht = false;
7839
Johannes Berg4c476992010-10-04 21:36:35 +02007840 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307841 info->attrs[NL80211_ATTR_KEYS],
7842 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007843 if (IS_ERR(connkeys))
7844 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307845
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007846 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7847 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007848 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307849 return -EINVAL;
7850 }
Johannes Berg4c476992010-10-04 21:36:35 +02007851 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007852
Antonio Quartulli267335d2012-01-31 20:25:47 +01007853 ibss.control_port =
7854 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7855
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007856 ibss.userspace_handles_dfs =
7857 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7858
Johannes Berg4c476992010-10-04 21:36:35 +02007859 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007860 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007861 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007862 return err;
7863}
7864
7865static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7866{
Johannes Berg4c476992010-10-04 21:36:35 +02007867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7868 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007869
Johannes Berg4c476992010-10-04 21:36:35 +02007870 if (!rdev->ops->leave_ibss)
7871 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007872
Johannes Berg4c476992010-10-04 21:36:35 +02007873 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7874 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007875
Johannes Berg4c476992010-10-04 21:36:35 +02007876 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007877}
7878
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007879static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7880{
7881 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7882 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007883 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007884 u32 nla_rate;
7885 int err;
7886
7887 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007888 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7889 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007890 return -EOPNOTSUPP;
7891
7892 if (!rdev->ops->set_mcast_rate)
7893 return -EOPNOTSUPP;
7894
7895 memset(mcast_rate, 0, sizeof(mcast_rate));
7896
7897 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7898 return -EINVAL;
7899
7900 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7901 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7902 return -EINVAL;
7903
Ilan Peera1056b12015-10-22 22:27:46 +03007904 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007905
7906 return err;
7907}
7908
Johannes Bergad7e7182013-11-13 13:37:47 +01007909static struct sk_buff *
7910__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007911 struct wireless_dev *wdev, int approxlen,
7912 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007913 enum nl80211_attrs attr,
7914 const struct nl80211_vendor_cmd_info *info,
7915 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007916{
7917 struct sk_buff *skb;
7918 void *hdr;
7919 struct nlattr *data;
7920
7921 skb = nlmsg_new(approxlen + 100, gfp);
7922 if (!skb)
7923 return NULL;
7924
7925 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7926 if (!hdr) {
7927 kfree_skb(skb);
7928 return NULL;
7929 }
7930
7931 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7932 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007933
7934 if (info) {
7935 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7936 info->vendor_id))
7937 goto nla_put_failure;
7938 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7939 info->subcmd))
7940 goto nla_put_failure;
7941 }
7942
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007943 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007944 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7945 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007946 goto nla_put_failure;
7947 if (wdev->netdev &&
7948 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7949 wdev->netdev->ifindex))
7950 goto nla_put_failure;
7951 }
7952
Johannes Bergad7e7182013-11-13 13:37:47 +01007953 data = nla_nest_start(skb, attr);
7954
7955 ((void **)skb->cb)[0] = rdev;
7956 ((void **)skb->cb)[1] = hdr;
7957 ((void **)skb->cb)[2] = data;
7958
7959 return skb;
7960
7961 nla_put_failure:
7962 kfree_skb(skb);
7963 return NULL;
7964}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007965
Johannes Berge03ad6e2014-01-01 17:22:30 +01007966struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007967 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007968 enum nl80211_commands cmd,
7969 enum nl80211_attrs attr,
7970 int vendor_event_idx,
7971 int approxlen, gfp_t gfp)
7972{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007973 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007974 const struct nl80211_vendor_cmd_info *info;
7975
7976 switch (cmd) {
7977 case NL80211_CMD_TESTMODE:
7978 if (WARN_ON(vendor_event_idx != -1))
7979 return NULL;
7980 info = NULL;
7981 break;
7982 case NL80211_CMD_VENDOR:
7983 if (WARN_ON(vendor_event_idx < 0 ||
7984 vendor_event_idx >= wiphy->n_vendor_events))
7985 return NULL;
7986 info = &wiphy->vendor_events[vendor_event_idx];
7987 break;
7988 default:
7989 WARN_ON(1);
7990 return NULL;
7991 }
7992
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007993 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007994 cmd, attr, info, gfp);
7995}
7996EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7997
7998void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7999{
8000 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8001 void *hdr = ((void **)skb->cb)[1];
8002 struct nlattr *data = ((void **)skb->cb)[2];
8003 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8004
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008005 /* clear CB data for netlink core to own from now on */
8006 memset(skb->cb, 0, sizeof(skb->cb));
8007
Johannes Berge03ad6e2014-01-01 17:22:30 +01008008 nla_nest_end(skb, data);
8009 genlmsg_end(skb, hdr);
8010
8011 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8012 mcgrp = NL80211_MCGRP_VENDOR;
8013
8014 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8015 mcgrp, gfp);
8016}
8017EXPORT_SYMBOL(__cfg80211_send_event_skb);
8018
Johannes Bergaff89a92009-07-01 21:26:51 +02008019#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008020static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8021{
Johannes Berg4c476992010-10-04 21:36:35 +02008022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008023 struct wireless_dev *wdev =
8024 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008025 int err;
8026
David Spinadelfc73f112013-07-31 18:04:15 +03008027 if (!rdev->ops->testmode_cmd)
8028 return -EOPNOTSUPP;
8029
8030 if (IS_ERR(wdev)) {
8031 err = PTR_ERR(wdev);
8032 if (err != -EINVAL)
8033 return err;
8034 wdev = NULL;
8035 } else if (wdev->wiphy != &rdev->wiphy) {
8036 return -EINVAL;
8037 }
8038
Johannes Bergaff89a92009-07-01 21:26:51 +02008039 if (!info->attrs[NL80211_ATTR_TESTDATA])
8040 return -EINVAL;
8041
Johannes Bergad7e7182013-11-13 13:37:47 +01008042 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008043 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008044 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8045 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008046 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008047
Johannes Bergaff89a92009-07-01 21:26:51 +02008048 return err;
8049}
8050
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008051static int nl80211_testmode_dump(struct sk_buff *skb,
8052 struct netlink_callback *cb)
8053{
Johannes Berg00918d32011-12-13 17:22:05 +01008054 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008055 int err;
8056 long phy_idx;
8057 void *data = NULL;
8058 int data_len = 0;
8059
Johannes Berg5fe231e2013-05-08 21:45:15 +02008060 rtnl_lock();
8061
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008062 if (cb->args[0]) {
8063 /*
8064 * 0 is a valid index, but not valid for args[0],
8065 * so we need to offset by 1.
8066 */
8067 phy_idx = cb->args[0] - 1;
8068 } else {
8069 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8070 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8071 nl80211_policy);
8072 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008073 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008074
Johannes Berg2bd7e352012-06-15 14:23:16 +02008075 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8076 nl80211_fam.attrbuf);
8077 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008078 err = PTR_ERR(rdev);
8079 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008080 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008081 phy_idx = rdev->wiphy_idx;
8082 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008083
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008084 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8085 cb->args[1] =
8086 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8087 }
8088
8089 if (cb->args[1]) {
8090 data = nla_data((void *)cb->args[1]);
8091 data_len = nla_len((void *)cb->args[1]);
8092 }
8093
Johannes Berg00918d32011-12-13 17:22:05 +01008094 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8095 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008096 err = -ENOENT;
8097 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008098 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008099
Johannes Berg00918d32011-12-13 17:22:05 +01008100 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008101 err = -EOPNOTSUPP;
8102 goto out_err;
8103 }
8104
8105 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008106 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008107 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8108 NL80211_CMD_TESTMODE);
8109 struct nlattr *tmdata;
8110
Dan Carpentercb35fba2013-08-14 14:50:01 +03008111 if (!hdr)
8112 break;
8113
David S. Miller9360ffd2012-03-29 04:41:26 -04008114 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008115 genlmsg_cancel(skb, hdr);
8116 break;
8117 }
8118
8119 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8120 if (!tmdata) {
8121 genlmsg_cancel(skb, hdr);
8122 break;
8123 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008124 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008125 nla_nest_end(skb, tmdata);
8126
8127 if (err == -ENOBUFS || err == -ENOENT) {
8128 genlmsg_cancel(skb, hdr);
8129 break;
8130 } else if (err) {
8131 genlmsg_cancel(skb, hdr);
8132 goto out_err;
8133 }
8134
8135 genlmsg_end(skb, hdr);
8136 }
8137
8138 err = skb->len;
8139 /* see above */
8140 cb->args[0] = phy_idx + 1;
8141 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008142 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008143 return err;
8144}
Johannes Bergaff89a92009-07-01 21:26:51 +02008145#endif
8146
Samuel Ortizb23aa672009-07-01 21:26:54 +02008147static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8148{
Johannes Berg4c476992010-10-04 21:36:35 +02008149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8150 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008151 struct cfg80211_connect_params connect;
8152 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008153 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008154 int err;
8155
8156 memset(&connect, 0, sizeof(connect));
8157
8158 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8159 return -EINVAL;
8160
8161 if (!info->attrs[NL80211_ATTR_SSID] ||
8162 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8163 return -EINVAL;
8164
8165 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8166 connect.auth_type =
8167 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008168 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8169 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008170 return -EINVAL;
8171 } else
8172 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8173
8174 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8175
Johannes Bergc0692b82010-08-27 14:26:53 +03008176 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008177 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008178 if (err)
8179 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008180
Johannes Berg074ac8d2010-09-16 14:58:22 +02008181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8183 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008184
Johannes Berg79c97e92009-07-07 03:56:12 +02008185 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008186
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308187 connect.bg_scan_period = -1;
8188 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8189 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8190 connect.bg_scan_period =
8191 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8192 }
8193
Samuel Ortizb23aa672009-07-01 21:26:54 +02008194 if (info->attrs[NL80211_ATTR_MAC])
8195 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008196 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8197 connect.bssid_hint =
8198 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008199 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8200 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8201
8202 if (info->attrs[NL80211_ATTR_IE]) {
8203 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8204 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8205 }
8206
Jouni Malinencee00a92013-01-15 17:15:57 +02008207 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8208 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8209 if (connect.mfp != NL80211_MFP_REQUIRED &&
8210 connect.mfp != NL80211_MFP_NO)
8211 return -EINVAL;
8212 } else {
8213 connect.mfp = NL80211_MFP_NO;
8214 }
8215
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008216 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8217 connect.prev_bssid =
8218 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8219
Samuel Ortizb23aa672009-07-01 21:26:54 +02008220 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008221 connect.channel = nl80211_get_valid_chan(
8222 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8223 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008224 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008225 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008226 connect.channel_hint = nl80211_get_valid_chan(
8227 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8228 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008229 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008230 }
8231
Johannes Bergfffd0932009-07-08 14:22:54 +02008232 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8233 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308234 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008235 if (IS_ERR(connkeys))
8236 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008237 }
8238
Ben Greear7e7c8922011-11-18 11:31:59 -08008239 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8240 connect.flags |= ASSOC_REQ_DISABLE_HT;
8241
8242 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8243 memcpy(&connect.ht_capa_mask,
8244 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8245 sizeof(connect.ht_capa_mask));
8246
8247 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008248 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008249 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008250 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008251 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008252 memcpy(&connect.ht_capa,
8253 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8254 sizeof(connect.ht_capa));
8255 }
8256
Johannes Bergee2aca32013-02-21 17:36:01 +01008257 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8258 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8259
8260 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8261 memcpy(&connect.vht_capa_mask,
8262 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8263 sizeof(connect.vht_capa_mask));
8264
8265 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8266 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008267 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008268 return -EINVAL;
8269 }
8270 memcpy(&connect.vht_capa,
8271 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8272 sizeof(connect.vht_capa));
8273 }
8274
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008275 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008276 if (!((rdev->wiphy.features &
8277 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8278 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8279 !wiphy_ext_feature_isset(&rdev->wiphy,
8280 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008281 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008282 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008283 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008284 connect.flags |= ASSOC_REQ_USE_RRM;
8285 }
8286
Lior David34d50512016-01-28 10:58:25 +02008287 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008288 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008289 kzfree(connkeys);
8290 return -EOPNOTSUPP;
8291 }
8292
Arend van Spriel38de03d2016-03-02 20:37:18 +01008293 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8294 /* bss selection makes no sense if bssid is set */
8295 if (connect.bssid) {
8296 kzfree(connkeys);
8297 return -EINVAL;
8298 }
8299
8300 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8301 wiphy, &connect.bss_select);
8302 if (err) {
8303 kzfree(connkeys);
8304 return err;
8305 }
8306 }
8307
Johannes Berg83739b02013-05-15 17:44:01 +02008308 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008309 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8310 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008311 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008312 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008313 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008314 return err;
8315}
8316
8317static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8318{
Johannes Berg4c476992010-10-04 21:36:35 +02008319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8320 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008321 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008322 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008323
8324 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8325 reason = WLAN_REASON_DEAUTH_LEAVING;
8326 else
8327 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8328
8329 if (reason == 0)
8330 return -EINVAL;
8331
Johannes Berg074ac8d2010-09-16 14:58:22 +02008332 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008333 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8334 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008335
Johannes Berg83739b02013-05-15 17:44:01 +02008336 wdev_lock(dev->ieee80211_ptr);
8337 ret = cfg80211_disconnect(rdev, dev, reason, true);
8338 wdev_unlock(dev->ieee80211_ptr);
8339 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008340}
8341
Johannes Berg463d0182009-07-14 00:33:35 +02008342static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8343{
Johannes Berg4c476992010-10-04 21:36:35 +02008344 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008345 struct net *net;
8346 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008347
Vadim Kochan4b681c82015-01-12 16:34:05 +02008348 if (info->attrs[NL80211_ATTR_PID]) {
8349 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8350
8351 net = get_net_ns_by_pid(pid);
8352 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8353 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8354
8355 net = get_net_ns_by_fd(fd);
8356 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008357 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008358 }
Johannes Berg463d0182009-07-14 00:33:35 +02008359
Johannes Berg4c476992010-10-04 21:36:35 +02008360 if (IS_ERR(net))
8361 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008362
8363 err = 0;
8364
8365 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008366 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8367 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008368
Johannes Berg463d0182009-07-14 00:33:35 +02008369 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008370 return err;
8371}
8372
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008373static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8374{
Johannes Berg4c476992010-10-04 21:36:35 +02008375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008376 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8377 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008378 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008379 struct cfg80211_pmksa pmksa;
8380
8381 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8382
8383 if (!info->attrs[NL80211_ATTR_MAC])
8384 return -EINVAL;
8385
8386 if (!info->attrs[NL80211_ATTR_PMKID])
8387 return -EINVAL;
8388
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008389 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8390 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8391
Johannes Berg074ac8d2010-09-16 14:58:22 +02008392 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008393 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8394 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008395
8396 switch (info->genlhdr->cmd) {
8397 case NL80211_CMD_SET_PMKSA:
8398 rdev_ops = rdev->ops->set_pmksa;
8399 break;
8400 case NL80211_CMD_DEL_PMKSA:
8401 rdev_ops = rdev->ops->del_pmksa;
8402 break;
8403 default:
8404 WARN_ON(1);
8405 break;
8406 }
8407
Johannes Berg4c476992010-10-04 21:36:35 +02008408 if (!rdev_ops)
8409 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008410
Johannes Berg4c476992010-10-04 21:36:35 +02008411 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008412}
8413
8414static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8415{
Johannes Berg4c476992010-10-04 21:36:35 +02008416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8417 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008418
Johannes Berg074ac8d2010-09-16 14:58:22 +02008419 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008420 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8421 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008422
Johannes Berg4c476992010-10-04 21:36:35 +02008423 if (!rdev->ops->flush_pmksa)
8424 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008425
Hila Gonene35e4d22012-06-27 17:19:42 +03008426 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008427}
8428
Arik Nemtsov109086c2011-09-28 14:12:50 +03008429static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8430{
8431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8432 struct net_device *dev = info->user_ptr[1];
8433 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308434 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008435 u16 status_code;
8436 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008437 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008438
8439 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8440 !rdev->ops->tdls_mgmt)
8441 return -EOPNOTSUPP;
8442
8443 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8444 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8445 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8446 !info->attrs[NL80211_ATTR_IE] ||
8447 !info->attrs[NL80211_ATTR_MAC])
8448 return -EINVAL;
8449
8450 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8451 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8452 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8453 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008454 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308455 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8456 peer_capability =
8457 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008458
Hila Gonene35e4d22012-06-27 17:19:42 +03008459 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308460 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008461 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008462 nla_data(info->attrs[NL80211_ATTR_IE]),
8463 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008464}
8465
8466static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8467{
8468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8469 struct net_device *dev = info->user_ptr[1];
8470 enum nl80211_tdls_operation operation;
8471 u8 *peer;
8472
8473 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8474 !rdev->ops->tdls_oper)
8475 return -EOPNOTSUPP;
8476
8477 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8478 !info->attrs[NL80211_ATTR_MAC])
8479 return -EINVAL;
8480
8481 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8482 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8483
Hila Gonene35e4d22012-06-27 17:19:42 +03008484 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008485}
8486
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008487static int nl80211_remain_on_channel(struct sk_buff *skb,
8488 struct genl_info *info)
8489{
Johannes Berg4c476992010-10-04 21:36:35 +02008490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008491 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008492 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008493 struct sk_buff *msg;
8494 void *hdr;
8495 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008496 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008497 int err;
8498
8499 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8500 !info->attrs[NL80211_ATTR_DURATION])
8501 return -EINVAL;
8502
8503 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8504
Johannes Berg7c4ef712011-11-18 15:33:48 +01008505 if (!rdev->ops->remain_on_channel ||
8506 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008507 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008508
Johannes Bergebf348f2012-06-01 12:50:54 +02008509 /*
8510 * We should be on that channel for at least a minimum amount of
8511 * time (10ms) but no longer than the driver supports.
8512 */
8513 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8514 duration > rdev->wiphy.max_remain_on_channel_duration)
8515 return -EINVAL;
8516
Johannes Berg683b6d32012-11-08 21:25:48 +01008517 err = nl80211_parse_chandef(rdev, info, &chandef);
8518 if (err)
8519 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008520
8521 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008522 if (!msg)
8523 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008524
Eric W. Biederman15e47302012-09-07 20:12:54 +00008525 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008526 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008527 if (!hdr) {
8528 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008529 goto free_msg;
8530 }
8531
Johannes Berg683b6d32012-11-08 21:25:48 +01008532 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8533 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008534
8535 if (err)
8536 goto free_msg;
8537
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008538 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8539 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008540 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008541
8542 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008543
8544 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008545
8546 nla_put_failure:
8547 err = -ENOBUFS;
8548 free_msg:
8549 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008550 return err;
8551}
8552
8553static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8554 struct genl_info *info)
8555{
Johannes Berg4c476992010-10-04 21:36:35 +02008556 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008557 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008558 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008559
8560 if (!info->attrs[NL80211_ATTR_COOKIE])
8561 return -EINVAL;
8562
Johannes Berg4c476992010-10-04 21:36:35 +02008563 if (!rdev->ops->cancel_remain_on_channel)
8564 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008565
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008566 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8567
Hila Gonene35e4d22012-06-27 17:19:42 +03008568 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008569}
8570
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008571static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8572 u8 *rates, u8 rates_len)
8573{
8574 u8 i;
8575 u32 mask = 0;
8576
8577 for (i = 0; i < rates_len; i++) {
8578 int rate = (rates[i] & 0x7f) * 5;
8579 int ridx;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008580
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008581 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8582 struct ieee80211_rate *srate =
8583 &sband->bitrates[ridx];
8584 if (rate == srate->bitrate) {
8585 mask |= 1 << ridx;
8586 break;
8587 }
8588 }
8589 if (ridx == sband->n_bitrates)
8590 return 0; /* rate not found */
8591 }
8592
8593 return mask;
8594}
8595
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008596static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8597 u8 *rates, u8 rates_len,
8598 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8599{
8600 u8 i;
8601
8602 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8603
8604 for (i = 0; i < rates_len; i++) {
8605 int ridx, rbit;
8606
8607 ridx = rates[i] / 8;
8608 rbit = BIT(rates[i] % 8);
8609
8610 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008611 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008612 return false;
8613
8614 /* check availability */
8615 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8616 mcs[ridx] |= rbit;
8617 else
8618 return false;
8619 }
8620
8621 return true;
8622}
8623
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008624static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8625{
8626 u16 mcs_mask = 0;
8627
8628 switch (vht_mcs_map) {
8629 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8630 break;
8631 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8632 mcs_mask = 0x00FF;
8633 break;
8634 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8635 mcs_mask = 0x01FF;
8636 break;
8637 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8638 mcs_mask = 0x03FF;
8639 break;
8640 default:
8641 break;
8642 }
8643
8644 return mcs_mask;
8645}
8646
8647static void vht_build_mcs_mask(u16 vht_mcs_map,
8648 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8649{
8650 u8 nss;
8651
8652 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8653 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8654 vht_mcs_map >>= 2;
8655 }
8656}
8657
8658static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8659 struct nl80211_txrate_vht *txrate,
8660 u16 mcs[NL80211_VHT_NSS_MAX])
8661{
8662 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8663 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8664 u8 i;
8665
8666 if (!sband->vht_cap.vht_supported)
8667 return false;
8668
8669 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8670
8671 /* Build vht_mcs_mask from VHT capabilities */
8672 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8673
8674 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8675 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8676 mcs[i] = txrate->mcs[i];
8677 else
8678 return false;
8679 }
8680
8681 return true;
8682}
8683
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008684static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008685 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8686 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008687 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8688 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008689 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008690 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008691};
8692
8693static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8694 struct genl_info *info)
8695{
8696 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008698 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008699 int rem, i;
8700 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008701 struct nlattr *tx_rates;
8702 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008703 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008704
Johannes Berg4c476992010-10-04 21:36:35 +02008705 if (!rdev->ops->set_bitrate_mask)
8706 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008707
8708 memset(&mask, 0, sizeof(mask));
8709 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008710 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008711 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008712
8713 if (!sband)
8714 continue;
8715
8716 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008717 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008718 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008719 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008720
8721 if (!sband->vht_cap.vht_supported)
8722 continue;
8723
8724 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8725 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008726 }
8727
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008728 /* if no rates are given set it back to the defaults */
8729 if (!info->attrs[NL80211_ATTR_TX_RATES])
8730 goto out;
8731
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008732 /*
8733 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008734 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008735 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008736 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008737 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008738 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008739 int err;
8740
Johannes Berg57fbcce2016-04-12 15:56:15 +02008741 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008742 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008743 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008744 if (sband == NULL)
8745 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008746 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8747 nla_len(tx_rates), nl80211_txattr_policy);
8748 if (err)
8749 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008750 if (tb[NL80211_TXRATE_LEGACY]) {
8751 mask.control[band].legacy = rateset_to_mask(
8752 sband,
8753 nla_data(tb[NL80211_TXRATE_LEGACY]),
8754 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308755 if ((mask.control[band].legacy == 0) &&
8756 nla_len(tb[NL80211_TXRATE_LEGACY]))
8757 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008758 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008759 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008760 if (!ht_rateset_to_mask(
8761 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008762 nla_data(tb[NL80211_TXRATE_HT]),
8763 nla_len(tb[NL80211_TXRATE_HT]),
8764 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008765 return -EINVAL;
8766 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008767 if (tb[NL80211_TXRATE_VHT]) {
8768 if (!vht_set_mcs_mask(
8769 sband,
8770 nla_data(tb[NL80211_TXRATE_VHT]),
8771 mask.control[band].vht_mcs))
8772 return -EINVAL;
8773 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008774 if (tb[NL80211_TXRATE_GI]) {
8775 mask.control[band].gi =
8776 nla_get_u8(tb[NL80211_TXRATE_GI]);
8777 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8778 return -EINVAL;
8779 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008780
8781 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008782 /* don't allow empty legacy rates if HT or VHT
8783 * are not even supported.
8784 */
8785 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8786 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008787 return -EINVAL;
8788
8789 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008790 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008791 goto out;
8792
8793 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8794 if (mask.control[band].vht_mcs[i])
8795 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008796
8797 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008798 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008799 }
8800 }
8801
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008802out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008803 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008804}
8805
Johannes Berg2e161f72010-08-12 15:38:38 +02008806static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008807{
Johannes Berg4c476992010-10-04 21:36:35 +02008808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008809 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008810 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008811
8812 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8813 return -EINVAL;
8814
Johannes Berg2e161f72010-08-12 15:38:38 +02008815 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8816 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008817
Johannes Berg71bbc992012-06-15 15:30:18 +02008818 switch (wdev->iftype) {
8819 case NL80211_IFTYPE_STATION:
8820 case NL80211_IFTYPE_ADHOC:
8821 case NL80211_IFTYPE_P2P_CLIENT:
8822 case NL80211_IFTYPE_AP:
8823 case NL80211_IFTYPE_AP_VLAN:
8824 case NL80211_IFTYPE_MESH_POINT:
8825 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008826 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008827 break;
8828 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008829 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008830 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008831
8832 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008833 if (!rdev->ops->mgmt_tx)
8834 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008835
Eric W. Biederman15e47302012-09-07 20:12:54 +00008836 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008837 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8838 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008839}
8840
Johannes Berg2e161f72010-08-12 15:38:38 +02008841static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008842{
Johannes Berg4c476992010-10-04 21:36:35 +02008843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008844 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008845 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008846 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008847 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008848 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008849 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008850 struct cfg80211_mgmt_tx_params params = {
8851 .dont_wait_for_ack =
8852 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8853 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008854
Johannes Berg683b6d32012-11-08 21:25:48 +01008855 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008856 return -EINVAL;
8857
Johannes Berg4c476992010-10-04 21:36:35 +02008858 if (!rdev->ops->mgmt_tx)
8859 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008860
Johannes Berg71bbc992012-06-15 15:30:18 +02008861 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008862 case NL80211_IFTYPE_P2P_DEVICE:
8863 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8864 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008865 case NL80211_IFTYPE_STATION:
8866 case NL80211_IFTYPE_ADHOC:
8867 case NL80211_IFTYPE_P2P_CLIENT:
8868 case NL80211_IFTYPE_AP:
8869 case NL80211_IFTYPE_AP_VLAN:
8870 case NL80211_IFTYPE_MESH_POINT:
8871 case NL80211_IFTYPE_P2P_GO:
8872 break;
8873 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008874 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008875 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008876
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008877 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008878 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008879 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008880 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008881
8882 /*
8883 * We should wait on the channel for at least a minimum amount
8884 * of time (10ms) but no longer than the driver supports.
8885 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008886 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8887 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008888 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008889 }
8890
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008891 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008892
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008893 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008894 return -EINVAL;
8895
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008896 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308897
Antonio Quartulliea141b752013-06-11 14:20:03 +02008898 /* get the channel if any has been specified, otherwise pass NULL to
8899 * the driver. The latter will use the current one
8900 */
8901 chandef.chan = NULL;
8902 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8903 err = nl80211_parse_chandef(rdev, info, &chandef);
8904 if (err)
8905 return err;
8906 }
8907
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008908 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008909 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008910
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008911 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8912 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8913
8914 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8915 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8916 int i;
8917
8918 if (len % sizeof(u16))
8919 return -EINVAL;
8920
8921 params.n_csa_offsets = len / sizeof(u16);
8922 params.csa_offsets =
8923 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8924
8925 /* check that all the offsets fit the frame */
8926 for (i = 0; i < params.n_csa_offsets; i++) {
8927 if (params.csa_offsets[i] >= params.len)
8928 return -EINVAL;
8929 }
8930 }
8931
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008932 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008933 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8934 if (!msg)
8935 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008936
Eric W. Biederman15e47302012-09-07 20:12:54 +00008937 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008938 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008939 if (!hdr) {
8940 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008941 goto free_msg;
8942 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008943 }
Johannes Berge247bd902011-11-04 11:18:21 +01008944
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008945 params.chan = chandef.chan;
8946 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008947 if (err)
8948 goto free_msg;
8949
Johannes Berge247bd902011-11-04 11:18:21 +01008950 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008951 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8952 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008953 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008954
Johannes Berge247bd902011-11-04 11:18:21 +01008955 genlmsg_end(msg, hdr);
8956 return genlmsg_reply(msg, info);
8957 }
8958
8959 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008960
8961 nla_put_failure:
8962 err = -ENOBUFS;
8963 free_msg:
8964 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008965 return err;
8966}
8967
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008968static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8969{
8970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008971 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008972 u64 cookie;
8973
8974 if (!info->attrs[NL80211_ATTR_COOKIE])
8975 return -EINVAL;
8976
8977 if (!rdev->ops->mgmt_tx_cancel_wait)
8978 return -EOPNOTSUPP;
8979
Johannes Berg71bbc992012-06-15 15:30:18 +02008980 switch (wdev->iftype) {
8981 case NL80211_IFTYPE_STATION:
8982 case NL80211_IFTYPE_ADHOC:
8983 case NL80211_IFTYPE_P2P_CLIENT:
8984 case NL80211_IFTYPE_AP:
8985 case NL80211_IFTYPE_AP_VLAN:
8986 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008987 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008988 break;
8989 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008990 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008991 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008992
8993 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8994
Hila Gonene35e4d22012-06-27 17:19:42 +03008995 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008996}
8997
Kalle Valoffb9eb32010-02-17 17:58:10 +02008998static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8999{
Johannes Berg4c476992010-10-04 21:36:35 +02009000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009001 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009002 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009003 u8 ps_state;
9004 bool state;
9005 int err;
9006
Johannes Berg4c476992010-10-04 21:36:35 +02009007 if (!info->attrs[NL80211_ATTR_PS_STATE])
9008 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009009
9010 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9011
Johannes Berg4c476992010-10-04 21:36:35 +02009012 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9013 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009014
9015 wdev = dev->ieee80211_ptr;
9016
Johannes Berg4c476992010-10-04 21:36:35 +02009017 if (!rdev->ops->set_power_mgmt)
9018 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009019
9020 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9021
9022 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009023 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009024
Hila Gonene35e4d22012-06-27 17:19:42 +03009025 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009026 if (!err)
9027 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009028 return err;
9029}
9030
9031static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9032{
Johannes Berg4c476992010-10-04 21:36:35 +02009033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009034 enum nl80211_ps_state ps_state;
9035 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009036 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009037 struct sk_buff *msg;
9038 void *hdr;
9039 int err;
9040
Kalle Valoffb9eb32010-02-17 17:58:10 +02009041 wdev = dev->ieee80211_ptr;
9042
Johannes Berg4c476992010-10-04 21:36:35 +02009043 if (!rdev->ops->set_power_mgmt)
9044 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009045
9046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009047 if (!msg)
9048 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009049
Eric W. Biederman15e47302012-09-07 20:12:54 +00009050 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009051 NL80211_CMD_GET_POWER_SAVE);
9052 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009053 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009054 goto free_msg;
9055 }
9056
9057 if (wdev->ps)
9058 ps_state = NL80211_PS_ENABLED;
9059 else
9060 ps_state = NL80211_PS_DISABLED;
9061
David S. Miller9360ffd2012-03-29 04:41:26 -04009062 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9063 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009064
9065 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009066 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009067
Johannes Berg4c476992010-10-04 21:36:35 +02009068 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009069 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009070 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009071 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009072 return err;
9073}
9074
Johannes Berg94e860f2014-01-20 23:58:15 +01009075static const struct nla_policy
9076nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009077 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9078 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9079 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009080 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9081 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9082 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009083};
9084
Thomas Pedersen84f10702012-07-12 16:17:33 -07009085static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009086 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009087{
9088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009089 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009090 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009091
Johannes Bergd9d8b012012-11-26 12:51:52 +01009092 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009093 return -EINVAL;
9094
Thomas Pedersen84f10702012-07-12 16:17:33 -07009095 if (!rdev->ops->set_cqm_txe_config)
9096 return -EOPNOTSUPP;
9097
9098 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9099 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9100 return -EOPNOTSUPP;
9101
Hila Gonene35e4d22012-06-27 17:19:42 +03009102 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009103}
9104
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009105static int nl80211_set_cqm_rssi(struct genl_info *info,
9106 s32 threshold, u32 hysteresis)
9107{
Johannes Berg4c476992010-10-04 21:36:35 +02009108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009109 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009110 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009111
9112 if (threshold > 0)
9113 return -EINVAL;
9114
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009115 /* disabling - hysteresis should also be zero then */
9116 if (threshold == 0)
9117 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009118
Johannes Berg4c476992010-10-04 21:36:35 +02009119 if (!rdev->ops->set_cqm_rssi_config)
9120 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009121
Johannes Berg074ac8d2010-09-16 14:58:22 +02009122 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009123 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9124 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009125
Hila Gonene35e4d22012-06-27 17:19:42 +03009126 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009127}
9128
9129static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9130{
9131 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9132 struct nlattr *cqm;
9133 int err;
9134
9135 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009136 if (!cqm)
9137 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009138
9139 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9140 nl80211_attr_cqm_policy);
9141 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009142 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009143
9144 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9145 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009146 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9147 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009148
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009149 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9150 }
9151
9152 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9153 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9154 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9155 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9156 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9157 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9158
9159 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9160 }
9161
9162 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009163}
9164
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009165static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9166{
9167 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9168 struct net_device *dev = info->user_ptr[1];
9169 struct ocb_setup setup = {};
9170 int err;
9171
9172 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9173 if (err)
9174 return err;
9175
9176 return cfg80211_join_ocb(rdev, dev, &setup);
9177}
9178
9179static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9180{
9181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9182 struct net_device *dev = info->user_ptr[1];
9183
9184 return cfg80211_leave_ocb(rdev, dev);
9185}
9186
Johannes Berg29cbe682010-12-03 09:20:44 +01009187static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9188{
9189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9190 struct net_device *dev = info->user_ptr[1];
9191 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009192 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009193 int err;
9194
9195 /* start with default */
9196 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009197 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009198
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009199 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009200 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009201 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009202 if (err)
9203 return err;
9204 }
9205
9206 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9207 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9208 return -EINVAL;
9209
Javier Cardonac80d5452010-12-16 17:37:49 -08009210 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9211 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9212
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009213 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9214 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9215 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9216 return -EINVAL;
9217
Marco Porsch9bdbf042013-01-07 16:04:51 +01009218 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9219 setup.beacon_interval =
9220 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9221 if (setup.beacon_interval < 10 ||
9222 setup.beacon_interval > 10000)
9223 return -EINVAL;
9224 }
9225
9226 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9227 setup.dtim_period =
9228 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9229 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9230 return -EINVAL;
9231 }
9232
Javier Cardonac80d5452010-12-16 17:37:49 -08009233 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9234 /* parse additional setup parameters if given */
9235 err = nl80211_parse_mesh_setup(info, &setup);
9236 if (err)
9237 return err;
9238 }
9239
Thomas Pedersend37bb182013-03-04 13:06:13 -08009240 if (setup.user_mpm)
9241 cfg.auto_open_plinks = false;
9242
Johannes Bergcc1d2802012-05-16 23:50:20 +02009243 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009244 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9245 if (err)
9246 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009247 } else {
9248 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009249 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009250 }
9251
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009252 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9253 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9254 int n_rates =
9255 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9256 struct ieee80211_supported_band *sband;
9257
9258 if (!setup.chandef.chan)
9259 return -EINVAL;
9260
9261 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9262
9263 err = ieee80211_get_ratemask(sband, rates, n_rates,
9264 &setup.basic_rates);
9265 if (err)
9266 return err;
9267 }
9268
Javier Cardonac80d5452010-12-16 17:37:49 -08009269 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009270}
9271
9272static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9273{
9274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9275 struct net_device *dev = info->user_ptr[1];
9276
9277 return cfg80211_leave_mesh(rdev, dev);
9278}
9279
Johannes Bergdfb89c52012-06-27 09:23:48 +02009280#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009281static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9282 struct cfg80211_registered_device *rdev)
9283{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009284 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009285 struct nlattr *nl_pats, *nl_pat;
9286 int i, pat_len;
9287
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009288 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009289 return 0;
9290
9291 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9292 if (!nl_pats)
9293 return -ENOBUFS;
9294
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009295 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009296 nl_pat = nla_nest_start(msg, i + 1);
9297 if (!nl_pat)
9298 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009299 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009300 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009301 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009302 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9303 wowlan->patterns[i].pattern) ||
9304 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009305 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009306 return -ENOBUFS;
9307 nla_nest_end(msg, nl_pat);
9308 }
9309 nla_nest_end(msg, nl_pats);
9310
9311 return 0;
9312}
9313
Johannes Berg2a0e0472013-01-23 22:57:40 +01009314static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9315 struct cfg80211_wowlan_tcp *tcp)
9316{
9317 struct nlattr *nl_tcp;
9318
9319 if (!tcp)
9320 return 0;
9321
9322 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9323 if (!nl_tcp)
9324 return -ENOBUFS;
9325
Jiri Benc930345e2015-03-29 16:59:25 +02009326 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9327 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009328 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9329 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9330 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9331 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9332 tcp->payload_len, tcp->payload) ||
9333 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9334 tcp->data_interval) ||
9335 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9336 tcp->wake_len, tcp->wake_data) ||
9337 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9338 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9339 return -ENOBUFS;
9340
9341 if (tcp->payload_seq.len &&
9342 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9343 sizeof(tcp->payload_seq), &tcp->payload_seq))
9344 return -ENOBUFS;
9345
9346 if (tcp->payload_tok.len &&
9347 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9348 sizeof(tcp->payload_tok) + tcp->tokens_size,
9349 &tcp->payload_tok))
9350 return -ENOBUFS;
9351
Johannes Berge248ad32013-05-16 10:24:28 +02009352 nla_nest_end(msg, nl_tcp);
9353
Johannes Berg2a0e0472013-01-23 22:57:40 +01009354 return 0;
9355}
9356
Luciano Coelho75453cc2015-01-09 14:06:37 +02009357static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9358 struct cfg80211_sched_scan_request *req)
9359{
Avraham Stern3b06d272015-10-12 09:51:34 +03009360 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009361 int i;
9362
9363 if (!req)
9364 return 0;
9365
9366 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9367 if (!nd)
9368 return -ENOBUFS;
9369
Avraham Stern3b06d272015-10-12 09:51:34 +03009370 if (req->n_scan_plans == 1 &&
9371 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9372 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009373 return -ENOBUFS;
9374
Luciano Coelho21fea562015-03-17 16:36:01 +02009375 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9376 return -ENOBUFS;
9377
Luciano Coelho75453cc2015-01-09 14:06:37 +02009378 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9379 if (!freqs)
9380 return -ENOBUFS;
9381
9382 for (i = 0; i < req->n_channels; i++)
9383 nla_put_u32(msg, i, req->channels[i]->center_freq);
9384
9385 nla_nest_end(msg, freqs);
9386
9387 if (req->n_match_sets) {
9388 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9389 for (i = 0; i < req->n_match_sets; i++) {
9390 match = nla_nest_start(msg, i);
9391 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9392 req->match_sets[i].ssid.ssid_len,
9393 req->match_sets[i].ssid.ssid);
9394 nla_nest_end(msg, match);
9395 }
9396 nla_nest_end(msg, matches);
9397 }
9398
Avraham Stern3b06d272015-10-12 09:51:34 +03009399 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9400 if (!scan_plans)
9401 return -ENOBUFS;
9402
9403 for (i = 0; i < req->n_scan_plans; i++) {
9404 scan_plan = nla_nest_start(msg, i + 1);
9405 if (!scan_plan ||
9406 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9407 req->scan_plans[i].interval) ||
9408 (req->scan_plans[i].iterations &&
9409 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9410 req->scan_plans[i].iterations)))
9411 return -ENOBUFS;
9412 nla_nest_end(msg, scan_plan);
9413 }
9414 nla_nest_end(msg, scan_plans);
9415
Luciano Coelho75453cc2015-01-09 14:06:37 +02009416 nla_nest_end(msg, nd);
9417
9418 return 0;
9419}
9420
Johannes Bergff1b6e62011-05-04 15:37:28 +02009421static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9422{
9423 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9424 struct sk_buff *msg;
9425 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009426 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009427
Johannes Berg964dc9e2013-06-03 17:25:34 +02009428 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009429 return -EOPNOTSUPP;
9430
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009431 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009432 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009433 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9434 rdev->wiphy.wowlan_config->tcp->payload_len +
9435 rdev->wiphy.wowlan_config->tcp->wake_len +
9436 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009437 }
9438
9439 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009440 if (!msg)
9441 return -ENOMEM;
9442
Eric W. Biederman15e47302012-09-07 20:12:54 +00009443 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009444 NL80211_CMD_GET_WOWLAN);
9445 if (!hdr)
9446 goto nla_put_failure;
9447
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009448 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009449 struct nlattr *nl_wowlan;
9450
9451 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9452 if (!nl_wowlan)
9453 goto nla_put_failure;
9454
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009455 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009456 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009457 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009458 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009459 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009460 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009461 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009462 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009463 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009464 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009465 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009466 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009467 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009468 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9469 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009470
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009471 if (nl80211_send_wowlan_patterns(msg, rdev))
9472 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009473
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009474 if (nl80211_send_wowlan_tcp(msg,
9475 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009476 goto nla_put_failure;
9477
Luciano Coelho75453cc2015-01-09 14:06:37 +02009478 if (nl80211_send_wowlan_nd(
9479 msg,
9480 rdev->wiphy.wowlan_config->nd_config))
9481 goto nla_put_failure;
9482
Johannes Bergff1b6e62011-05-04 15:37:28 +02009483 nla_nest_end(msg, nl_wowlan);
9484 }
9485
9486 genlmsg_end(msg, hdr);
9487 return genlmsg_reply(msg, info);
9488
9489nla_put_failure:
9490 nlmsg_free(msg);
9491 return -ENOBUFS;
9492}
9493
Johannes Berg2a0e0472013-01-23 22:57:40 +01009494static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9495 struct nlattr *attr,
9496 struct cfg80211_wowlan *trig)
9497{
9498 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9499 struct cfg80211_wowlan_tcp *cfg;
9500 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9501 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9502 u32 size;
9503 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9504 int err, port;
9505
Johannes Berg964dc9e2013-06-03 17:25:34 +02009506 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009507 return -EINVAL;
9508
9509 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9510 nla_data(attr), nla_len(attr),
9511 nl80211_wowlan_tcp_policy);
9512 if (err)
9513 return err;
9514
9515 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9516 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9517 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9518 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9519 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9520 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9521 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9522 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9523 return -EINVAL;
9524
9525 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009526 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009527 return -EINVAL;
9528
9529 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009530 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009531 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009532 return -EINVAL;
9533
9534 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009535 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009536 return -EINVAL;
9537
9538 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9539 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9540 return -EINVAL;
9541
9542 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9543 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9544
9545 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9546 tokens_size = tokln - sizeof(*tok);
9547
9548 if (!tok->len || tokens_size % tok->len)
9549 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009550 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009551 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009552 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009553 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009554 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009555 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009556 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009557 return -EINVAL;
9558 if (tok->offset + tok->len > data_size)
9559 return -EINVAL;
9560 }
9561
9562 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9563 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009564 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009565 return -EINVAL;
9566 if (seq->len == 0 || seq->len > 4)
9567 return -EINVAL;
9568 if (seq->len + seq->offset > data_size)
9569 return -EINVAL;
9570 }
9571
9572 size = sizeof(*cfg);
9573 size += data_size;
9574 size += wake_size + wake_mask_size;
9575 size += tokens_size;
9576
9577 cfg = kzalloc(size, GFP_KERNEL);
9578 if (!cfg)
9579 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009580 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9581 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009582 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9583 ETH_ALEN);
9584 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9585 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9586 else
9587 port = 0;
9588#ifdef CONFIG_INET
9589 /* allocate a socket and port for it and use it */
9590 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9591 IPPROTO_TCP, &cfg->sock, 1);
9592 if (err) {
9593 kfree(cfg);
9594 return err;
9595 }
9596 if (inet_csk_get_port(cfg->sock->sk, port)) {
9597 sock_release(cfg->sock);
9598 kfree(cfg);
9599 return -EADDRINUSE;
9600 }
9601 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9602#else
9603 if (!port) {
9604 kfree(cfg);
9605 return -EINVAL;
9606 }
9607 cfg->src_port = port;
9608#endif
9609
9610 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9611 cfg->payload_len = data_size;
9612 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9613 memcpy((void *)cfg->payload,
9614 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9615 data_size);
9616 if (seq)
9617 cfg->payload_seq = *seq;
9618 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9619 cfg->wake_len = wake_size;
9620 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9621 memcpy((void *)cfg->wake_data,
9622 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9623 wake_size);
9624 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9625 data_size + wake_size;
9626 memcpy((void *)cfg->wake_mask,
9627 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9628 wake_mask_size);
9629 if (tok) {
9630 cfg->tokens_size = tokens_size;
9631 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9632 }
9633
9634 trig->tcp = cfg;
9635
9636 return 0;
9637}
9638
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009639static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9640 const struct wiphy_wowlan_support *wowlan,
9641 struct nlattr *attr,
9642 struct cfg80211_wowlan *trig)
9643{
9644 struct nlattr **tb;
9645 int err;
9646
9647 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9648 if (!tb)
9649 return -ENOMEM;
9650
9651 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9652 err = -EOPNOTSUPP;
9653 goto out;
9654 }
9655
9656 err = nla_parse(tb, NL80211_ATTR_MAX,
9657 nla_data(attr), nla_len(attr),
9658 nl80211_policy);
9659 if (err)
9660 goto out;
9661
Johannes Bergad2b26a2014-06-12 21:39:05 +02009662 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009663 err = PTR_ERR_OR_ZERO(trig->nd_config);
9664 if (err)
9665 trig->nd_config = NULL;
9666
9667out:
9668 kfree(tb);
9669 return err;
9670}
9671
Johannes Bergff1b6e62011-05-04 15:37:28 +02009672static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9673{
9674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9675 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009676 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009677 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009678 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009679 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009680 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009681 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009682
Johannes Berg964dc9e2013-06-03 17:25:34 +02009683 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009684 return -EOPNOTSUPP;
9685
Johannes Bergae33bd82012-07-12 16:25:02 +02009686 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9687 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009688 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009689 goto set_wakeup;
9690 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009691
9692 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9693 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9694 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9695 nl80211_wowlan_policy);
9696 if (err)
9697 return err;
9698
9699 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9700 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9701 return -EINVAL;
9702 new_triggers.any = true;
9703 }
9704
9705 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9706 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9707 return -EINVAL;
9708 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009709 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009710 }
9711
9712 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9713 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9714 return -EINVAL;
9715 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009716 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009717 }
9718
Johannes Berg77dbbb12011-07-13 10:48:55 +02009719 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9720 return -EINVAL;
9721
9722 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9723 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9724 return -EINVAL;
9725 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009726 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009727 }
9728
9729 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9730 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9731 return -EINVAL;
9732 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009733 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009734 }
9735
9736 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9737 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9738 return -EINVAL;
9739 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009740 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009741 }
9742
9743 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9744 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9745 return -EINVAL;
9746 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009747 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009748 }
9749
Johannes Bergff1b6e62011-05-04 15:37:28 +02009750 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9751 struct nlattr *pat;
9752 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009753 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009754 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009755
Johannes Berg98fc4382015-03-01 09:10:13 +02009756 regular = true;
9757
Johannes Bergff1b6e62011-05-04 15:37:28 +02009758 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9759 rem)
9760 n_patterns++;
9761 if (n_patterns > wowlan->n_patterns)
9762 return -EINVAL;
9763
9764 new_triggers.patterns = kcalloc(n_patterns,
9765 sizeof(new_triggers.patterns[0]),
9766 GFP_KERNEL);
9767 if (!new_triggers.patterns)
9768 return -ENOMEM;
9769
9770 new_triggers.n_patterns = n_patterns;
9771 i = 0;
9772
9773 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9774 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009775 u8 *mask_pat;
9776
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009777 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9778 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009779 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009780 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9781 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009782 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009783 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009784 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009785 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009786 goto error;
9787 if (pat_len > wowlan->pattern_max_len ||
9788 pat_len < wowlan->pattern_min_len)
9789 goto error;
9790
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009791 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009792 pkt_offset = 0;
9793 else
9794 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009795 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009796 if (pkt_offset > wowlan->max_pkt_offset)
9797 goto error;
9798 new_triggers.patterns[i].pkt_offset = pkt_offset;
9799
Johannes Berg922bd802014-05-19 17:59:50 +02009800 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9801 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009802 err = -ENOMEM;
9803 goto error;
9804 }
Johannes Berg922bd802014-05-19 17:59:50 +02009805 new_triggers.patterns[i].mask = mask_pat;
9806 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009807 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009808 mask_pat += mask_len;
9809 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009810 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009811 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009812 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009813 pat_len);
9814 i++;
9815 }
9816 }
9817
Johannes Berg2a0e0472013-01-23 22:57:40 +01009818 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009819 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009820 err = nl80211_parse_wowlan_tcp(
9821 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9822 &new_triggers);
9823 if (err)
9824 goto error;
9825 }
9826
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009827 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009828 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009829 err = nl80211_parse_wowlan_nd(
9830 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9831 &new_triggers);
9832 if (err)
9833 goto error;
9834 }
9835
Johannes Berg98fc4382015-03-01 09:10:13 +02009836 /* The 'any' trigger means the device continues operating more or less
9837 * as in its normal operation mode and wakes up the host on most of the
9838 * normal interrupts (like packet RX, ...)
9839 * It therefore makes little sense to combine with the more constrained
9840 * wakeup trigger modes.
9841 */
9842 if (new_triggers.any && regular) {
9843 err = -EINVAL;
9844 goto error;
9845 }
9846
Johannes Bergae33bd82012-07-12 16:25:02 +02009847 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9848 if (!ntrig) {
9849 err = -ENOMEM;
9850 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009851 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009852 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009853 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009854
Johannes Bergae33bd82012-07-12 16:25:02 +02009855 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009856 if (rdev->ops->set_wakeup &&
9857 prev_enabled != !!rdev->wiphy.wowlan_config)
9858 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009859
Johannes Bergff1b6e62011-05-04 15:37:28 +02009860 return 0;
9861 error:
9862 for (i = 0; i < new_triggers.n_patterns; i++)
9863 kfree(new_triggers.patterns[i].mask);
9864 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009865 if (new_triggers.tcp && new_triggers.tcp->sock)
9866 sock_release(new_triggers.tcp->sock);
9867 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009868 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009869 return err;
9870}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009871#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009872
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009873static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9874 struct cfg80211_registered_device *rdev)
9875{
9876 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9877 int i, j, pat_len;
9878 struct cfg80211_coalesce_rules *rule;
9879
9880 if (!rdev->coalesce->n_rules)
9881 return 0;
9882
9883 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9884 if (!nl_rules)
9885 return -ENOBUFS;
9886
9887 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9888 nl_rule = nla_nest_start(msg, i + 1);
9889 if (!nl_rule)
9890 return -ENOBUFS;
9891
9892 rule = &rdev->coalesce->rules[i];
9893 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9894 rule->delay))
9895 return -ENOBUFS;
9896
9897 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9898 rule->condition))
9899 return -ENOBUFS;
9900
9901 nl_pats = nla_nest_start(msg,
9902 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9903 if (!nl_pats)
9904 return -ENOBUFS;
9905
9906 for (j = 0; j < rule->n_patterns; j++) {
9907 nl_pat = nla_nest_start(msg, j + 1);
9908 if (!nl_pat)
9909 return -ENOBUFS;
9910 pat_len = rule->patterns[j].pattern_len;
9911 if (nla_put(msg, NL80211_PKTPAT_MASK,
9912 DIV_ROUND_UP(pat_len, 8),
9913 rule->patterns[j].mask) ||
9914 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9915 rule->patterns[j].pattern) ||
9916 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9917 rule->patterns[j].pkt_offset))
9918 return -ENOBUFS;
9919 nla_nest_end(msg, nl_pat);
9920 }
9921 nla_nest_end(msg, nl_pats);
9922 nla_nest_end(msg, nl_rule);
9923 }
9924 nla_nest_end(msg, nl_rules);
9925
9926 return 0;
9927}
9928
9929static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9930{
9931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9932 struct sk_buff *msg;
9933 void *hdr;
9934
9935 if (!rdev->wiphy.coalesce)
9936 return -EOPNOTSUPP;
9937
9938 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9939 if (!msg)
9940 return -ENOMEM;
9941
9942 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9943 NL80211_CMD_GET_COALESCE);
9944 if (!hdr)
9945 goto nla_put_failure;
9946
9947 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9948 goto nla_put_failure;
9949
9950 genlmsg_end(msg, hdr);
9951 return genlmsg_reply(msg, info);
9952
9953nla_put_failure:
9954 nlmsg_free(msg);
9955 return -ENOBUFS;
9956}
9957
9958void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9959{
9960 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9961 int i, j;
9962 struct cfg80211_coalesce_rules *rule;
9963
9964 if (!coalesce)
9965 return;
9966
9967 for (i = 0; i < coalesce->n_rules; i++) {
9968 rule = &coalesce->rules[i];
9969 for (j = 0; j < rule->n_patterns; j++)
9970 kfree(rule->patterns[j].mask);
9971 kfree(rule->patterns);
9972 }
9973 kfree(coalesce->rules);
9974 kfree(coalesce);
9975 rdev->coalesce = NULL;
9976}
9977
9978static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9979 struct nlattr *rule,
9980 struct cfg80211_coalesce_rules *new_rule)
9981{
9982 int err, i;
9983 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9984 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9985 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9986 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9987
9988 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9989 nla_len(rule), nl80211_coalesce_policy);
9990 if (err)
9991 return err;
9992
9993 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9994 new_rule->delay =
9995 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9996 if (new_rule->delay > coalesce->max_delay)
9997 return -EINVAL;
9998
9999 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10000 new_rule->condition =
10001 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10002 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10003 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10004 return -EINVAL;
10005
10006 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10007 return -EINVAL;
10008
10009 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10010 rem)
10011 n_patterns++;
10012 if (n_patterns > coalesce->n_patterns)
10013 return -EINVAL;
10014
10015 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10016 GFP_KERNEL);
10017 if (!new_rule->patterns)
10018 return -ENOMEM;
10019
10020 new_rule->n_patterns = n_patterns;
10021 i = 0;
10022
10023 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10024 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010025 u8 *mask_pat;
10026
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010027 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10028 nla_len(pat), NULL);
10029 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10030 !pat_tb[NL80211_PKTPAT_PATTERN])
10031 return -EINVAL;
10032 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10033 mask_len = DIV_ROUND_UP(pat_len, 8);
10034 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10035 return -EINVAL;
10036 if (pat_len > coalesce->pattern_max_len ||
10037 pat_len < coalesce->pattern_min_len)
10038 return -EINVAL;
10039
10040 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10041 pkt_offset = 0;
10042 else
10043 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10044 if (pkt_offset > coalesce->max_pkt_offset)
10045 return -EINVAL;
10046 new_rule->patterns[i].pkt_offset = pkt_offset;
10047
Johannes Berg922bd802014-05-19 17:59:50 +020010048 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10049 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010050 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010051
10052 new_rule->patterns[i].mask = mask_pat;
10053 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10054 mask_len);
10055
10056 mask_pat += mask_len;
10057 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010058 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010059 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10060 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010061 i++;
10062 }
10063
10064 return 0;
10065}
10066
10067static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10068{
10069 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10070 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10071 struct cfg80211_coalesce new_coalesce = {};
10072 struct cfg80211_coalesce *n_coalesce;
10073 int err, rem_rule, n_rules = 0, i, j;
10074 struct nlattr *rule;
10075 struct cfg80211_coalesce_rules *tmp_rule;
10076
10077 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10078 return -EOPNOTSUPP;
10079
10080 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10081 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010082 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010083 return 0;
10084 }
10085
10086 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10087 rem_rule)
10088 n_rules++;
10089 if (n_rules > coalesce->n_rules)
10090 return -EINVAL;
10091
10092 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10093 GFP_KERNEL);
10094 if (!new_coalesce.rules)
10095 return -ENOMEM;
10096
10097 new_coalesce.n_rules = n_rules;
10098 i = 0;
10099
10100 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10101 rem_rule) {
10102 err = nl80211_parse_coalesce_rule(rdev, rule,
10103 &new_coalesce.rules[i]);
10104 if (err)
10105 goto error;
10106
10107 i++;
10108 }
10109
Ilan Peera1056b12015-10-22 22:27:46 +030010110 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010111 if (err)
10112 goto error;
10113
10114 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10115 if (!n_coalesce) {
10116 err = -ENOMEM;
10117 goto error;
10118 }
10119 cfg80211_rdev_free_coalesce(rdev);
10120 rdev->coalesce = n_coalesce;
10121
10122 return 0;
10123error:
10124 for (i = 0; i < new_coalesce.n_rules; i++) {
10125 tmp_rule = &new_coalesce.rules[i];
10126 for (j = 0; j < tmp_rule->n_patterns; j++)
10127 kfree(tmp_rule->patterns[j].mask);
10128 kfree(tmp_rule->patterns);
10129 }
10130 kfree(new_coalesce.rules);
10131
10132 return err;
10133}
10134
Johannes Berge5497d72011-07-05 16:35:40 +020010135static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10136{
10137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10138 struct net_device *dev = info->user_ptr[1];
10139 struct wireless_dev *wdev = dev->ieee80211_ptr;
10140 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10141 struct cfg80211_gtk_rekey_data rekey_data;
10142 int err;
10143
10144 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10145 return -EINVAL;
10146
10147 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10148 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10149 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10150 nl80211_rekey_policy);
10151 if (err)
10152 return err;
10153
10154 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10155 return -ERANGE;
10156 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10157 return -ERANGE;
10158 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10159 return -ERANGE;
10160
Johannes Berg78f686c2014-09-10 22:28:06 +030010161 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10162 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10163 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010164
10165 wdev_lock(wdev);
10166 if (!wdev->current_bss) {
10167 err = -ENOTCONN;
10168 goto out;
10169 }
10170
10171 if (!rdev->ops->set_rekey_data) {
10172 err = -EOPNOTSUPP;
10173 goto out;
10174 }
10175
Hila Gonene35e4d22012-06-27 17:19:42 +030010176 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010177 out:
10178 wdev_unlock(wdev);
10179 return err;
10180}
10181
Johannes Berg28946da2011-11-04 11:18:12 +010010182static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10183 struct genl_info *info)
10184{
10185 struct net_device *dev = info->user_ptr[1];
10186 struct wireless_dev *wdev = dev->ieee80211_ptr;
10187
10188 if (wdev->iftype != NL80211_IFTYPE_AP &&
10189 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10190 return -EINVAL;
10191
Eric W. Biederman15e47302012-09-07 20:12:54 +000010192 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010193 return -EBUSY;
10194
Eric W. Biederman15e47302012-09-07 20:12:54 +000010195 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010196 return 0;
10197}
10198
Johannes Berg7f6cf312011-11-04 11:18:15 +010010199static int nl80211_probe_client(struct sk_buff *skb,
10200 struct genl_info *info)
10201{
10202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10203 struct net_device *dev = info->user_ptr[1];
10204 struct wireless_dev *wdev = dev->ieee80211_ptr;
10205 struct sk_buff *msg;
10206 void *hdr;
10207 const u8 *addr;
10208 u64 cookie;
10209 int err;
10210
10211 if (wdev->iftype != NL80211_IFTYPE_AP &&
10212 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10213 return -EOPNOTSUPP;
10214
10215 if (!info->attrs[NL80211_ATTR_MAC])
10216 return -EINVAL;
10217
10218 if (!rdev->ops->probe_client)
10219 return -EOPNOTSUPP;
10220
10221 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10222 if (!msg)
10223 return -ENOMEM;
10224
Eric W. Biederman15e47302012-09-07 20:12:54 +000010225 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010226 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010227 if (!hdr) {
10228 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010229 goto free_msg;
10230 }
10231
10232 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10233
Hila Gonene35e4d22012-06-27 17:19:42 +030010234 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010235 if (err)
10236 goto free_msg;
10237
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010238 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10239 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010240 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010241
10242 genlmsg_end(msg, hdr);
10243
10244 return genlmsg_reply(msg, info);
10245
10246 nla_put_failure:
10247 err = -ENOBUFS;
10248 free_msg:
10249 nlmsg_free(msg);
10250 return err;
10251}
10252
Johannes Berg5e7602302011-11-04 11:18:17 +010010253static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10254{
10255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010256 struct cfg80211_beacon_registration *reg, *nreg;
10257 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010258
10259 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10260 return -EOPNOTSUPP;
10261
Ben Greear37c73b52012-10-26 14:49:25 -070010262 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10263 if (!nreg)
10264 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010265
Ben Greear37c73b52012-10-26 14:49:25 -070010266 /* First, check if already registered. */
10267 spin_lock_bh(&rdev->beacon_registrations_lock);
10268 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10269 if (reg->nlportid == info->snd_portid) {
10270 rv = -EALREADY;
10271 goto out_err;
10272 }
10273 }
10274 /* Add it to the list */
10275 nreg->nlportid = info->snd_portid;
10276 list_add(&nreg->list, &rdev->beacon_registrations);
10277
10278 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010279
10280 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010281out_err:
10282 spin_unlock_bh(&rdev->beacon_registrations_lock);
10283 kfree(nreg);
10284 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010285}
10286
Johannes Berg98104fde2012-06-16 00:19:54 +020010287static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10288{
10289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10290 struct wireless_dev *wdev = info->user_ptr[1];
10291 int err;
10292
10293 if (!rdev->ops->start_p2p_device)
10294 return -EOPNOTSUPP;
10295
10296 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10297 return -EOPNOTSUPP;
10298
10299 if (wdev->p2p_started)
10300 return 0;
10301
Luciano Coelhob6a55012014-02-27 11:07:21 +020010302 if (rfkill_blocked(rdev->rfkill))
10303 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010304
Johannes Bergeeb126e2012-10-23 15:16:50 +020010305 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010306 if (err)
10307 return err;
10308
10309 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010310 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010311
10312 return 0;
10313}
10314
10315static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10316{
10317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10318 struct wireless_dev *wdev = info->user_ptr[1];
10319
10320 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10321 return -EOPNOTSUPP;
10322
10323 if (!rdev->ops->stop_p2p_device)
10324 return -EOPNOTSUPP;
10325
Johannes Bergf9f47522013-03-19 15:04:07 +010010326 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010327
10328 return 0;
10329}
10330
Johannes Berg3713b4e2013-02-14 16:19:38 +010010331static int nl80211_get_protocol_features(struct sk_buff *skb,
10332 struct genl_info *info)
10333{
10334 void *hdr;
10335 struct sk_buff *msg;
10336
10337 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10338 if (!msg)
10339 return -ENOMEM;
10340
10341 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10342 NL80211_CMD_GET_PROTOCOL_FEATURES);
10343 if (!hdr)
10344 goto nla_put_failure;
10345
10346 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10347 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10348 goto nla_put_failure;
10349
10350 genlmsg_end(msg, hdr);
10351 return genlmsg_reply(msg, info);
10352
10353 nla_put_failure:
10354 kfree_skb(msg);
10355 return -ENOBUFS;
10356}
10357
Jouni Malinen355199e2013-02-27 17:14:27 +020010358static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10359{
10360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10361 struct cfg80211_update_ft_ies_params ft_params;
10362 struct net_device *dev = info->user_ptr[1];
10363
10364 if (!rdev->ops->update_ft_ies)
10365 return -EOPNOTSUPP;
10366
10367 if (!info->attrs[NL80211_ATTR_MDID] ||
10368 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10369 return -EINVAL;
10370
10371 memset(&ft_params, 0, sizeof(ft_params));
10372 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10373 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10374 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10375
10376 return rdev_update_ft_ies(rdev, dev, &ft_params);
10377}
10378
Arend van Spriel5de17982013-04-18 15:49:00 +020010379static int nl80211_crit_protocol_start(struct sk_buff *skb,
10380 struct genl_info *info)
10381{
10382 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10383 struct wireless_dev *wdev = info->user_ptr[1];
10384 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10385 u16 duration;
10386 int ret;
10387
10388 if (!rdev->ops->crit_proto_start)
10389 return -EOPNOTSUPP;
10390
10391 if (WARN_ON(!rdev->ops->crit_proto_stop))
10392 return -EINVAL;
10393
10394 if (rdev->crit_proto_nlportid)
10395 return -EBUSY;
10396
10397 /* determine protocol if provided */
10398 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10399 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10400
10401 if (proto >= NUM_NL80211_CRIT_PROTO)
10402 return -EINVAL;
10403
10404 /* timeout must be provided */
10405 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10406 return -EINVAL;
10407
10408 duration =
10409 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10410
10411 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10412 return -ERANGE;
10413
10414 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10415 if (!ret)
10416 rdev->crit_proto_nlportid = info->snd_portid;
10417
10418 return ret;
10419}
10420
10421static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10422 struct genl_info *info)
10423{
10424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10425 struct wireless_dev *wdev = info->user_ptr[1];
10426
10427 if (!rdev->ops->crit_proto_stop)
10428 return -EOPNOTSUPP;
10429
10430 if (rdev->crit_proto_nlportid) {
10431 rdev->crit_proto_nlportid = 0;
10432 rdev_crit_proto_stop(rdev, wdev);
10433 }
10434 return 0;
10435}
10436
Johannes Bergad7e7182013-11-13 13:37:47 +010010437static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10438{
10439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10440 struct wireless_dev *wdev =
10441 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10442 int i, err;
10443 u32 vid, subcmd;
10444
10445 if (!rdev->wiphy.vendor_commands)
10446 return -EOPNOTSUPP;
10447
10448 if (IS_ERR(wdev)) {
10449 err = PTR_ERR(wdev);
10450 if (err != -EINVAL)
10451 return err;
10452 wdev = NULL;
10453 } else if (wdev->wiphy != &rdev->wiphy) {
10454 return -EINVAL;
10455 }
10456
10457 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10458 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10459 return -EINVAL;
10460
10461 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10462 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10463 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10464 const struct wiphy_vendor_command *vcmd;
10465 void *data = NULL;
10466 int len = 0;
10467
10468 vcmd = &rdev->wiphy.vendor_commands[i];
10469
10470 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10471 continue;
10472
10473 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10474 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10475 if (!wdev)
10476 return -EINVAL;
10477 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10478 !wdev->netdev)
10479 return -EINVAL;
10480
10481 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10482 if (wdev->netdev &&
10483 !netif_running(wdev->netdev))
10484 return -ENETDOWN;
10485 if (!wdev->netdev && !wdev->p2p_started)
10486 return -ENETDOWN;
10487 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010488
10489 if (!vcmd->doit)
10490 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010491 } else {
10492 wdev = NULL;
10493 }
10494
10495 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10496 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10497 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10498 }
10499
10500 rdev->cur_cmd_info = info;
10501 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10502 data, len);
10503 rdev->cur_cmd_info = NULL;
10504 return err;
10505 }
10506
10507 return -EOPNOTSUPP;
10508}
10509
Johannes Berg7bdbe402015-08-15 22:39:49 +030010510static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10511 struct netlink_callback *cb,
10512 struct cfg80211_registered_device **rdev,
10513 struct wireless_dev **wdev)
10514{
10515 u32 vid, subcmd;
10516 unsigned int i;
10517 int vcmd_idx = -1;
10518 int err;
10519 void *data = NULL;
10520 unsigned int data_len = 0;
10521
10522 rtnl_lock();
10523
10524 if (cb->args[0]) {
10525 /* subtract the 1 again here */
10526 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10527 struct wireless_dev *tmp;
10528
10529 if (!wiphy) {
10530 err = -ENODEV;
10531 goto out_unlock;
10532 }
10533 *rdev = wiphy_to_rdev(wiphy);
10534 *wdev = NULL;
10535
10536 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010537 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010538 if (tmp->identifier == cb->args[1] - 1) {
10539 *wdev = tmp;
10540 break;
10541 }
10542 }
10543 }
10544
10545 /* keep rtnl locked in successful case */
10546 return 0;
10547 }
10548
10549 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10550 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10551 nl80211_policy);
10552 if (err)
10553 goto out_unlock;
10554
10555 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10556 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10557 err = -EINVAL;
10558 goto out_unlock;
10559 }
10560
10561 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10562 nl80211_fam.attrbuf);
10563 if (IS_ERR(*wdev))
10564 *wdev = NULL;
10565
10566 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10567 nl80211_fam.attrbuf);
10568 if (IS_ERR(*rdev)) {
10569 err = PTR_ERR(*rdev);
10570 goto out_unlock;
10571 }
10572
10573 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10574 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10575
10576 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10577 const struct wiphy_vendor_command *vcmd;
10578
10579 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10580
10581 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10582 continue;
10583
10584 if (!vcmd->dumpit) {
10585 err = -EOPNOTSUPP;
10586 goto out_unlock;
10587 }
10588
10589 vcmd_idx = i;
10590 break;
10591 }
10592
10593 if (vcmd_idx < 0) {
10594 err = -EOPNOTSUPP;
10595 goto out_unlock;
10596 }
10597
10598 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10599 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10600 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10601 }
10602
10603 /* 0 is the first index - add 1 to parse only once */
10604 cb->args[0] = (*rdev)->wiphy_idx + 1;
10605 /* add 1 to know if it was NULL */
10606 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10607 cb->args[2] = vcmd_idx;
10608 cb->args[3] = (unsigned long)data;
10609 cb->args[4] = data_len;
10610
10611 /* keep rtnl locked in successful case */
10612 return 0;
10613 out_unlock:
10614 rtnl_unlock();
10615 return err;
10616}
10617
10618static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10619 struct netlink_callback *cb)
10620{
10621 struct cfg80211_registered_device *rdev;
10622 struct wireless_dev *wdev;
10623 unsigned int vcmd_idx;
10624 const struct wiphy_vendor_command *vcmd;
10625 void *data;
10626 int data_len;
10627 int err;
10628 struct nlattr *vendor_data;
10629
10630 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10631 if (err)
10632 return err;
10633
10634 vcmd_idx = cb->args[2];
10635 data = (void *)cb->args[3];
10636 data_len = cb->args[4];
10637 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10638
10639 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10640 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10641 if (!wdev)
10642 return -EINVAL;
10643 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10644 !wdev->netdev)
10645 return -EINVAL;
10646
10647 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10648 if (wdev->netdev &&
10649 !netif_running(wdev->netdev))
10650 return -ENETDOWN;
10651 if (!wdev->netdev && !wdev->p2p_started)
10652 return -ENETDOWN;
10653 }
10654 }
10655
10656 while (1) {
10657 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10658 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10659 NL80211_CMD_VENDOR);
10660 if (!hdr)
10661 break;
10662
10663 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010664 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10665 wdev_id(wdev),
10666 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010667 genlmsg_cancel(skb, hdr);
10668 break;
10669 }
10670
10671 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10672 if (!vendor_data) {
10673 genlmsg_cancel(skb, hdr);
10674 break;
10675 }
10676
10677 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10678 (unsigned long *)&cb->args[5]);
10679 nla_nest_end(skb, vendor_data);
10680
10681 if (err == -ENOBUFS || err == -ENOENT) {
10682 genlmsg_cancel(skb, hdr);
10683 break;
10684 } else if (err) {
10685 genlmsg_cancel(skb, hdr);
10686 goto out;
10687 }
10688
10689 genlmsg_end(skb, hdr);
10690 }
10691
10692 err = skb->len;
10693 out:
10694 rtnl_unlock();
10695 return err;
10696}
10697
Johannes Bergad7e7182013-11-13 13:37:47 +010010698struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10699 enum nl80211_commands cmd,
10700 enum nl80211_attrs attr,
10701 int approxlen)
10702{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010703 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010704
10705 if (WARN_ON(!rdev->cur_cmd_info))
10706 return NULL;
10707
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010708 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010709 rdev->cur_cmd_info->snd_portid,
10710 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010711 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010712}
10713EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10714
10715int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10716{
10717 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10718 void *hdr = ((void **)skb->cb)[1];
10719 struct nlattr *data = ((void **)skb->cb)[2];
10720
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010721 /* clear CB data for netlink core to own from now on */
10722 memset(skb->cb, 0, sizeof(skb->cb));
10723
Johannes Bergad7e7182013-11-13 13:37:47 +010010724 if (WARN_ON(!rdev->cur_cmd_info)) {
10725 kfree_skb(skb);
10726 return -EINVAL;
10727 }
10728
10729 nla_nest_end(skb, data);
10730 genlmsg_end(skb, hdr);
10731 return genlmsg_reply(skb, rdev->cur_cmd_info);
10732}
10733EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10734
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010735static int nl80211_set_qos_map(struct sk_buff *skb,
10736 struct genl_info *info)
10737{
10738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10739 struct cfg80211_qos_map *qos_map = NULL;
10740 struct net_device *dev = info->user_ptr[1];
10741 u8 *pos, len, num_des, des_len, des;
10742 int ret;
10743
10744 if (!rdev->ops->set_qos_map)
10745 return -EOPNOTSUPP;
10746
10747 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10748 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10749 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10750
10751 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10752 len > IEEE80211_QOS_MAP_LEN_MAX)
10753 return -EINVAL;
10754
10755 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10756 if (!qos_map)
10757 return -ENOMEM;
10758
10759 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10760 if (num_des) {
10761 des_len = num_des *
10762 sizeof(struct cfg80211_dscp_exception);
10763 memcpy(qos_map->dscp_exception, pos, des_len);
10764 qos_map->num_des = num_des;
10765 for (des = 0; des < num_des; des++) {
10766 if (qos_map->dscp_exception[des].up > 7) {
10767 kfree(qos_map);
10768 return -EINVAL;
10769 }
10770 }
10771 pos += des_len;
10772 }
10773 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10774 }
10775
10776 wdev_lock(dev->ieee80211_ptr);
10777 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10778 if (!ret)
10779 ret = rdev_set_qos_map(rdev, dev, qos_map);
10780 wdev_unlock(dev->ieee80211_ptr);
10781
10782 kfree(qos_map);
10783 return ret;
10784}
10785
Johannes Berg960d01a2014-09-09 22:55:35 +030010786static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10787{
10788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10789 struct net_device *dev = info->user_ptr[1];
10790 struct wireless_dev *wdev = dev->ieee80211_ptr;
10791 const u8 *peer;
10792 u8 tsid, up;
10793 u16 admitted_time = 0;
10794 int err;
10795
Johannes Berg723e73a2014-10-22 09:25:06 +020010796 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010797 return -EOPNOTSUPP;
10798
10799 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10800 !info->attrs[NL80211_ATTR_USER_PRIO])
10801 return -EINVAL;
10802
10803 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10804 if (tsid >= IEEE80211_NUM_TIDS)
10805 return -EINVAL;
10806
10807 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10808 if (up >= IEEE80211_NUM_UPS)
10809 return -EINVAL;
10810
10811 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010812 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010813 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010814 * need more attributes for that (e.g. BA session requirement);
10815 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010816 */
10817 return -EINVAL;
10818 }
10819
10820 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10821
10822 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10823 admitted_time =
10824 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10825 if (!admitted_time)
10826 return -EINVAL;
10827 }
10828
10829 wdev_lock(wdev);
10830 switch (wdev->iftype) {
10831 case NL80211_IFTYPE_STATION:
10832 case NL80211_IFTYPE_P2P_CLIENT:
10833 if (wdev->current_bss)
10834 break;
10835 err = -ENOTCONN;
10836 goto out;
10837 default:
10838 err = -EOPNOTSUPP;
10839 goto out;
10840 }
10841
10842 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10843
10844 out:
10845 wdev_unlock(wdev);
10846 return err;
10847}
10848
10849static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10850{
10851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10852 struct net_device *dev = info->user_ptr[1];
10853 struct wireless_dev *wdev = dev->ieee80211_ptr;
10854 const u8 *peer;
10855 u8 tsid;
10856 int err;
10857
10858 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10859 return -EINVAL;
10860
10861 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10862 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10863
10864 wdev_lock(wdev);
10865 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10866 wdev_unlock(wdev);
10867
10868 return err;
10869}
10870
Arik Nemtsov1057d352014-11-19 12:54:26 +020010871static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10872 struct genl_info *info)
10873{
10874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10875 struct net_device *dev = info->user_ptr[1];
10876 struct wireless_dev *wdev = dev->ieee80211_ptr;
10877 struct cfg80211_chan_def chandef = {};
10878 const u8 *addr;
10879 u8 oper_class;
10880 int err;
10881
10882 if (!rdev->ops->tdls_channel_switch ||
10883 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10884 return -EOPNOTSUPP;
10885
10886 switch (dev->ieee80211_ptr->iftype) {
10887 case NL80211_IFTYPE_STATION:
10888 case NL80211_IFTYPE_P2P_CLIENT:
10889 break;
10890 default:
10891 return -EOPNOTSUPP;
10892 }
10893
10894 if (!info->attrs[NL80211_ATTR_MAC] ||
10895 !info->attrs[NL80211_ATTR_OPER_CLASS])
10896 return -EINVAL;
10897
10898 err = nl80211_parse_chandef(rdev, info, &chandef);
10899 if (err)
10900 return err;
10901
10902 /*
10903 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10904 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10905 * specification is not defined for them.
10906 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010907 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010908 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10909 chandef.width != NL80211_CHAN_WIDTH_20)
10910 return -EINVAL;
10911
10912 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010913 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10914 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010915 return -EINVAL;
10916
10917 /* don't allow switching to DFS channels */
10918 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10919 return -EINVAL;
10920
10921 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10922 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10923
10924 wdev_lock(wdev);
10925 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10926 wdev_unlock(wdev);
10927
10928 return err;
10929}
10930
10931static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10932 struct genl_info *info)
10933{
10934 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10935 struct net_device *dev = info->user_ptr[1];
10936 struct wireless_dev *wdev = dev->ieee80211_ptr;
10937 const u8 *addr;
10938
10939 if (!rdev->ops->tdls_channel_switch ||
10940 !rdev->ops->tdls_cancel_channel_switch ||
10941 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10942 return -EOPNOTSUPP;
10943
10944 switch (dev->ieee80211_ptr->iftype) {
10945 case NL80211_IFTYPE_STATION:
10946 case NL80211_IFTYPE_P2P_CLIENT:
10947 break;
10948 default:
10949 return -EOPNOTSUPP;
10950 }
10951
10952 if (!info->attrs[NL80211_ATTR_MAC])
10953 return -EINVAL;
10954
10955 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10956
10957 wdev_lock(wdev);
10958 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10959 wdev_unlock(wdev);
10960
10961 return 0;
10962}
10963
Johannes Berg4c476992010-10-04 21:36:35 +020010964#define NL80211_FLAG_NEED_WIPHY 0x01
10965#define NL80211_FLAG_NEED_NETDEV 0x02
10966#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010967#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10968#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10969 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010970#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010971/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010972#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10973 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010974#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010975
Johannes Bergf84f7712013-11-14 17:14:45 +010010976static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010977 struct genl_info *info)
10978{
10979 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010980 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010981 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010982 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10983
10984 if (rtnl)
10985 rtnl_lock();
10986
10987 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010988 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010989 if (IS_ERR(rdev)) {
10990 if (rtnl)
10991 rtnl_unlock();
10992 return PTR_ERR(rdev);
10993 }
10994 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010995 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10996 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010997 ASSERT_RTNL();
10998
Johannes Berg89a54e42012-06-15 14:33:17 +020010999 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11000 info->attrs);
11001 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011002 if (rtnl)
11003 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011004 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011005 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011006
Johannes Berg89a54e42012-06-15 14:33:17 +020011007 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011008 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011009
Johannes Berg1bf614e2012-06-15 15:23:36 +020011010 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11011 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011012 if (rtnl)
11013 rtnl_unlock();
11014 return -EINVAL;
11015 }
11016
11017 info->user_ptr[1] = dev;
11018 } else {
11019 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011020 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011021
Johannes Berg1bf614e2012-06-15 15:23:36 +020011022 if (dev) {
11023 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11024 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011025 if (rtnl)
11026 rtnl_unlock();
11027 return -ENETDOWN;
11028 }
11029
11030 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011031 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
11032 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020011033 if (rtnl)
11034 rtnl_unlock();
11035 return -ENETDOWN;
11036 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020011037 }
11038
Johannes Berg4c476992010-10-04 21:36:35 +020011039 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011040 }
11041
11042 return 0;
11043}
11044
Johannes Bergf84f7712013-11-14 17:14:45 +010011045static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011046 struct genl_info *info)
11047{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011048 if (info->user_ptr[1]) {
11049 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11050 struct wireless_dev *wdev = info->user_ptr[1];
11051
11052 if (wdev->netdev)
11053 dev_put(wdev->netdev);
11054 } else {
11055 dev_put(info->user_ptr[1]);
11056 }
11057 }
Johannes Berg5393b912014-09-10 15:00:16 +030011058
Johannes Berg4c476992010-10-04 21:36:35 +020011059 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11060 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011061
11062 /* If needed, clear the netlink message payload from the SKB
11063 * as it might contain key data that shouldn't stick around on
11064 * the heap after the SKB is freed. The netlink message header
11065 * is still needed for further processing, so leave it intact.
11066 */
11067 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11068 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11069
11070 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11071 }
Johannes Berg4c476992010-10-04 21:36:35 +020011072}
11073
Johannes Berg4534de82013-11-14 17:14:46 +010011074static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011075 {
11076 .cmd = NL80211_CMD_GET_WIPHY,
11077 .doit = nl80211_get_wiphy,
11078 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011079 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011080 .policy = nl80211_policy,
11081 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011082 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11083 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011084 },
11085 {
11086 .cmd = NL80211_CMD_SET_WIPHY,
11087 .doit = nl80211_set_wiphy,
11088 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011089 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011090 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011091 },
11092 {
11093 .cmd = NL80211_CMD_GET_INTERFACE,
11094 .doit = nl80211_get_interface,
11095 .dumpit = nl80211_dump_interface,
11096 .policy = nl80211_policy,
11097 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011098 .internal_flags = NL80211_FLAG_NEED_WDEV |
11099 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011100 },
11101 {
11102 .cmd = NL80211_CMD_SET_INTERFACE,
11103 .doit = nl80211_set_interface,
11104 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011105 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011106 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11107 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011108 },
11109 {
11110 .cmd = NL80211_CMD_NEW_INTERFACE,
11111 .doit = nl80211_new_interface,
11112 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011113 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011114 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11115 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011116 },
11117 {
11118 .cmd = NL80211_CMD_DEL_INTERFACE,
11119 .doit = nl80211_del_interface,
11120 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011121 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011122 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011123 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011124 },
Johannes Berg41ade002007-12-19 02:03:29 +010011125 {
11126 .cmd = NL80211_CMD_GET_KEY,
11127 .doit = nl80211_get_key,
11128 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011129 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011130 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011131 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011132 },
11133 {
11134 .cmd = NL80211_CMD_SET_KEY,
11135 .doit = nl80211_set_key,
11136 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011137 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011138 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011139 NL80211_FLAG_NEED_RTNL |
11140 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011141 },
11142 {
11143 .cmd = NL80211_CMD_NEW_KEY,
11144 .doit = nl80211_new_key,
11145 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011146 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011147 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011148 NL80211_FLAG_NEED_RTNL |
11149 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011150 },
11151 {
11152 .cmd = NL80211_CMD_DEL_KEY,
11153 .doit = nl80211_del_key,
11154 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011155 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011157 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011158 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011159 {
11160 .cmd = NL80211_CMD_SET_BEACON,
11161 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011162 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011163 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011165 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011166 },
11167 {
Johannes Berg88600202012-02-13 15:17:18 +010011168 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011169 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011170 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011171 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011173 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011174 },
11175 {
Johannes Berg88600202012-02-13 15:17:18 +010011176 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011177 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011178 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011179 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011180 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011181 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011182 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011183 {
11184 .cmd = NL80211_CMD_GET_STATION,
11185 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011186 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011187 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011188 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11189 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011190 },
11191 {
11192 .cmd = NL80211_CMD_SET_STATION,
11193 .doit = nl80211_set_station,
11194 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011195 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011197 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011198 },
11199 {
11200 .cmd = NL80211_CMD_NEW_STATION,
11201 .doit = nl80211_new_station,
11202 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011203 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011205 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011206 },
11207 {
11208 .cmd = NL80211_CMD_DEL_STATION,
11209 .doit = nl80211_del_station,
11210 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011211 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011212 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011213 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011214 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011215 {
11216 .cmd = NL80211_CMD_GET_MPATH,
11217 .doit = nl80211_get_mpath,
11218 .dumpit = nl80211_dump_mpath,
11219 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011220 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011222 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011223 },
11224 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011225 .cmd = NL80211_CMD_GET_MPP,
11226 .doit = nl80211_get_mpp,
11227 .dumpit = nl80211_dump_mpp,
11228 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011229 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11231 NL80211_FLAG_NEED_RTNL,
11232 },
11233 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011234 .cmd = NL80211_CMD_SET_MPATH,
11235 .doit = nl80211_set_mpath,
11236 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011237 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011239 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011240 },
11241 {
11242 .cmd = NL80211_CMD_NEW_MPATH,
11243 .doit = nl80211_new_mpath,
11244 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011245 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011247 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011248 },
11249 {
11250 .cmd = NL80211_CMD_DEL_MPATH,
11251 .doit = nl80211_del_mpath,
11252 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011253 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011254 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011255 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011256 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011257 {
11258 .cmd = NL80211_CMD_SET_BSS,
11259 .doit = nl80211_set_bss,
11260 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011261 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011262 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011263 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011264 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011265 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011266 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011267 .doit = nl80211_get_reg_do,
11268 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011269 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011270 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011271 /* can be retrieved by unprivileged users */
11272 },
Johannes Bergb6863032015-10-15 09:25:18 +020011273#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011274 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011275 .cmd = NL80211_CMD_SET_REG,
11276 .doit = nl80211_set_reg,
11277 .policy = nl80211_policy,
11278 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011279 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011280 },
Johannes Bergb6863032015-10-15 09:25:18 +020011281#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011282 {
11283 .cmd = NL80211_CMD_REQ_SET_REG,
11284 .doit = nl80211_req_set_reg,
11285 .policy = nl80211_policy,
11286 .flags = GENL_ADMIN_PERM,
11287 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011288 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011289 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11290 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011291 .policy = nl80211_policy,
11292 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011293 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011294 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011295 },
11296 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011297 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11298 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011299 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011300 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011301 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011302 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011303 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011304 {
Johannes Berg2a519312009-02-10 21:25:55 +010011305 .cmd = NL80211_CMD_TRIGGER_SCAN,
11306 .doit = nl80211_trigger_scan,
11307 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011308 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011309 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011310 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011311 },
11312 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011313 .cmd = NL80211_CMD_ABORT_SCAN,
11314 .doit = nl80211_abort_scan,
11315 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011316 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011317 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11318 NL80211_FLAG_NEED_RTNL,
11319 },
11320 {
Johannes Berg2a519312009-02-10 21:25:55 +010011321 .cmd = NL80211_CMD_GET_SCAN,
11322 .policy = nl80211_policy,
11323 .dumpit = nl80211_dump_scan,
11324 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011325 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011326 .cmd = NL80211_CMD_START_SCHED_SCAN,
11327 .doit = nl80211_start_sched_scan,
11328 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011329 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11331 NL80211_FLAG_NEED_RTNL,
11332 },
11333 {
11334 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11335 .doit = nl80211_stop_sched_scan,
11336 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011337 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011338 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11339 NL80211_FLAG_NEED_RTNL,
11340 },
11341 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011342 .cmd = NL80211_CMD_AUTHENTICATE,
11343 .doit = nl80211_authenticate,
11344 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011345 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011347 NL80211_FLAG_NEED_RTNL |
11348 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011349 },
11350 {
11351 .cmd = NL80211_CMD_ASSOCIATE,
11352 .doit = nl80211_associate,
11353 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011354 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011356 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011357 },
11358 {
11359 .cmd = NL80211_CMD_DEAUTHENTICATE,
11360 .doit = nl80211_deauthenticate,
11361 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011362 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011364 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011365 },
11366 {
11367 .cmd = NL80211_CMD_DISASSOCIATE,
11368 .doit = nl80211_disassociate,
11369 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011370 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011371 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011372 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011373 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011374 {
11375 .cmd = NL80211_CMD_JOIN_IBSS,
11376 .doit = nl80211_join_ibss,
11377 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011378 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011379 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011380 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011381 },
11382 {
11383 .cmd = NL80211_CMD_LEAVE_IBSS,
11384 .doit = nl80211_leave_ibss,
11385 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011386 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011388 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011389 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011390#ifdef CONFIG_NL80211_TESTMODE
11391 {
11392 .cmd = NL80211_CMD_TESTMODE,
11393 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011394 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011395 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011396 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011397 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11398 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011399 },
11400#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011401 {
11402 .cmd = NL80211_CMD_CONNECT,
11403 .doit = nl80211_connect,
11404 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011405 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011407 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011408 },
11409 {
11410 .cmd = NL80211_CMD_DISCONNECT,
11411 .doit = nl80211_disconnect,
11412 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011413 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011414 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011415 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011416 },
Johannes Berg463d0182009-07-14 00:33:35 +020011417 {
11418 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11419 .doit = nl80211_wiphy_netns,
11420 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011421 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011422 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11423 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011424 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011425 {
11426 .cmd = NL80211_CMD_GET_SURVEY,
11427 .policy = nl80211_policy,
11428 .dumpit = nl80211_dump_survey,
11429 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011430 {
11431 .cmd = NL80211_CMD_SET_PMKSA,
11432 .doit = nl80211_setdel_pmksa,
11433 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011434 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011436 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011437 },
11438 {
11439 .cmd = NL80211_CMD_DEL_PMKSA,
11440 .doit = nl80211_setdel_pmksa,
11441 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011442 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011444 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011445 },
11446 {
11447 .cmd = NL80211_CMD_FLUSH_PMKSA,
11448 .doit = nl80211_flush_pmksa,
11449 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011450 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011452 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011453 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011454 {
11455 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11456 .doit = nl80211_remain_on_channel,
11457 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011458 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011459 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011460 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011461 },
11462 {
11463 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11464 .doit = nl80211_cancel_remain_on_channel,
11465 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011466 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011467 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011468 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011469 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011470 {
11471 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11472 .doit = nl80211_set_tx_bitrate_mask,
11473 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011474 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011475 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11476 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011477 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011478 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011479 .cmd = NL80211_CMD_REGISTER_FRAME,
11480 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011481 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011482 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011483 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011484 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011485 },
11486 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011487 .cmd = NL80211_CMD_FRAME,
11488 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011489 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011490 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011491 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011492 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011493 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011494 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011495 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11496 .doit = nl80211_tx_mgmt_cancel_wait,
11497 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011498 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011499 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011500 NL80211_FLAG_NEED_RTNL,
11501 },
11502 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011503 .cmd = NL80211_CMD_SET_POWER_SAVE,
11504 .doit = nl80211_set_power_save,
11505 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011506 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011507 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11508 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011509 },
11510 {
11511 .cmd = NL80211_CMD_GET_POWER_SAVE,
11512 .doit = nl80211_get_power_save,
11513 .policy = nl80211_policy,
11514 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011515 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11516 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011517 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011518 {
11519 .cmd = NL80211_CMD_SET_CQM,
11520 .doit = nl80211_set_cqm,
11521 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011522 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011523 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11524 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011525 },
Johannes Bergf444de02010-05-05 15:25:02 +020011526 {
11527 .cmd = NL80211_CMD_SET_CHANNEL,
11528 .doit = nl80211_set_channel,
11529 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011530 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011531 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11532 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011533 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011534 {
11535 .cmd = NL80211_CMD_SET_WDS_PEER,
11536 .doit = nl80211_set_wds_peer,
11537 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011538 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011539 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11540 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011541 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011542 {
11543 .cmd = NL80211_CMD_JOIN_MESH,
11544 .doit = nl80211_join_mesh,
11545 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011546 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011547 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11548 NL80211_FLAG_NEED_RTNL,
11549 },
11550 {
11551 .cmd = NL80211_CMD_LEAVE_MESH,
11552 .doit = nl80211_leave_mesh,
11553 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011554 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11556 NL80211_FLAG_NEED_RTNL,
11557 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011558 {
11559 .cmd = NL80211_CMD_JOIN_OCB,
11560 .doit = nl80211_join_ocb,
11561 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011562 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11564 NL80211_FLAG_NEED_RTNL,
11565 },
11566 {
11567 .cmd = NL80211_CMD_LEAVE_OCB,
11568 .doit = nl80211_leave_ocb,
11569 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011570 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011571 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11572 NL80211_FLAG_NEED_RTNL,
11573 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011574#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011575 {
11576 .cmd = NL80211_CMD_GET_WOWLAN,
11577 .doit = nl80211_get_wowlan,
11578 .policy = nl80211_policy,
11579 /* can be retrieved by unprivileged users */
11580 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11581 NL80211_FLAG_NEED_RTNL,
11582 },
11583 {
11584 .cmd = NL80211_CMD_SET_WOWLAN,
11585 .doit = nl80211_set_wowlan,
11586 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011587 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011588 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11589 NL80211_FLAG_NEED_RTNL,
11590 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011591#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011592 {
11593 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11594 .doit = nl80211_set_rekey_data,
11595 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011596 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011598 NL80211_FLAG_NEED_RTNL |
11599 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011600 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011601 {
11602 .cmd = NL80211_CMD_TDLS_MGMT,
11603 .doit = nl80211_tdls_mgmt,
11604 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011605 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11607 NL80211_FLAG_NEED_RTNL,
11608 },
11609 {
11610 .cmd = NL80211_CMD_TDLS_OPER,
11611 .doit = nl80211_tdls_oper,
11612 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011613 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11615 NL80211_FLAG_NEED_RTNL,
11616 },
Johannes Berg28946da2011-11-04 11:18:12 +010011617 {
11618 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11619 .doit = nl80211_register_unexpected_frame,
11620 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011621 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011622 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11623 NL80211_FLAG_NEED_RTNL,
11624 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011625 {
11626 .cmd = NL80211_CMD_PROBE_CLIENT,
11627 .doit = nl80211_probe_client,
11628 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011629 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011631 NL80211_FLAG_NEED_RTNL,
11632 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011633 {
11634 .cmd = NL80211_CMD_REGISTER_BEACONS,
11635 .doit = nl80211_register_beacons,
11636 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011637 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010011638 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11639 NL80211_FLAG_NEED_RTNL,
11640 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011641 {
11642 .cmd = NL80211_CMD_SET_NOACK_MAP,
11643 .doit = nl80211_set_noack_map,
11644 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011645 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011646 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11647 NL80211_FLAG_NEED_RTNL,
11648 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011649 {
11650 .cmd = NL80211_CMD_START_P2P_DEVICE,
11651 .doit = nl80211_start_p2p_device,
11652 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011653 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011654 .internal_flags = NL80211_FLAG_NEED_WDEV |
11655 NL80211_FLAG_NEED_RTNL,
11656 },
11657 {
11658 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11659 .doit = nl80211_stop_p2p_device,
11660 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011661 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011662 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11663 NL80211_FLAG_NEED_RTNL,
11664 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011665 {
11666 .cmd = NL80211_CMD_SET_MCAST_RATE,
11667 .doit = nl80211_set_mcast_rate,
11668 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011669 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011670 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11671 NL80211_FLAG_NEED_RTNL,
11672 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011673 {
11674 .cmd = NL80211_CMD_SET_MAC_ACL,
11675 .doit = nl80211_set_mac_acl,
11676 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011677 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011678 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11679 NL80211_FLAG_NEED_RTNL,
11680 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011681 {
11682 .cmd = NL80211_CMD_RADAR_DETECT,
11683 .doit = nl80211_start_radar_detection,
11684 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011685 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011686 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11687 NL80211_FLAG_NEED_RTNL,
11688 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011689 {
11690 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11691 .doit = nl80211_get_protocol_features,
11692 .policy = nl80211_policy,
11693 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011694 {
11695 .cmd = NL80211_CMD_UPDATE_FT_IES,
11696 .doit = nl80211_update_ft_ies,
11697 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011698 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011699 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11700 NL80211_FLAG_NEED_RTNL,
11701 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011702 {
11703 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11704 .doit = nl80211_crit_protocol_start,
11705 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011706 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011707 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11708 NL80211_FLAG_NEED_RTNL,
11709 },
11710 {
11711 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11712 .doit = nl80211_crit_protocol_stop,
11713 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011714 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011715 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11716 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011717 },
11718 {
11719 .cmd = NL80211_CMD_GET_COALESCE,
11720 .doit = nl80211_get_coalesce,
11721 .policy = nl80211_policy,
11722 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11723 NL80211_FLAG_NEED_RTNL,
11724 },
11725 {
11726 .cmd = NL80211_CMD_SET_COALESCE,
11727 .doit = nl80211_set_coalesce,
11728 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011729 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011730 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11731 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011732 },
11733 {
11734 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11735 .doit = nl80211_channel_switch,
11736 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011737 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11739 NL80211_FLAG_NEED_RTNL,
11740 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011741 {
11742 .cmd = NL80211_CMD_VENDOR,
11743 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011744 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011745 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011746 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011747 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11748 NL80211_FLAG_NEED_RTNL,
11749 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011750 {
11751 .cmd = NL80211_CMD_SET_QOS_MAP,
11752 .doit = nl80211_set_qos_map,
11753 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011754 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11756 NL80211_FLAG_NEED_RTNL,
11757 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011758 {
11759 .cmd = NL80211_CMD_ADD_TX_TS,
11760 .doit = nl80211_add_tx_ts,
11761 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011762 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011763 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11764 NL80211_FLAG_NEED_RTNL,
11765 },
11766 {
11767 .cmd = NL80211_CMD_DEL_TX_TS,
11768 .doit = nl80211_del_tx_ts,
11769 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011770 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11772 NL80211_FLAG_NEED_RTNL,
11773 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011774 {
11775 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11776 .doit = nl80211_tdls_channel_switch,
11777 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011778 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011779 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11780 NL80211_FLAG_NEED_RTNL,
11781 },
11782 {
11783 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11784 .doit = nl80211_tdls_cancel_channel_switch,
11785 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011786 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011787 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11788 NL80211_FLAG_NEED_RTNL,
11789 },
Johannes Berg55682962007-09-20 13:09:35 -040011790};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011791
Johannes Berg55682962007-09-20 13:09:35 -040011792/* notification functions */
11793
Johannes Berg3bb20552014-05-26 13:52:25 +020011794void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11795 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011796{
11797 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011798 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011799
Johannes Berg3bb20552014-05-26 13:52:25 +020011800 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11801 cmd != NL80211_CMD_DEL_WIPHY);
11802
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011804 if (!msg)
11805 return;
11806
Johannes Berg3bb20552014-05-26 13:52:25 +020011807 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011808 nlmsg_free(msg);
11809 return;
11810 }
11811
Johannes Berg68eb5502013-11-19 15:19:38 +010011812 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011813 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011814}
11815
Johannes Berg362a4152009-05-24 16:43:15 +020011816static int nl80211_add_scan_req(struct sk_buff *msg,
11817 struct cfg80211_registered_device *rdev)
11818{
11819 struct cfg80211_scan_request *req = rdev->scan_req;
11820 struct nlattr *nest;
11821 int i;
11822
11823 if (WARN_ON(!req))
11824 return 0;
11825
11826 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11827 if (!nest)
11828 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011829 for (i = 0; i < req->n_ssids; i++) {
11830 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11831 goto nla_put_failure;
11832 }
Johannes Berg362a4152009-05-24 16:43:15 +020011833 nla_nest_end(msg, nest);
11834
11835 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11836 if (!nest)
11837 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011838 for (i = 0; i < req->n_channels; i++) {
11839 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11840 goto nla_put_failure;
11841 }
Johannes Berg362a4152009-05-24 16:43:15 +020011842 nla_nest_end(msg, nest);
11843
David S. Miller9360ffd2012-03-29 04:41:26 -040011844 if (req->ie &&
11845 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11846 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011847
Johannes Bergae917c92013-10-25 11:05:22 +020011848 if (req->flags &&
11849 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11850 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011851
Avraham Stern1d762502016-07-05 17:10:13 +030011852 if (req->info.scan_start_tsf &&
11853 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
11854 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
11855 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
11856 req->info.tsf_bssid)))
11857 goto nla_put_failure;
11858
Johannes Berg362a4152009-05-24 16:43:15 +020011859 return 0;
11860 nla_put_failure:
11861 return -ENOBUFS;
11862}
11863
Johannes Berga538e2d2009-06-16 19:56:42 +020011864static int nl80211_send_scan_msg(struct sk_buff *msg,
11865 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011866 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011867 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011868 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011869{
11870 void *hdr;
11871
Eric W. Biederman15e47302012-09-07 20:12:54 +000011872 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011873 if (!hdr)
11874 return -1;
11875
David S. Miller9360ffd2012-03-29 04:41:26 -040011876 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011877 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11878 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011879 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11880 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011881 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011882
Johannes Berg362a4152009-05-24 16:43:15 +020011883 /* ignore errors and send incomplete event anyway */
11884 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011885
Johannes Berg053c0952015-01-16 22:09:00 +010011886 genlmsg_end(msg, hdr);
11887 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011888
11889 nla_put_failure:
11890 genlmsg_cancel(msg, hdr);
11891 return -EMSGSIZE;
11892}
11893
Luciano Coelho807f8a82011-05-11 17:09:35 +030011894static int
11895nl80211_send_sched_scan_msg(struct sk_buff *msg,
11896 struct cfg80211_registered_device *rdev,
11897 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011898 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011899{
11900 void *hdr;
11901
Eric W. Biederman15e47302012-09-07 20:12:54 +000011902 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011903 if (!hdr)
11904 return -1;
11905
David S. Miller9360ffd2012-03-29 04:41:26 -040011906 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11907 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11908 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011909
Johannes Berg053c0952015-01-16 22:09:00 +010011910 genlmsg_end(msg, hdr);
11911 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011912
11913 nla_put_failure:
11914 genlmsg_cancel(msg, hdr);
11915 return -EMSGSIZE;
11916}
11917
Johannes Berga538e2d2009-06-16 19:56:42 +020011918void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011919 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011920{
11921 struct sk_buff *msg;
11922
Thomas Graf58050fc2012-06-28 03:57:45 +000011923 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011924 if (!msg)
11925 return;
11926
Johannes Bergfd014282012-06-18 19:17:03 +020011927 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011928 NL80211_CMD_TRIGGER_SCAN) < 0) {
11929 nlmsg_free(msg);
11930 return;
11931 }
11932
Johannes Berg68eb5502013-11-19 15:19:38 +010011933 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011934 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011935}
11936
Johannes Bergf9d15d12014-01-22 11:14:19 +020011937struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11938 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011939{
11940 struct sk_buff *msg;
11941
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011942 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011943 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011944 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011945
Johannes Bergfd014282012-06-18 19:17:03 +020011946 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011947 aborted ? NL80211_CMD_SCAN_ABORTED :
11948 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011949 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011950 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011951 }
11952
Johannes Bergf9d15d12014-01-22 11:14:19 +020011953 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011954}
11955
Johannes Bergf9d15d12014-01-22 11:14:19 +020011956void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11957 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011958{
Johannes Berg2a519312009-02-10 21:25:55 +010011959 if (!msg)
11960 return;
11961
Johannes Berg68eb5502013-11-19 15:19:38 +010011962 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011963 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011964}
11965
Luciano Coelho807f8a82011-05-11 17:09:35 +030011966void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11967 struct net_device *netdev)
11968{
11969 struct sk_buff *msg;
11970
11971 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11972 if (!msg)
11973 return;
11974
11975 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11976 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11977 nlmsg_free(msg);
11978 return;
11979 }
11980
Johannes Berg68eb5502013-11-19 15:19:38 +010011981 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011982 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011983}
11984
11985void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11986 struct net_device *netdev, u32 cmd)
11987{
11988 struct sk_buff *msg;
11989
Thomas Graf58050fc2012-06-28 03:57:45 +000011990 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011991 if (!msg)
11992 return;
11993
11994 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11995 nlmsg_free(msg);
11996 return;
11997 }
11998
Johannes Berg68eb5502013-11-19 15:19:38 +010011999 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012000 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012001}
12002
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012003static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12004 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012005{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012006 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012007 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12008 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012009
David S. Miller9360ffd2012-03-29 04:41:26 -040012010 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12011 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12012 NL80211_REGDOM_TYPE_WORLD))
12013 goto nla_put_failure;
12014 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12015 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12016 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12017 goto nla_put_failure;
12018 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12019 request->intersect) {
12020 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12021 NL80211_REGDOM_TYPE_INTERSECTION))
12022 goto nla_put_failure;
12023 } else {
12024 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12025 NL80211_REGDOM_TYPE_COUNTRY) ||
12026 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12027 request->alpha2))
12028 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012029 }
12030
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012031 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12032 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12033
12034 if (wiphy &&
12035 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12036 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012037
12038 if (wiphy &&
12039 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12040 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12041 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012042 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012043
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012044 return true;
12045
12046nla_put_failure:
12047 return false;
12048}
12049
12050/*
12051 * This can happen on global regulatory changes or device specific settings
12052 * based on custom regulatory domains.
12053 */
12054void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12055 struct regulatory_request *request)
12056{
12057 struct sk_buff *msg;
12058 void *hdr;
12059
12060 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12061 if (!msg)
12062 return;
12063
12064 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12065 if (!hdr) {
12066 nlmsg_free(msg);
12067 return;
12068 }
12069
12070 if (nl80211_reg_change_event_fill(msg, request) == false)
12071 goto nla_put_failure;
12072
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012073 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012074
Johannes Bergbc43b282009-07-25 10:54:13 +020012075 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012076 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012077 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012078 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012079
12080 return;
12081
12082nla_put_failure:
12083 genlmsg_cancel(msg, hdr);
12084 nlmsg_free(msg);
12085}
12086
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012087static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12088 struct net_device *netdev,
12089 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012090 enum nl80211_commands cmd, gfp_t gfp,
12091 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012092{
12093 struct sk_buff *msg;
12094 void *hdr;
12095
Johannes Berge6d6e342009-07-01 21:26:47 +020012096 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012097 if (!msg)
12098 return;
12099
12100 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12101 if (!hdr) {
12102 nlmsg_free(msg);
12103 return;
12104 }
12105
David S. Miller9360ffd2012-03-29 04:41:26 -040012106 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12107 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12108 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12109 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012110
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012111 if (uapsd_queues >= 0) {
12112 struct nlattr *nla_wmm =
12113 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12114 if (!nla_wmm)
12115 goto nla_put_failure;
12116
12117 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12118 uapsd_queues))
12119 goto nla_put_failure;
12120
12121 nla_nest_end(msg, nla_wmm);
12122 }
12123
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012124 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012125
Johannes Berg68eb5502013-11-19 15:19:38 +010012126 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012127 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012128 return;
12129
12130 nla_put_failure:
12131 genlmsg_cancel(msg, hdr);
12132 nlmsg_free(msg);
12133}
12134
12135void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012136 struct net_device *netdev, const u8 *buf,
12137 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012138{
12139 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012140 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012141}
12142
12143void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12144 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012145 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012146{
Johannes Berge6d6e342009-07-01 21:26:47 +020012147 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012148 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012149}
12150
Jouni Malinen53b46b82009-03-27 20:53:56 +020012151void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012152 struct net_device *netdev, const u8 *buf,
12153 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012154{
12155 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012156 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012157}
12158
Jouni Malinen53b46b82009-03-27 20:53:56 +020012159void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12160 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012161 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012162{
12163 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012164 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012165}
12166
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012167void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12168 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012169{
Johannes Berg947add32013-02-22 22:05:20 +010012170 struct wireless_dev *wdev = dev->ieee80211_ptr;
12171 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012172 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012173 const struct ieee80211_mgmt *mgmt = (void *)buf;
12174 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012175
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012176 if (WARN_ON(len < 2))
12177 return;
12178
12179 if (ieee80211_is_deauth(mgmt->frame_control))
12180 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12181 else
12182 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12183
12184 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012185 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012186}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012187EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012188
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012189static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12190 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012191 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012192{
12193 struct sk_buff *msg;
12194 void *hdr;
12195
Johannes Berge6d6e342009-07-01 21:26:47 +020012196 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012197 if (!msg)
12198 return;
12199
12200 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12201 if (!hdr) {
12202 nlmsg_free(msg);
12203 return;
12204 }
12205
David S. Miller9360ffd2012-03-29 04:41:26 -040012206 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12207 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12208 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12209 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12210 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012211
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012212 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012213
Johannes Berg68eb5502013-11-19 15:19:38 +010012214 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012215 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012216 return;
12217
12218 nla_put_failure:
12219 genlmsg_cancel(msg, hdr);
12220 nlmsg_free(msg);
12221}
12222
12223void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012224 struct net_device *netdev, const u8 *addr,
12225 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012226{
12227 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012228 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012229}
12230
12231void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012232 struct net_device *netdev, const u8 *addr,
12233 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012234{
Johannes Berge6d6e342009-07-01 21:26:47 +020012235 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12236 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012237}
12238
Samuel Ortizb23aa672009-07-01 21:26:54 +020012239void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12240 struct net_device *netdev, const u8 *bssid,
12241 const u8 *req_ie, size_t req_ie_len,
12242 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012243 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012244{
12245 struct sk_buff *msg;
12246 void *hdr;
12247
Thomas Graf58050fc2012-06-28 03:57:45 +000012248 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012249 if (!msg)
12250 return;
12251
12252 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12253 if (!hdr) {
12254 nlmsg_free(msg);
12255 return;
12256 }
12257
David S. Miller9360ffd2012-03-29 04:41:26 -040012258 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12259 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12260 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012261 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12262 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12263 status) ||
12264 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012265 (req_ie &&
12266 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12267 (resp_ie &&
12268 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12269 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012270
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012271 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012272
Johannes Berg68eb5502013-11-19 15:19:38 +010012273 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012274 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012275 return;
12276
12277 nla_put_failure:
12278 genlmsg_cancel(msg, hdr);
12279 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012280}
12281
12282void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12283 struct net_device *netdev, const u8 *bssid,
12284 const u8 *req_ie, size_t req_ie_len,
12285 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12286{
12287 struct sk_buff *msg;
12288 void *hdr;
12289
Thomas Graf58050fc2012-06-28 03:57:45 +000012290 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012291 if (!msg)
12292 return;
12293
12294 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12295 if (!hdr) {
12296 nlmsg_free(msg);
12297 return;
12298 }
12299
David S. Miller9360ffd2012-03-29 04:41:26 -040012300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12301 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12302 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12303 (req_ie &&
12304 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12305 (resp_ie &&
12306 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12307 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012308
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012309 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012310
Johannes Berg68eb5502013-11-19 15:19:38 +010012311 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012312 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012313 return;
12314
12315 nla_put_failure:
12316 genlmsg_cancel(msg, hdr);
12317 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012318}
12319
12320void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12321 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012322 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012323{
12324 struct sk_buff *msg;
12325 void *hdr;
12326
Thomas Graf58050fc2012-06-28 03:57:45 +000012327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012328 if (!msg)
12329 return;
12330
12331 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12332 if (!hdr) {
12333 nlmsg_free(msg);
12334 return;
12335 }
12336
David S. Miller9360ffd2012-03-29 04:41:26 -040012337 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12338 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12339 (from_ap && reason &&
12340 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12341 (from_ap &&
12342 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12343 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12344 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012345
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012346 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012347
Johannes Berg68eb5502013-11-19 15:19:38 +010012348 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012349 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012350 return;
12351
12352 nla_put_failure:
12353 genlmsg_cancel(msg, hdr);
12354 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012355}
12356
Johannes Berg04a773a2009-04-19 21:24:32 +020012357void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12358 struct net_device *netdev, const u8 *bssid,
12359 gfp_t gfp)
12360{
12361 struct sk_buff *msg;
12362 void *hdr;
12363
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012364 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012365 if (!msg)
12366 return;
12367
12368 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12369 if (!hdr) {
12370 nlmsg_free(msg);
12371 return;
12372 }
12373
David S. Miller9360ffd2012-03-29 04:41:26 -040012374 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12375 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12376 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12377 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012378
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012379 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012380
Johannes Berg68eb5502013-11-19 15:19:38 +010012381 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012382 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012383 return;
12384
12385 nla_put_failure:
12386 genlmsg_cancel(msg, hdr);
12387 nlmsg_free(msg);
12388}
12389
Johannes Berg947add32013-02-22 22:05:20 +010012390void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12391 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012392{
Johannes Berg947add32013-02-22 22:05:20 +010012393 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012394 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012395 struct sk_buff *msg;
12396 void *hdr;
12397
Johannes Berg947add32013-02-22 22:05:20 +010012398 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12399 return;
12400
12401 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12402
Javier Cardonac93b5e72011-04-07 15:08:34 -070012403 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12404 if (!msg)
12405 return;
12406
12407 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12408 if (!hdr) {
12409 nlmsg_free(msg);
12410 return;
12411 }
12412
David S. Miller9360ffd2012-03-29 04:41:26 -040012413 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012414 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12415 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012416 (ie_len && ie &&
12417 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12418 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012419
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012420 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012421
Johannes Berg68eb5502013-11-19 15:19:38 +010012422 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012423 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012424 return;
12425
12426 nla_put_failure:
12427 genlmsg_cancel(msg, hdr);
12428 nlmsg_free(msg);
12429}
Johannes Berg947add32013-02-22 22:05:20 +010012430EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012431
Jouni Malinena3b8b052009-03-27 21:59:49 +020012432void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12433 struct net_device *netdev, const u8 *addr,
12434 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012435 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012436{
12437 struct sk_buff *msg;
12438 void *hdr;
12439
Johannes Berge6d6e342009-07-01 21:26:47 +020012440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012441 if (!msg)
12442 return;
12443
12444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12445 if (!hdr) {
12446 nlmsg_free(msg);
12447 return;
12448 }
12449
David S. Miller9360ffd2012-03-29 04:41:26 -040012450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12451 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12452 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12453 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12454 (key_id != -1 &&
12455 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12456 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12457 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012458
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012459 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012460
Johannes Berg68eb5502013-11-19 15:19:38 +010012461 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012462 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012463 return;
12464
12465 nla_put_failure:
12466 genlmsg_cancel(msg, hdr);
12467 nlmsg_free(msg);
12468}
12469
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012470void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12471 struct ieee80211_channel *channel_before,
12472 struct ieee80211_channel *channel_after)
12473{
12474 struct sk_buff *msg;
12475 void *hdr;
12476 struct nlattr *nl_freq;
12477
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012479 if (!msg)
12480 return;
12481
12482 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12483 if (!hdr) {
12484 nlmsg_free(msg);
12485 return;
12486 }
12487
12488 /*
12489 * Since we are applying the beacon hint to a wiphy we know its
12490 * wiphy_idx is valid
12491 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012492 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12493 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012494
12495 /* Before */
12496 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12497 if (!nl_freq)
12498 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012499 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012500 goto nla_put_failure;
12501 nla_nest_end(msg, nl_freq);
12502
12503 /* After */
12504 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12505 if (!nl_freq)
12506 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012507 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012508 goto nla_put_failure;
12509 nla_nest_end(msg, nl_freq);
12510
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012511 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012512
Johannes Berg463d0182009-07-14 00:33:35 +020012513 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012514 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012515 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012516 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012517
12518 return;
12519
12520nla_put_failure:
12521 genlmsg_cancel(msg, hdr);
12522 nlmsg_free(msg);
12523}
12524
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012525static void nl80211_send_remain_on_chan_event(
12526 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012527 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012528 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012529 unsigned int duration, gfp_t gfp)
12530{
12531 struct sk_buff *msg;
12532 void *hdr;
12533
12534 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12535 if (!msg)
12536 return;
12537
12538 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12539 if (!hdr) {
12540 nlmsg_free(msg);
12541 return;
12542 }
12543
David S. Miller9360ffd2012-03-29 04:41:26 -040012544 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012545 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12546 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012547 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12548 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012549 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012550 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12551 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012552 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12553 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012554 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012555
David S. Miller9360ffd2012-03-29 04:41:26 -040012556 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12557 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12558 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012559
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012560 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012561
Johannes Berg68eb5502013-11-19 15:19:38 +010012562 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012563 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012564 return;
12565
12566 nla_put_failure:
12567 genlmsg_cancel(msg, hdr);
12568 nlmsg_free(msg);
12569}
12570
Johannes Berg947add32013-02-22 22:05:20 +010012571void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12572 struct ieee80211_channel *chan,
12573 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012574{
Johannes Berg947add32013-02-22 22:05:20 +010012575 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012576 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012577
12578 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012579 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012580 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012581 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012582}
Johannes Berg947add32013-02-22 22:05:20 +010012583EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012584
Johannes Berg947add32013-02-22 22:05:20 +010012585void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12586 struct ieee80211_channel *chan,
12587 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012588{
Johannes Berg947add32013-02-22 22:05:20 +010012589 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012590 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012591
12592 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012593 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012594 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012595}
Johannes Berg947add32013-02-22 22:05:20 +010012596EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012597
Johannes Berg947add32013-02-22 22:05:20 +010012598void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12599 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012600{
Johannes Berg947add32013-02-22 22:05:20 +010012601 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012602 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012603 struct sk_buff *msg;
12604
Johannes Berg947add32013-02-22 22:05:20 +010012605 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12606
Thomas Graf58050fc2012-06-28 03:57:45 +000012607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012608 if (!msg)
12609 return;
12610
Johannes Bergcf5ead82014-11-14 17:14:00 +010012611 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012612 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012613 nlmsg_free(msg);
12614 return;
12615 }
12616
Johannes Berg68eb5502013-11-19 15:19:38 +010012617 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012618 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012619}
Johannes Berg947add32013-02-22 22:05:20 +010012620EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012621
Johannes Bergcf5ead82014-11-14 17:14:00 +010012622void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12623 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012624{
Johannes Berg947add32013-02-22 22:05:20 +010012625 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012626 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012627 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012628 struct station_info empty_sinfo = {};
12629
12630 if (!sinfo)
12631 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012632
Johannes Berg947add32013-02-22 22:05:20 +010012633 trace_cfg80211_del_sta(dev, mac_addr);
12634
Thomas Graf58050fc2012-06-28 03:57:45 +000012635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012636 if (!msg)
12637 return;
12638
Johannes Bergcf5ead82014-11-14 17:14:00 +010012639 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012640 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012641 nlmsg_free(msg);
12642 return;
12643 }
12644
Johannes Berg68eb5502013-11-19 15:19:38 +010012645 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012646 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012647}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012648EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012649
Johannes Berg947add32013-02-22 22:05:20 +010012650void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12651 enum nl80211_connect_failed_reason reason,
12652 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012653{
Johannes Berg947add32013-02-22 22:05:20 +010012654 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012655 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012656 struct sk_buff *msg;
12657 void *hdr;
12658
12659 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12660 if (!msg)
12661 return;
12662
12663 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12664 if (!hdr) {
12665 nlmsg_free(msg);
12666 return;
12667 }
12668
12669 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12670 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12671 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12672 goto nla_put_failure;
12673
12674 genlmsg_end(msg, hdr);
12675
Johannes Berg68eb5502013-11-19 15:19:38 +010012676 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012677 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012678 return;
12679
12680 nla_put_failure:
12681 genlmsg_cancel(msg, hdr);
12682 nlmsg_free(msg);
12683}
Johannes Berg947add32013-02-22 22:05:20 +010012684EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012685
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012686static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12687 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012688{
12689 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012690 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012691 struct sk_buff *msg;
12692 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012693 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012694
Eric W. Biederman15e47302012-09-07 20:12:54 +000012695 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012696 return false;
12697
12698 msg = nlmsg_new(100, gfp);
12699 if (!msg)
12700 return true;
12701
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012702 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012703 if (!hdr) {
12704 nlmsg_free(msg);
12705 return true;
12706 }
12707
David S. Miller9360ffd2012-03-29 04:41:26 -040012708 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12709 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12710 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12711 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012712
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012713 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012714 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012715 return true;
12716
12717 nla_put_failure:
12718 genlmsg_cancel(msg, hdr);
12719 nlmsg_free(msg);
12720 return true;
12721}
12722
Johannes Berg947add32013-02-22 22:05:20 +010012723bool cfg80211_rx_spurious_frame(struct net_device *dev,
12724 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012725{
Johannes Berg947add32013-02-22 22:05:20 +010012726 struct wireless_dev *wdev = dev->ieee80211_ptr;
12727 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012728
Johannes Berg947add32013-02-22 22:05:20 +010012729 trace_cfg80211_rx_spurious_frame(dev, addr);
12730
12731 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12732 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12733 trace_cfg80211_return_bool(false);
12734 return false;
12735 }
12736 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12737 addr, gfp);
12738 trace_cfg80211_return_bool(ret);
12739 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012740}
Johannes Berg947add32013-02-22 22:05:20 +010012741EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12742
12743bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12744 const u8 *addr, gfp_t gfp)
12745{
12746 struct wireless_dev *wdev = dev->ieee80211_ptr;
12747 bool ret;
12748
12749 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12750
12751 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12752 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12753 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12754 trace_cfg80211_return_bool(false);
12755 return false;
12756 }
12757 ret = __nl80211_unexpected_frame(dev,
12758 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12759 addr, gfp);
12760 trace_cfg80211_return_bool(ret);
12761 return ret;
12762}
12763EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012764
Johannes Berg2e161f72010-08-12 15:38:38 +020012765int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012766 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012767 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012768 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012769{
Johannes Berg71bbc992012-06-15 15:30:18 +020012770 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012771 struct sk_buff *msg;
12772 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012773
12774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12775 if (!msg)
12776 return -ENOMEM;
12777
Johannes Berg2e161f72010-08-12 15:38:38 +020012778 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012779 if (!hdr) {
12780 nlmsg_free(msg);
12781 return -ENOMEM;
12782 }
12783
David S. Miller9360ffd2012-03-29 04:41:26 -040012784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012785 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12786 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012787 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12788 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012789 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12790 (sig_dbm &&
12791 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012792 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12793 (flags &&
12794 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012795 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012796
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012797 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012798
Eric W. Biederman15e47302012-09-07 20:12:54 +000012799 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012800
12801 nla_put_failure:
12802 genlmsg_cancel(msg, hdr);
12803 nlmsg_free(msg);
12804 return -ENOBUFS;
12805}
12806
Johannes Berg947add32013-02-22 22:05:20 +010012807void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12808 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012809{
Johannes Berg947add32013-02-22 22:05:20 +010012810 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012811 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012812 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012813 struct sk_buff *msg;
12814 void *hdr;
12815
Johannes Berg947add32013-02-22 22:05:20 +010012816 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12817
Jouni Malinen026331c2010-02-15 12:53:10 +020012818 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12819 if (!msg)
12820 return;
12821
Johannes Berg2e161f72010-08-12 15:38:38 +020012822 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012823 if (!hdr) {
12824 nlmsg_free(msg);
12825 return;
12826 }
12827
David S. Miller9360ffd2012-03-29 04:41:26 -040012828 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012829 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12830 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012831 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12832 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012833 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012834 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12835 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012836 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12837 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012838
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012839 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012840
Johannes Berg68eb5502013-11-19 15:19:38 +010012841 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012842 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012843 return;
12844
12845 nla_put_failure:
12846 genlmsg_cancel(msg, hdr);
12847 nlmsg_free(msg);
12848}
Johannes Berg947add32013-02-22 22:05:20 +010012849EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012850
Johannes Berg5b97f492014-11-26 12:37:43 +010012851static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12852 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012853{
Johannes Berg947add32013-02-22 22:05:20 +010012854 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012855 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12856 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12857 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012858
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012859 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012860 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012861
Johannes Berg5b97f492014-11-26 12:37:43 +010012862 cb = (void **)msg->cb;
12863
12864 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12865 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012866 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012867 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012868 }
12869
David S. Miller9360ffd2012-03-29 04:41:26 -040012870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012871 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012872 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012873
Johannes Berg5b97f492014-11-26 12:37:43 +010012874 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012875 goto nla_put_failure;
12876
Johannes Berg5b97f492014-11-26 12:37:43 +010012877 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12878 if (!cb[1])
12879 goto nla_put_failure;
12880
12881 cb[2] = rdev;
12882
12883 return msg;
12884 nla_put_failure:
12885 nlmsg_free(msg);
12886 return NULL;
12887}
12888
12889static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12890{
12891 void **cb = (void **)msg->cb;
12892 struct cfg80211_registered_device *rdev = cb[2];
12893
12894 nla_nest_end(msg, cb[1]);
12895 genlmsg_end(msg, cb[0]);
12896
12897 memset(msg->cb, 0, sizeof(msg->cb));
12898
12899 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12900 NL80211_MCGRP_MLME, gfp);
12901}
12902
12903void cfg80211_cqm_rssi_notify(struct net_device *dev,
12904 enum nl80211_cqm_rssi_threshold_event rssi_event,
12905 gfp_t gfp)
12906{
12907 struct sk_buff *msg;
12908
12909 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12910
Johannes Berg98f03342014-11-26 12:42:02 +010012911 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12912 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12913 return;
12914
Johannes Berg5b97f492014-11-26 12:37:43 +010012915 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12916 if (!msg)
12917 return;
12918
David S. Miller9360ffd2012-03-29 04:41:26 -040012919 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12920 rssi_event))
12921 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012922
Johannes Berg5b97f492014-11-26 12:37:43 +010012923 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012924
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012925 return;
12926
12927 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012928 nlmsg_free(msg);
12929}
Johannes Berg947add32013-02-22 22:05:20 +010012930EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012931
Johannes Berg5b97f492014-11-26 12:37:43 +010012932void cfg80211_cqm_txe_notify(struct net_device *dev,
12933 const u8 *peer, u32 num_packets,
12934 u32 rate, u32 intvl, gfp_t gfp)
12935{
12936 struct sk_buff *msg;
12937
12938 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12939 if (!msg)
12940 return;
12941
12942 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12943 goto nla_put_failure;
12944
12945 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12946 goto nla_put_failure;
12947
12948 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12949 goto nla_put_failure;
12950
12951 cfg80211_send_cqm(msg, gfp);
12952 return;
12953
12954 nla_put_failure:
12955 nlmsg_free(msg);
12956}
12957EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12958
12959void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12960 const u8 *peer, u32 num_packets, gfp_t gfp)
12961{
12962 struct sk_buff *msg;
12963
12964 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12965
12966 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12967 if (!msg)
12968 return;
12969
12970 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12971 goto nla_put_failure;
12972
12973 cfg80211_send_cqm(msg, gfp);
12974 return;
12975
12976 nla_put_failure:
12977 nlmsg_free(msg);
12978}
12979EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12980
Johannes Berg98f03342014-11-26 12:42:02 +010012981void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12982{
12983 struct sk_buff *msg;
12984
12985 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12986 if (!msg)
12987 return;
12988
12989 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12990 goto nla_put_failure;
12991
12992 cfg80211_send_cqm(msg, gfp);
12993 return;
12994
12995 nla_put_failure:
12996 nlmsg_free(msg);
12997}
12998EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12999
Johannes Berg947add32013-02-22 22:05:20 +010013000static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13001 struct net_device *netdev, const u8 *bssid,
13002 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013003{
13004 struct sk_buff *msg;
13005 struct nlattr *rekey_attr;
13006 void *hdr;
13007
Thomas Graf58050fc2012-06-28 03:57:45 +000013008 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013009 if (!msg)
13010 return;
13011
13012 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13013 if (!hdr) {
13014 nlmsg_free(msg);
13015 return;
13016 }
13017
David S. Miller9360ffd2012-03-29 04:41:26 -040013018 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13019 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13020 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13021 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013022
13023 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13024 if (!rekey_attr)
13025 goto nla_put_failure;
13026
David S. Miller9360ffd2012-03-29 04:41:26 -040013027 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13028 NL80211_REPLAY_CTR_LEN, replay_ctr))
13029 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013030
13031 nla_nest_end(msg, rekey_attr);
13032
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013033 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013034
Johannes Berg68eb5502013-11-19 15:19:38 +010013035 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013036 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013037 return;
13038
13039 nla_put_failure:
13040 genlmsg_cancel(msg, hdr);
13041 nlmsg_free(msg);
13042}
13043
Johannes Berg947add32013-02-22 22:05:20 +010013044void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13045 const u8 *replay_ctr, gfp_t gfp)
13046{
13047 struct wireless_dev *wdev = dev->ieee80211_ptr;
13048 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013049 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013050
13051 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13052 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13053}
13054EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13055
13056static void
13057nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13058 struct net_device *netdev, int index,
13059 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013060{
13061 struct sk_buff *msg;
13062 struct nlattr *attr;
13063 void *hdr;
13064
Thomas Graf58050fc2012-06-28 03:57:45 +000013065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013066 if (!msg)
13067 return;
13068
13069 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13070 if (!hdr) {
13071 nlmsg_free(msg);
13072 return;
13073 }
13074
David S. Miller9360ffd2012-03-29 04:41:26 -040013075 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13076 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13077 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013078
13079 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13080 if (!attr)
13081 goto nla_put_failure;
13082
David S. Miller9360ffd2012-03-29 04:41:26 -040013083 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13084 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13085 (preauth &&
13086 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13087 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013088
13089 nla_nest_end(msg, attr);
13090
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013091 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013092
Johannes Berg68eb5502013-11-19 15:19:38 +010013093 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013094 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013095 return;
13096
13097 nla_put_failure:
13098 genlmsg_cancel(msg, hdr);
13099 nlmsg_free(msg);
13100}
13101
Johannes Berg947add32013-02-22 22:05:20 +010013102void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13103 const u8 *bssid, bool preauth, gfp_t gfp)
13104{
13105 struct wireless_dev *wdev = dev->ieee80211_ptr;
13106 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013107 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013108
13109 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13110 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13111}
13112EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13113
13114static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13115 struct net_device *netdev,
13116 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013117 gfp_t gfp,
13118 enum nl80211_commands notif,
13119 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013120{
13121 struct sk_buff *msg;
13122 void *hdr;
13123
Thomas Graf58050fc2012-06-28 03:57:45 +000013124 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013125 if (!msg)
13126 return;
13127
Luciano Coelhof8d75522014-11-07 14:31:35 +020013128 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013129 if (!hdr) {
13130 nlmsg_free(msg);
13131 return;
13132 }
13133
Johannes Berg683b6d32012-11-08 21:25:48 +010013134 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13135 goto nla_put_failure;
13136
13137 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013138 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013139
Luciano Coelhof8d75522014-11-07 14:31:35 +020013140 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13141 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13142 goto nla_put_failure;
13143
Thomas Pedersen53145262012-04-06 13:35:47 -070013144 genlmsg_end(msg, hdr);
13145
Johannes Berg68eb5502013-11-19 15:19:38 +010013146 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013147 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013148 return;
13149
13150 nla_put_failure:
13151 genlmsg_cancel(msg, hdr);
13152 nlmsg_free(msg);
13153}
13154
Johannes Berg947add32013-02-22 22:05:20 +010013155void cfg80211_ch_switch_notify(struct net_device *dev,
13156 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013157{
Johannes Berg947add32013-02-22 22:05:20 +010013158 struct wireless_dev *wdev = dev->ieee80211_ptr;
13159 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013161
Simon Wunderliche487eae2013-11-21 18:19:51 +010013162 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013163
Simon Wunderliche487eae2013-11-21 18:19:51 +010013164 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013165
Michal Kazior9e0e2962014-01-29 14:22:27 +010013166 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013167 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013168 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13169 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013170}
13171EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13172
Luciano Coelhof8d75522014-11-07 14:31:35 +020013173void cfg80211_ch_switch_started_notify(struct net_device *dev,
13174 struct cfg80211_chan_def *chandef,
13175 u8 count)
13176{
13177 struct wireless_dev *wdev = dev->ieee80211_ptr;
13178 struct wiphy *wiphy = wdev->wiphy;
13179 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13180
13181 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13182
13183 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13184 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13185}
13186EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13187
Thomas Pedersen84f10702012-07-12 16:17:33 -070013188void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013189nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013190 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013191 enum nl80211_radar_event event,
13192 struct net_device *netdev, gfp_t gfp)
13193{
13194 struct sk_buff *msg;
13195 void *hdr;
13196
13197 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13198 if (!msg)
13199 return;
13200
13201 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13202 if (!hdr) {
13203 nlmsg_free(msg);
13204 return;
13205 }
13206
13207 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13208 goto nla_put_failure;
13209
13210 /* NOP and radar events don't need a netdev parameter */
13211 if (netdev) {
13212 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13213
13214 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013215 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13216 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013217 goto nla_put_failure;
13218 }
13219
13220 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13221 goto nla_put_failure;
13222
13223 if (nl80211_send_chandef(msg, chandef))
13224 goto nla_put_failure;
13225
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013226 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013227
Johannes Berg68eb5502013-11-19 15:19:38 +010013228 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013229 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013230 return;
13231
13232 nla_put_failure:
13233 genlmsg_cancel(msg, hdr);
13234 nlmsg_free(msg);
13235}
13236
Johannes Berg7f6cf312011-11-04 11:18:15 +010013237void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13238 u64 cookie, bool acked, gfp_t gfp)
13239{
13240 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013241 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013242 struct sk_buff *msg;
13243 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013244
Beni Lev4ee3e062012-08-27 12:49:39 +030013245 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13246
Thomas Graf58050fc2012-06-28 03:57:45 +000013247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013248
Johannes Berg7f6cf312011-11-04 11:18:15 +010013249 if (!msg)
13250 return;
13251
13252 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13253 if (!hdr) {
13254 nlmsg_free(msg);
13255 return;
13256 }
13257
David S. Miller9360ffd2012-03-29 04:41:26 -040013258 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13259 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13260 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013261 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13262 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013263 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13264 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013265
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013266 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013267
Johannes Berg68eb5502013-11-19 15:19:38 +010013268 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013269 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013270 return;
13271
13272 nla_put_failure:
13273 genlmsg_cancel(msg, hdr);
13274 nlmsg_free(msg);
13275}
13276EXPORT_SYMBOL(cfg80211_probe_status);
13277
Johannes Berg5e7602302011-11-04 11:18:17 +010013278void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13279 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013280 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013281{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013283 struct sk_buff *msg;
13284 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013285 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013286
Beni Lev4ee3e062012-08-27 12:49:39 +030013287 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13288
Ben Greear37c73b52012-10-26 14:49:25 -070013289 spin_lock_bh(&rdev->beacon_registrations_lock);
13290 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13291 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13292 if (!msg) {
13293 spin_unlock_bh(&rdev->beacon_registrations_lock);
13294 return;
13295 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013296
Ben Greear37c73b52012-10-26 14:49:25 -070013297 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13298 if (!hdr)
13299 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013300
Ben Greear37c73b52012-10-26 14:49:25 -070013301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13302 (freq &&
13303 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13304 (sig_dbm &&
13305 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13306 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13307 goto nla_put_failure;
13308
13309 genlmsg_end(msg, hdr);
13310
13311 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013312 }
Ben Greear37c73b52012-10-26 14:49:25 -070013313 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013314 return;
13315
13316 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013317 spin_unlock_bh(&rdev->beacon_registrations_lock);
13318 if (hdr)
13319 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013320 nlmsg_free(msg);
13321}
13322EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13323
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013324#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013325static int cfg80211_net_detect_results(struct sk_buff *msg,
13326 struct cfg80211_wowlan_wakeup *wakeup)
13327{
13328 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13329 struct nlattr *nl_results, *nl_match, *nl_freqs;
13330 int i, j;
13331
13332 nl_results = nla_nest_start(
13333 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13334 if (!nl_results)
13335 return -EMSGSIZE;
13336
13337 for (i = 0; i < nd->n_matches; i++) {
13338 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13339
13340 nl_match = nla_nest_start(msg, i);
13341 if (!nl_match)
13342 break;
13343
13344 /* The SSID attribute is optional in nl80211, but for
13345 * simplicity reasons it's always present in the
13346 * cfg80211 structure. If a driver can't pass the
13347 * SSID, that needs to be changed. A zero length SSID
13348 * is still a valid SSID (wildcard), so it cannot be
13349 * used for this purpose.
13350 */
13351 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13352 match->ssid.ssid)) {
13353 nla_nest_cancel(msg, nl_match);
13354 goto out;
13355 }
13356
13357 if (match->n_channels) {
13358 nl_freqs = nla_nest_start(
13359 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13360 if (!nl_freqs) {
13361 nla_nest_cancel(msg, nl_match);
13362 goto out;
13363 }
13364
13365 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013366 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013367 nla_nest_cancel(msg, nl_freqs);
13368 nla_nest_cancel(msg, nl_match);
13369 goto out;
13370 }
13371 }
13372
13373 nla_nest_end(msg, nl_freqs);
13374 }
13375
13376 nla_nest_end(msg, nl_match);
13377 }
13378
13379out:
13380 nla_nest_end(msg, nl_results);
13381 return 0;
13382}
13383
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013384void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13385 struct cfg80211_wowlan_wakeup *wakeup,
13386 gfp_t gfp)
13387{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013388 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013389 struct sk_buff *msg;
13390 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013391 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013392
13393 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13394
13395 if (wakeup)
13396 size += wakeup->packet_present_len;
13397
13398 msg = nlmsg_new(size, gfp);
13399 if (!msg)
13400 return;
13401
13402 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13403 if (!hdr)
13404 goto free_msg;
13405
13406 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013407 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13408 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013409 goto free_msg;
13410
13411 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13412 wdev->netdev->ifindex))
13413 goto free_msg;
13414
13415 if (wakeup) {
13416 struct nlattr *reasons;
13417
13418 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013419 if (!reasons)
13420 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013421
13422 if (wakeup->disconnect &&
13423 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13424 goto free_msg;
13425 if (wakeup->magic_pkt &&
13426 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13427 goto free_msg;
13428 if (wakeup->gtk_rekey_failure &&
13429 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13430 goto free_msg;
13431 if (wakeup->eap_identity_req &&
13432 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13433 goto free_msg;
13434 if (wakeup->four_way_handshake &&
13435 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13436 goto free_msg;
13437 if (wakeup->rfkill_release &&
13438 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13439 goto free_msg;
13440
13441 if (wakeup->pattern_idx >= 0 &&
13442 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13443 wakeup->pattern_idx))
13444 goto free_msg;
13445
Johannes Bergae917c92013-10-25 11:05:22 +020013446 if (wakeup->tcp_match &&
13447 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13448 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013449
Johannes Bergae917c92013-10-25 11:05:22 +020013450 if (wakeup->tcp_connlost &&
13451 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13452 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013453
Johannes Bergae917c92013-10-25 11:05:22 +020013454 if (wakeup->tcp_nomoretokens &&
13455 nla_put_flag(msg,
13456 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13457 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013458
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013459 if (wakeup->packet) {
13460 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13461 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13462
13463 if (!wakeup->packet_80211) {
13464 pkt_attr =
13465 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13466 len_attr =
13467 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13468 }
13469
13470 if (wakeup->packet_len &&
13471 nla_put_u32(msg, len_attr, wakeup->packet_len))
13472 goto free_msg;
13473
13474 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13475 wakeup->packet))
13476 goto free_msg;
13477 }
13478
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013479 if (wakeup->net_detect &&
13480 cfg80211_net_detect_results(msg, wakeup))
13481 goto free_msg;
13482
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013483 nla_nest_end(msg, reasons);
13484 }
13485
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013486 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013487
Johannes Berg68eb5502013-11-19 15:19:38 +010013488 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013489 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013490 return;
13491
13492 free_msg:
13493 nlmsg_free(msg);
13494}
13495EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13496#endif
13497
Jouni Malinen3475b092012-11-16 22:49:57 +020013498void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13499 enum nl80211_tdls_operation oper,
13500 u16 reason_code, gfp_t gfp)
13501{
13502 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013503 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013504 struct sk_buff *msg;
13505 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013506
13507 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13508 reason_code);
13509
13510 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13511 if (!msg)
13512 return;
13513
13514 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13515 if (!hdr) {
13516 nlmsg_free(msg);
13517 return;
13518 }
13519
13520 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13521 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13522 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13523 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13524 (reason_code > 0 &&
13525 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13526 goto nla_put_failure;
13527
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013528 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013529
Johannes Berg68eb5502013-11-19 15:19:38 +010013530 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013531 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013532 return;
13533
13534 nla_put_failure:
13535 genlmsg_cancel(msg, hdr);
13536 nlmsg_free(msg);
13537}
13538EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13539
Jouni Malinen026331c2010-02-15 12:53:10 +020013540static int nl80211_netlink_notify(struct notifier_block * nb,
13541 unsigned long state,
13542 void *_notify)
13543{
13544 struct netlink_notify *notify = _notify;
13545 struct cfg80211_registered_device *rdev;
13546 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013547 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013548
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013549 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013550 return NOTIFY_DONE;
13551
13552 rcu_read_lock();
13553
Johannes Berg5e7602302011-11-04 11:18:17 +010013554 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013555 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013556 bool schedule_scan_stop = false;
13557 struct cfg80211_sched_scan_request *sched_scan_req =
13558 rcu_dereference(rdev->sched_scan_req);
13559
13560 if (sched_scan_req && notify->portid &&
13561 sched_scan_req->owner_nlportid == notify->portid)
13562 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013563
Johannes Berg53873f12016-05-03 16:52:04 +030013564 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013565 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013566
Johannes Berg78f22b62014-03-24 17:57:27 +010013567 if (wdev->owner_nlportid == notify->portid)
13568 schedule_destroy_work = true;
13569 }
13570
Ben Greear37c73b52012-10-26 14:49:25 -070013571 spin_lock_bh(&rdev->beacon_registrations_lock);
13572 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13573 list) {
13574 if (reg->nlportid == notify->portid) {
13575 list_del(&reg->list);
13576 kfree(reg);
13577 break;
13578 }
13579 }
13580 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013581
13582 if (schedule_destroy_work) {
13583 struct cfg80211_iface_destroy *destroy;
13584
13585 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13586 if (destroy) {
13587 destroy->nlportid = notify->portid;
13588 spin_lock(&rdev->destroy_list_lock);
13589 list_add(&destroy->list, &rdev->destroy_list);
13590 spin_unlock(&rdev->destroy_list_lock);
13591 schedule_work(&rdev->destroy_work);
13592 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013593 } else if (schedule_scan_stop) {
13594 sched_scan_req->owner_nlportid = 0;
13595
13596 if (rdev->ops->sched_scan_stop &&
13597 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13598 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013599 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013600 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013601
13602 rcu_read_unlock();
13603
Ilan peer05050752015-03-04 00:32:06 -050013604 /*
13605 * It is possible that the user space process that is controlling the
13606 * indoor setting disappeared, so notify the regulatory core.
13607 */
13608 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013609 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013610}
13611
13612static struct notifier_block nl80211_netlink_notifier = {
13613 .notifier_call = nl80211_netlink_notify,
13614};
13615
Jouni Malinen355199e2013-02-27 17:14:27 +020013616void cfg80211_ft_event(struct net_device *netdev,
13617 struct cfg80211_ft_event_params *ft_event)
13618{
13619 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013620 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013621 struct sk_buff *msg;
13622 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013623
13624 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13625
13626 if (!ft_event->target_ap)
13627 return;
13628
13629 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13630 if (!msg)
13631 return;
13632
13633 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013634 if (!hdr)
13635 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013636
Johannes Bergae917c92013-10-25 11:05:22 +020013637 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13638 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13639 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13640 goto out;
13641
13642 if (ft_event->ies &&
13643 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13644 goto out;
13645 if (ft_event->ric_ies &&
13646 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13647 ft_event->ric_ies))
13648 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013649
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013650 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013651
Johannes Berg68eb5502013-11-19 15:19:38 +010013652 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013653 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013654 return;
13655 out:
13656 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013657}
13658EXPORT_SYMBOL(cfg80211_ft_event);
13659
Arend van Spriel5de17982013-04-18 15:49:00 +020013660void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13661{
13662 struct cfg80211_registered_device *rdev;
13663 struct sk_buff *msg;
13664 void *hdr;
13665 u32 nlportid;
13666
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013667 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013668 if (!rdev->crit_proto_nlportid)
13669 return;
13670
13671 nlportid = rdev->crit_proto_nlportid;
13672 rdev->crit_proto_nlportid = 0;
13673
13674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13675 if (!msg)
13676 return;
13677
13678 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13679 if (!hdr)
13680 goto nla_put_failure;
13681
13682 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013683 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13684 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013685 goto nla_put_failure;
13686
13687 genlmsg_end(msg, hdr);
13688
13689 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13690 return;
13691
13692 nla_put_failure:
13693 if (hdr)
13694 genlmsg_cancel(msg, hdr);
13695 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020013696}
13697EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13698
Johannes Berg348baf02014-01-24 14:06:29 +010013699void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13700{
13701 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013702 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013703 struct sk_buff *msg;
13704 void *hdr;
13705
13706 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13707 if (!msg)
13708 return;
13709
13710 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13711 if (!hdr)
13712 goto out;
13713
13714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013716 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13717 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013718 goto out;
13719
13720 genlmsg_end(msg, hdr);
13721
13722 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13723 NL80211_MCGRP_MLME, GFP_KERNEL);
13724 return;
13725 out:
13726 nlmsg_free(msg);
13727}
13728
Johannes Berg55682962007-09-20 13:09:35 -040013729/* initialisation/exit functions */
13730
13731int nl80211_init(void)
13732{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013733 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013734
Johannes Berg2a94fe42013-11-19 15:19:39 +010013735 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13736 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013737 if (err)
13738 return err;
13739
Jouni Malinen026331c2010-02-15 12:53:10 +020013740 err = netlink_register_notifier(&nl80211_netlink_notifier);
13741 if (err)
13742 goto err_out;
13743
Johannes Berg55682962007-09-20 13:09:35 -040013744 return 0;
13745 err_out:
13746 genl_unregister_family(&nl80211_fam);
13747 return err;
13748}
13749
13750void nl80211_exit(void)
13751{
Jouni Malinen026331c2010-02-15 12:53:10 +020013752 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013753 genl_unregister_family(&nl80211_fam);
13754}