blob: 244d552d5647d1c4d34a8661f4974fb7c1a77fe6 [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 },
Johannes Berg55682962007-09-20 13:09:35 -0400408};
409
Johannes Berge31b8212010-10-05 19:39:30 +0200410/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000411static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200412 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200413 [NL80211_KEY_IDX] = { .type = NLA_U8 },
414 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200415 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200416 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
417 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200418 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100419 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
420};
421
422/* policy for the key default flags */
423static const struct nla_policy
424nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
425 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
426 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200427};
428
Johannes Bergff1b6e62011-05-04 15:37:28 +0200429/* policy for WoWLAN attributes */
430static const struct nla_policy
431nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
432 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
435 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200436 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
437 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
439 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100440 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300441 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100442};
443
444static const struct nla_policy
445nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
446 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
447 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
448 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
449 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
450 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
451 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
452 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
453 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
454 },
455 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
456 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
457 },
458 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
459 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
460 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200461};
462
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700463/* policy for coalesce rule attributes */
464static const struct nla_policy
465nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
466 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
467 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
468 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
469};
470
Johannes Berge5497d72011-07-05 16:35:40 +0200471/* policy for GTK rekey offload attributes */
472static const struct nla_policy
473nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
474 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
475 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
476 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
477};
478
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300479static const struct nla_policy
480nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200481 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300482 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700483 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300484};
485
Avraham Stern3b06d272015-10-12 09:51:34 +0300486static const struct nla_policy
487nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
488 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
489 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
490};
491
Arend van Spriel38de03d2016-03-02 20:37:18 +0100492static const struct nla_policy
493nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
494 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
495 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
496 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
497 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
498 },
499};
500
Johannes Berg97990a02013-04-19 01:02:55 +0200501static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
502 struct netlink_callback *cb,
503 struct cfg80211_registered_device **rdev,
504 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100505{
Johannes Berg67748892010-10-04 21:14:06 +0200506 int err;
507
Johannes Berg67748892010-10-04 21:14:06 +0200508 rtnl_lock();
509
Johannes Berg97990a02013-04-19 01:02:55 +0200510 if (!cb->args[0]) {
511 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
512 nl80211_fam.attrbuf, nl80211_fam.maxattr,
513 nl80211_policy);
514 if (err)
515 goto out_unlock;
516
517 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
518 nl80211_fam.attrbuf);
519 if (IS_ERR(*wdev)) {
520 err = PTR_ERR(*wdev);
521 goto out_unlock;
522 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800523 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200524 /* 0 is the first index - add 1 to parse only once */
525 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200526 cb->args[1] = (*wdev)->identifier;
527 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200528 /* subtract the 1 again here */
529 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200530 struct wireless_dev *tmp;
531
532 if (!wiphy) {
533 err = -ENODEV;
534 goto out_unlock;
535 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800536 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200537 *wdev = NULL;
538
Johannes Berg53873f12016-05-03 16:52:04 +0300539 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200540 if (tmp->identifier == cb->args[1]) {
541 *wdev = tmp;
542 break;
543 }
544 }
Johannes Berg97990a02013-04-19 01:02:55 +0200545
546 if (!*wdev) {
547 err = -ENODEV;
548 goto out_unlock;
549 }
Johannes Berg67748892010-10-04 21:14:06 +0200550 }
551
Johannes Berg67748892010-10-04 21:14:06 +0200552 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200553 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200554 rtnl_unlock();
555 return err;
556}
557
Johannes Berg97990a02013-04-19 01:02:55 +0200558static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200559{
Johannes Berg67748892010-10-04 21:14:06 +0200560 rtnl_unlock();
561}
562
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100563/* IE validation */
564static bool is_valid_ie_attr(const struct nlattr *attr)
565{
566 const u8 *pos;
567 int len;
568
569 if (!attr)
570 return true;
571
572 pos = nla_data(attr);
573 len = nla_len(attr);
574
575 while (len) {
576 u8 elemlen;
577
578 if (len < 2)
579 return false;
580 len -= 2;
581
582 elemlen = pos[1];
583 if (elemlen > len)
584 return false;
585
586 len -= elemlen;
587 pos += 2 + elemlen;
588 }
589
590 return true;
591}
592
Johannes Berg55682962007-09-20 13:09:35 -0400593/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000594static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400595 int flags, u8 cmd)
596{
597 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000598 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400599}
600
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400601static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100602 struct ieee80211_channel *chan,
603 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400604{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200605 /* Some channels must be completely excluded from the
606 * list to protect old user-space tools from breaking
607 */
608 if (!large && chan->flags &
609 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
610 return 0;
611
David S. Miller9360ffd2012-03-29 04:41:26 -0400612 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
613 chan->center_freq))
614 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400615
David S. Miller9360ffd2012-03-29 04:41:26 -0400616 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
617 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
618 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200619 if (chan->flags & IEEE80211_CHAN_NO_IR) {
620 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
621 goto nla_put_failure;
622 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
623 goto nla_put_failure;
624 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100625 if (chan->flags & IEEE80211_CHAN_RADAR) {
626 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
627 goto nla_put_failure;
628 if (large) {
629 u32 time;
630
631 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
632
633 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
634 chan->dfs_state))
635 goto nla_put_failure;
636 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
637 time))
638 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100639 if (nla_put_u32(msg,
640 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
641 chan->dfs_cac_ms))
642 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100643 }
644 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400645
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100646 if (large) {
647 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
648 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
649 goto nla_put_failure;
650 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
651 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
652 goto nla_put_failure;
653 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
654 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
655 goto nla_put_failure;
656 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
657 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
658 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200659 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
660 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
661 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300662 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
663 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200664 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200665 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
666 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
667 goto nla_put_failure;
668 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
669 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
670 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100671 }
672
David S. Miller9360ffd2012-03-29 04:41:26 -0400673 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
674 DBM_TO_MBM(chan->max_power)))
675 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400676
677 return 0;
678
679 nla_put_failure:
680 return -ENOBUFS;
681}
682
Johannes Berg55682962007-09-20 13:09:35 -0400683/* netlink command implementations */
684
Johannes Bergb9454e82009-07-08 13:29:08 +0200685struct key_parse {
686 struct key_params p;
687 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200688 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200689 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100690 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200691};
692
693static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
694{
695 struct nlattr *tb[NL80211_KEY_MAX + 1];
696 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
697 nl80211_key_policy);
698 if (err)
699 return err;
700
701 k->def = !!tb[NL80211_KEY_DEFAULT];
702 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
703
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100704 if (k->def) {
705 k->def_uni = true;
706 k->def_multi = true;
707 }
708 if (k->defmgmt)
709 k->def_multi = true;
710
Johannes Bergb9454e82009-07-08 13:29:08 +0200711 if (tb[NL80211_KEY_IDX])
712 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
713
714 if (tb[NL80211_KEY_DATA]) {
715 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
716 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
717 }
718
719 if (tb[NL80211_KEY_SEQ]) {
720 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
721 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
722 }
723
724 if (tb[NL80211_KEY_CIPHER])
725 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
726
Johannes Berge31b8212010-10-05 19:39:30 +0200727 if (tb[NL80211_KEY_TYPE]) {
728 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
729 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
730 return -EINVAL;
731 }
732
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100733 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
734 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700735
Johannes Berg2da8f412012-01-20 13:52:37 +0100736 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
737 tb[NL80211_KEY_DEFAULT_TYPES],
738 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100739 if (err)
740 return err;
741
742 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
743 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
744 }
745
Johannes Bergb9454e82009-07-08 13:29:08 +0200746 return 0;
747}
748
749static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
750{
751 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
752 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
753 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
754 }
755
756 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
757 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
758 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
759 }
760
761 if (info->attrs[NL80211_ATTR_KEY_IDX])
762 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
763
764 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
765 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
766
767 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
768 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
769
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100770 if (k->def) {
771 k->def_uni = true;
772 k->def_multi = true;
773 }
774 if (k->defmgmt)
775 k->def_multi = true;
776
Johannes Berge31b8212010-10-05 19:39:30 +0200777 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
778 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
779 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
780 return -EINVAL;
781 }
782
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100783 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
784 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
785 int err = nla_parse_nested(
786 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
787 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
788 nl80211_key_default_policy);
789 if (err)
790 return err;
791
792 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
793 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
794 }
795
Johannes Bergb9454e82009-07-08 13:29:08 +0200796 return 0;
797}
798
799static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
800{
801 int err;
802
803 memset(k, 0, sizeof(*k));
804 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200805 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200806
807 if (info->attrs[NL80211_ATTR_KEY])
808 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
809 else
810 err = nl80211_parse_key_old(info, k);
811
812 if (err)
813 return err;
814
815 if (k->def && k->defmgmt)
816 return -EINVAL;
817
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100818 if (k->defmgmt) {
819 if (k->def_uni || !k->def_multi)
820 return -EINVAL;
821 }
822
Johannes Bergb9454e82009-07-08 13:29:08 +0200823 if (k->idx != -1) {
824 if (k->defmgmt) {
825 if (k->idx < 4 || k->idx > 5)
826 return -EINVAL;
827 } else if (k->def) {
828 if (k->idx < 0 || k->idx > 3)
829 return -EINVAL;
830 } else {
831 if (k->idx < 0 || k->idx > 5)
832 return -EINVAL;
833 }
834 }
835
836 return 0;
837}
838
Johannes Bergfffd0932009-07-08 14:22:54 +0200839static struct cfg80211_cached_keys *
840nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530841 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200842{
843 struct key_parse parse;
844 struct nlattr *key;
845 struct cfg80211_cached_keys *result;
846 int rem, err, def = 0;
847
848 result = kzalloc(sizeof(*result), GFP_KERNEL);
849 if (!result)
850 return ERR_PTR(-ENOMEM);
851
852 result->def = -1;
853 result->defmgmt = -1;
854
855 nla_for_each_nested(key, keys, rem) {
856 memset(&parse, 0, sizeof(parse));
857 parse.idx = -1;
858
859 err = nl80211_parse_key_new(key, &parse);
860 if (err)
861 goto error;
862 err = -EINVAL;
863 if (!parse.p.key)
864 goto error;
865 if (parse.idx < 0 || parse.idx > 4)
866 goto error;
867 if (parse.def) {
868 if (def)
869 goto error;
870 def = 1;
871 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100872 if (!parse.def_uni || !parse.def_multi)
873 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200874 } else if (parse.defmgmt)
875 goto error;
876 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200877 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 if (err)
879 goto error;
880 result->params[parse.idx].cipher = parse.p.cipher;
881 result->params[parse.idx].key_len = parse.p.key_len;
882 result->params[parse.idx].key = result->data[parse.idx];
883 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530884
885 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
886 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
887 if (no_ht)
888 *no_ht = true;
889 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200890 }
891
892 return result;
893 error:
894 kfree(result);
895 return ERR_PTR(err);
896}
897
898static int nl80211_key_allowed(struct wireless_dev *wdev)
899{
900 ASSERT_WDEV_LOCK(wdev);
901
Johannes Bergfffd0932009-07-08 14:22:54 +0200902 switch (wdev->iftype) {
903 case NL80211_IFTYPE_AP:
904 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200905 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700906 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200907 break;
908 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200909 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200910 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200911 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200912 return -ENOLINK;
913 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100914 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100915 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100916 case NL80211_IFTYPE_MONITOR:
917 case NL80211_IFTYPE_P2P_DEVICE:
918 case NL80211_IFTYPE_WDS:
919 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200920 return -EINVAL;
921 }
922
923 return 0;
924}
925
Jouni Malinen664834d2014-01-15 00:01:44 +0200926static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
927 struct nlattr *tb)
928{
929 struct ieee80211_channel *chan;
930
931 if (tb == NULL)
932 return NULL;
933 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
934 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
935 return NULL;
936 return chan;
937}
938
Johannes Berg7527a782011-05-13 10:58:57 +0200939static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
940{
941 struct nlattr *nl_modes = nla_nest_start(msg, attr);
942 int i;
943
944 if (!nl_modes)
945 goto nla_put_failure;
946
947 i = 0;
948 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400949 if ((ifmodes & 1) && nla_put_flag(msg, i))
950 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200951 ifmodes >>= 1;
952 i++;
953 }
954
955 nla_nest_end(msg, nl_modes);
956 return 0;
957
958nla_put_failure:
959 return -ENOBUFS;
960}
961
962static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100963 struct sk_buff *msg,
964 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200965{
966 struct nlattr *nl_combis;
967 int i, j;
968
969 nl_combis = nla_nest_start(msg,
970 NL80211_ATTR_INTERFACE_COMBINATIONS);
971 if (!nl_combis)
972 goto nla_put_failure;
973
974 for (i = 0; i < wiphy->n_iface_combinations; i++) {
975 const struct ieee80211_iface_combination *c;
976 struct nlattr *nl_combi, *nl_limits;
977
978 c = &wiphy->iface_combinations[i];
979
980 nl_combi = nla_nest_start(msg, i + 1);
981 if (!nl_combi)
982 goto nla_put_failure;
983
984 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
985 if (!nl_limits)
986 goto nla_put_failure;
987
988 for (j = 0; j < c->n_limits; j++) {
989 struct nlattr *nl_limit;
990
991 nl_limit = nla_nest_start(msg, j + 1);
992 if (!nl_limit)
993 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400994 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
995 c->limits[j].max))
996 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200997 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
998 c->limits[j].types))
999 goto nla_put_failure;
1000 nla_nest_end(msg, nl_limit);
1001 }
1002
1003 nla_nest_end(msg, nl_limits);
1004
David S. Miller9360ffd2012-03-29 04:41:26 -04001005 if (c->beacon_int_infra_match &&
1006 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1007 goto nla_put_failure;
1008 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1009 c->num_different_channels) ||
1010 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1011 c->max_interfaces))
1012 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001013 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001014 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1015 c->radar_detect_widths) ||
1016 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1017 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001018 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001019
1020 nla_nest_end(msg, nl_combi);
1021 }
1022
1023 nla_nest_end(msg, nl_combis);
1024
1025 return 0;
1026nla_put_failure:
1027 return -ENOBUFS;
1028}
1029
Johannes Berg3713b4e2013-02-14 16:19:38 +01001030#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001031static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1032 struct sk_buff *msg)
1033{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001034 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001035 struct nlattr *nl_tcp;
1036
1037 if (!tcp)
1038 return 0;
1039
1040 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1041 if (!nl_tcp)
1042 return -ENOBUFS;
1043
1044 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1045 tcp->data_payload_max))
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 (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1053 return -ENOBUFS;
1054
1055 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1056 sizeof(*tcp->tok), tcp->tok))
1057 return -ENOBUFS;
1058
1059 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1060 tcp->data_interval_max))
1061 return -ENOBUFS;
1062
1063 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1064 tcp->wake_payload_max))
1065 return -ENOBUFS;
1066
1067 nla_nest_end(msg, nl_tcp);
1068 return 0;
1069}
1070
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001073 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074{
1075 struct nlattr *nl_wowlan;
1076
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078 return 0;
1079
1080 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1081 if (!nl_wowlan)
1082 return -ENOBUFS;
1083
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001084 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001085 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001098 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001099 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1100 return -ENOBUFS;
1101
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001103 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001104 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1105 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1106 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1107 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001108 };
1109
1110 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1111 sizeof(pat), &pat))
1112 return -ENOBUFS;
1113 }
1114
Luciano Coelho75453cc2015-01-09 14:06:37 +02001115 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1116 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1117 rdev->wiphy.wowlan->max_nd_match_sets))
1118 return -ENOBUFS;
1119
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001120 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001121 return -ENOBUFS;
1122
Johannes Berg3713b4e2013-02-14 16:19:38 +01001123 nla_nest_end(msg, nl_wowlan);
1124
1125 return 0;
1126}
1127#endif
1128
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001129static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001130 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001131{
1132 struct nl80211_coalesce_rule_support rule;
1133
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001135 return 0;
1136
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001137 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1138 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1139 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1140 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1141 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1142 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001143
1144 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1145 return -ENOBUFS;
1146
1147 return 0;
1148}
1149
Johannes Berg3713b4e2013-02-14 16:19:38 +01001150static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1151 struct ieee80211_supported_band *sband)
1152{
1153 struct nlattr *nl_rates, *nl_rate;
1154 struct ieee80211_rate *rate;
1155 int i;
1156
1157 /* add HT info */
1158 if (sband->ht_cap.ht_supported &&
1159 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1160 sizeof(sband->ht_cap.mcs),
1161 &sband->ht_cap.mcs) ||
1162 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1163 sband->ht_cap.cap) ||
1164 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1165 sband->ht_cap.ampdu_factor) ||
1166 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1167 sband->ht_cap.ampdu_density)))
1168 return -ENOBUFS;
1169
1170 /* add VHT info */
1171 if (sband->vht_cap.vht_supported &&
1172 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1173 sizeof(sband->vht_cap.vht_mcs),
1174 &sband->vht_cap.vht_mcs) ||
1175 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1176 sband->vht_cap.cap)))
1177 return -ENOBUFS;
1178
1179 /* add bitrates */
1180 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1181 if (!nl_rates)
1182 return -ENOBUFS;
1183
1184 for (i = 0; i < sband->n_bitrates; i++) {
1185 nl_rate = nla_nest_start(msg, i);
1186 if (!nl_rate)
1187 return -ENOBUFS;
1188
1189 rate = &sband->bitrates[i];
1190 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1191 rate->bitrate))
1192 return -ENOBUFS;
1193 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1194 nla_put_flag(msg,
1195 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1196 return -ENOBUFS;
1197
1198 nla_nest_end(msg, nl_rate);
1199 }
1200
1201 nla_nest_end(msg, nl_rates);
1202
1203 return 0;
1204}
1205
1206static int
1207nl80211_send_mgmt_stypes(struct sk_buff *msg,
1208 const struct ieee80211_txrx_stypes *mgmt_stypes)
1209{
1210 u16 stypes;
1211 struct nlattr *nl_ftypes, *nl_ifs;
1212 enum nl80211_iftype ift;
1213 int i;
1214
1215 if (!mgmt_stypes)
1216 return 0;
1217
1218 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1219 if (!nl_ifs)
1220 return -ENOBUFS;
1221
1222 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1223 nl_ftypes = nla_nest_start(msg, ift);
1224 if (!nl_ftypes)
1225 return -ENOBUFS;
1226 i = 0;
1227 stypes = mgmt_stypes[ift].tx;
1228 while (stypes) {
1229 if ((stypes & 1) &&
1230 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1231 (i << 4) | IEEE80211_FTYPE_MGMT))
1232 return -ENOBUFS;
1233 stypes >>= 1;
1234 i++;
1235 }
1236 nla_nest_end(msg, nl_ftypes);
1237 }
1238
1239 nla_nest_end(msg, nl_ifs);
1240
1241 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1242 if (!nl_ifs)
1243 return -ENOBUFS;
1244
1245 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1246 nl_ftypes = nla_nest_start(msg, ift);
1247 if (!nl_ftypes)
1248 return -ENOBUFS;
1249 i = 0;
1250 stypes = mgmt_stypes[ift].rx;
1251 while (stypes) {
1252 if ((stypes & 1) &&
1253 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1254 (i << 4) | IEEE80211_FTYPE_MGMT))
1255 return -ENOBUFS;
1256 stypes >>= 1;
1257 i++;
1258 }
1259 nla_nest_end(msg, nl_ftypes);
1260 }
1261 nla_nest_end(msg, nl_ifs);
1262
1263 return 0;
1264}
1265
Johannes Berg86e8cf92013-06-19 10:57:22 +02001266struct nl80211_dump_wiphy_state {
1267 s64 filter_wiphy;
1268 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301269 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001270 bool split;
1271};
1272
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001274 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001276 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001277{
1278 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001279 struct nlattr *nl_bands, *nl_band;
1280 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001281 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001282 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001283 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001284 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001285 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001287 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001288
Johannes Berg3bb20552014-05-26 13:52:25 +02001289 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001290 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 return -ENOBUFS;
1292
Johannes Berg86e8cf92013-06-19 10:57:22 +02001293 if (WARN_ON(!state))
1294 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001295
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001299 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001301 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001302
Johannes Berg3bb20552014-05-26 13:52:25 +02001303 if (cmd != NL80211_CMD_NEW_WIPHY)
1304 goto finish;
1305
Johannes Berg86e8cf92013-06-19 10:57:22 +02001306 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001307 case 0:
1308 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001327 rdev->wiphy.max_match_sets) ||
1328 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1329 rdev->wiphy.max_sched_scan_plans) ||
1330 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1331 rdev->wiphy.max_sched_scan_plan_interval) ||
1332 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1333 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001334 goto nla_put_failure;
1335
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001336 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1338 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1341 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001342 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1344 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1347 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001348 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001349 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1350 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001351 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001352 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001353 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 state->split_start++;
1355 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001356 break;
1357 case 1:
1358 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001359 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1360 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001361 goto nla_put_failure;
1362
Johannes Berg3713b4e2013-02-14 16:19:38 +01001363 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001364 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001365 goto nla_put_failure;
1366
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001367 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1369 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001370
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001372 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001374 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001376
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001377 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001379 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001380 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001381
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001382 if ((rdev->wiphy.available_antennas_tx ||
1383 rdev->wiphy.available_antennas_rx) &&
1384 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385 u32 tx_ant = 0, rx_ant = 0;
1386 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001387
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001388 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 if (!res) {
1390 if (nla_put_u32(msg,
1391 NL80211_ATTR_WIPHY_ANTENNA_TX,
1392 tx_ant) ||
1393 nla_put_u32(msg,
1394 NL80211_ATTR_WIPHY_ANTENNA_RX,
1395 rx_ant))
1396 goto nla_put_failure;
1397 }
Johannes Bergee688b002008-01-24 19:38:39 +01001398 }
1399
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 state->split_start++;
1401 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001402 break;
1403 case 2:
1404 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001405 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001407 state->split_start++;
1408 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001409 break;
1410 case 3:
1411 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1412 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001413 goto nla_put_failure;
1414
Johannes Berg86e8cf92013-06-19 10:57:22 +02001415 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001416 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417 struct ieee80211_supported_band *sband;
1418
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001419 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420
1421 if (!sband)
1422 continue;
1423
1424 nl_band = nla_nest_start(msg, band);
1425 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001426 goto nla_put_failure;
1427
Johannes Berg86e8cf92013-06-19 10:57:22 +02001428 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 case 0:
1430 if (nl80211_send_band_rateinfo(msg, sband))
1431 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 state->chan_start++;
1433 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 break;
1435 default:
1436 /* add frequencies */
1437 nl_freqs = nla_nest_start(
1438 msg, NL80211_BAND_ATTR_FREQS);
1439 if (!nl_freqs)
1440 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001441
Johannes Berg86e8cf92013-06-19 10:57:22 +02001442 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 i < sband->n_channels;
1444 i++) {
1445 nl_freq = nla_nest_start(msg, i);
1446 if (!nl_freq)
1447 goto nla_put_failure;
1448
1449 chan = &sband->channels[i];
1450
Johannes Berg86e8cf92013-06-19 10:57:22 +02001451 if (nl80211_msg_put_channel(
1452 msg, chan,
1453 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 goto nla_put_failure;
1455
1456 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001457 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 break;
1459 }
1460 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001461 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001463 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 nla_nest_end(msg, nl_freqs);
1465 }
1466
1467 nla_nest_end(msg, nl_band);
1468
Johannes Berg86e8cf92013-06-19 10:57:22 +02001469 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001471 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 band--;
1473 break;
1474 }
Johannes Bergee688b002008-01-24 19:38:39 +01001475 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001477
Johannes Berg57fbcce2016-04-12 15:56:15 +02001478 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001479 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001482
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001484 if (state->band_start == 0 && state->chan_start == 0)
1485 state->split_start++;
1486 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 break;
1488 case 4:
1489 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1490 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001491 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492
1493 i = 0;
1494#define CMD(op, n) \
1495 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 i++; \
1498 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1499 goto nla_put_failure; \
1500 } \
1501 } while (0)
1502
1503 CMD(add_virtual_intf, NEW_INTERFACE);
1504 CMD(change_virtual_intf, SET_INTERFACE);
1505 CMD(add_key, NEW_KEY);
1506 CMD(start_ap, START_AP);
1507 CMD(add_station, NEW_STATION);
1508 CMD(add_mpath, NEW_MPATH);
1509 CMD(update_mesh_config, SET_MESH_CONFIG);
1510 CMD(change_bss, SET_BSS);
1511 CMD(auth, AUTHENTICATE);
1512 CMD(assoc, ASSOCIATE);
1513 CMD(deauth, DEAUTHENTICATE);
1514 CMD(disassoc, DISASSOCIATE);
1515 CMD(join_ibss, JOIN_IBSS);
1516 CMD(join_mesh, JOIN_MESH);
1517 CMD(set_pmksa, SET_PMKSA);
1518 CMD(del_pmksa, DEL_PMKSA);
1519 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001520 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1522 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1523 CMD(mgmt_tx, FRAME);
1524 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001525 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 i++;
1527 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1528 goto nla_put_failure;
1529 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1531 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 i++;
1533 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1534 goto nla_put_failure;
1535 }
1536 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001537 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538 CMD(tdls_mgmt, TDLS_MGMT);
1539 CMD(tdls_oper, TDLS_OPER);
1540 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 CMD(sched_scan_start, START_SCHED_SCAN);
1543 CMD(probe_client, PROBE_CLIENT);
1544 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 i++;
1547 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1548 goto nla_put_failure;
1549 }
1550 CMD(start_p2p_device, START_P2P_DEVICE);
1551 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001552#ifdef CONFIG_NL80211_TESTMODE
1553 CMD(testmode_cmd, TESTMODE);
1554#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001555 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001556 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1557 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001558 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001559 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001560 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001561 if (rdev->wiphy.features &
1562 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001563 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001564 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001565 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001566#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001567
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001568 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 i++;
1570 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001571 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001572 }
1573
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001574 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575 i++;
1576 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1577 goto nla_put_failure;
1578 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001579
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 state->split_start++;
1582 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 break;
1584 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 if (rdev->ops->remain_on_channel &&
1586 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 nla_put_u32(msg,
1588 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001590 goto nla_put_failure;
1591
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001592 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1594 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001595
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1597 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001598 state->split_start++;
1599 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 break;
1601 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001602#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001603 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001605 state->split_start++;
1606 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607 break;
1608#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610#endif
1611 case 7:
1612 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001614 goto nla_put_failure;
1615
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001616 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001619
Johannes Berg86e8cf92013-06-19 10:57:22 +02001620 state->split_start++;
1621 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 break;
1623 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001624 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001625 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 goto nla_put_failure;
1628
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001629 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001630 /*
1631 * We can only add the per-channel limit information if the
1632 * dump is split, otherwise it makes it too big. Therefore
1633 * only advertise it in that case.
1634 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001635 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001636 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1637 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 goto nla_put_failure;
1639
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1643 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001644 goto nla_put_failure;
1645
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1647 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001650 goto nla_put_failure;
1651
1652 /*
1653 * Any information below this point is only available to
1654 * applications that can deal with it being split. This
1655 * helps ensure that newly added capabilities don't break
1656 * older tools by overrunning their buffers.
1657 *
1658 * We still increment split_start so that in the split
1659 * case we'll continue with more data in the next round,
1660 * but break unconditionally so unsplit data stops here.
1661 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001662 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001663 break;
1664 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001666 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001667 rdev->wiphy.extended_capabilities_len,
1668 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001669 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001670 rdev->wiphy.extended_capabilities_len,
1671 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001672 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001673
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001675 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001676 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1677 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001678 goto nla_put_failure;
1679
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001680 state->split_start++;
1681 break;
1682 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001683 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001684 goto nla_put_failure;
1685
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001686 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001687 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1688 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1689 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001690
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001691 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001692 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001693 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001694 goto nla_put_failure;
1695
Johannes Bergad7e7182013-11-13 13:37:47 +01001696 state->split_start++;
1697 break;
1698 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001699 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001700 const struct nl80211_vendor_cmd_info *info;
1701 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001702
Johannes Berg567ffc32013-12-18 14:43:31 +01001703 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1704 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001705 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001706
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001707 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1708 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001709 if (nla_put(msg, i + 1, sizeof(*info), info))
1710 goto nla_put_failure;
1711 }
1712 nla_nest_end(msg, nested);
1713 }
1714
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001715 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001716 const struct nl80211_vendor_cmd_info *info;
1717 struct nlattr *nested;
1718
1719 nested = nla_nest_start(msg,
1720 NL80211_ATTR_VENDOR_EVENTS);
1721 if (!nested)
1722 goto nla_put_failure;
1723
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001724 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1725 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001726 if (nla_put(msg, i + 1, sizeof(*info), info))
1727 goto nla_put_failure;
1728 }
1729 nla_nest_end(msg, nested);
1730 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001731 state->split_start++;
1732 break;
1733 case 12:
1734 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1735 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1736 rdev->wiphy.max_num_csa_counters))
1737 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001738
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001739 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1740 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1741 goto nla_put_failure;
1742
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001743 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1744 sizeof(rdev->wiphy.ext_features),
1745 rdev->wiphy.ext_features))
1746 goto nla_put_failure;
1747
Arend van Spriel38de03d2016-03-02 20:37:18 +01001748 if (rdev->wiphy.bss_select_support) {
1749 struct nlattr *nested;
1750 u32 bss_select_support = rdev->wiphy.bss_select_support;
1751
1752 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1753 if (!nested)
1754 goto nla_put_failure;
1755
1756 i = 0;
1757 while (bss_select_support) {
1758 if ((bss_select_support & 1) &&
1759 nla_put_flag(msg, i))
1760 goto nla_put_failure;
1761 i++;
1762 bss_select_support >>= 1;
1763 }
1764 nla_nest_end(msg, nested);
1765 }
1766
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301767 state->split_start++;
1768 break;
1769 case 13:
1770 if (rdev->wiphy.num_iftype_ext_capab &&
1771 rdev->wiphy.iftype_ext_capab) {
1772 struct nlattr *nested_ext_capab, *nested;
1773
1774 nested = nla_nest_start(msg,
1775 NL80211_ATTR_IFTYPE_EXT_CAPA);
1776 if (!nested)
1777 goto nla_put_failure;
1778
1779 for (i = state->capa_start;
1780 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1781 const struct wiphy_iftype_ext_capab *capab;
1782
1783 capab = &rdev->wiphy.iftype_ext_capab[i];
1784
1785 nested_ext_capab = nla_nest_start(msg, i);
1786 if (!nested_ext_capab ||
1787 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1788 capab->iftype) ||
1789 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1790 capab->extended_capabilities_len,
1791 capab->extended_capabilities) ||
1792 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1793 capab->extended_capabilities_len,
1794 capab->extended_capabilities_mask))
1795 goto nla_put_failure;
1796
1797 nla_nest_end(msg, nested_ext_capab);
1798 if (state->split)
1799 break;
1800 }
1801 nla_nest_end(msg, nested);
1802 if (i < rdev->wiphy.num_iftype_ext_capab) {
1803 state->capa_start = i + 1;
1804 break;
1805 }
1806 }
1807
Johannes Berg3713b4e2013-02-14 16:19:38 +01001808 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001809 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001810 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001811 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001812 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001813 genlmsg_end(msg, hdr);
1814 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001815
1816 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001817 genlmsg_cancel(msg, hdr);
1818 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001819}
1820
Johannes Berg86e8cf92013-06-19 10:57:22 +02001821static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1822 struct netlink_callback *cb,
1823 struct nl80211_dump_wiphy_state *state)
1824{
1825 struct nlattr **tb = nl80211_fam.attrbuf;
1826 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1827 tb, nl80211_fam.maxattr, nl80211_policy);
1828 /* ignore parse errors for backward compatibility */
1829 if (ret)
1830 return 0;
1831
1832 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1833 if (tb[NL80211_ATTR_WIPHY])
1834 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1835 if (tb[NL80211_ATTR_WDEV])
1836 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1837 if (tb[NL80211_ATTR_IFINDEX]) {
1838 struct net_device *netdev;
1839 struct cfg80211_registered_device *rdev;
1840 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1841
Ying Xue7f2b8562014-01-15 10:23:45 +08001842 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001843 if (!netdev)
1844 return -ENODEV;
1845 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001846 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001847 netdev->ieee80211_ptr->wiphy);
1848 state->filter_wiphy = rdev->wiphy_idx;
1849 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001850 }
1851
1852 return 0;
1853}
1854
Johannes Berg55682962007-09-20 13:09:35 -04001855static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1856{
Johannes Berg645e77d2013-03-01 14:03:49 +01001857 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001858 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001859 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001860
Johannes Berg5fe231e2013-05-08 21:45:15 +02001861 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001862 if (!state) {
1863 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001864 if (!state) {
1865 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001866 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001867 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001868 state->filter_wiphy = -1;
1869 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1870 if (ret) {
1871 kfree(state);
1872 rtnl_unlock();
1873 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001874 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001875 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001876 }
1877
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001878 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1879 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001880 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001881 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001882 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001883 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001884 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001885 continue;
1886 /* attempt to fit multiple wiphy data chunks into the skb */
1887 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001888 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1889 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001890 NETLINK_CB(cb->skb).portid,
1891 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001892 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001893 if (ret < 0) {
1894 /*
1895 * If sending the wiphy data didn't fit (ENOBUFS
1896 * or EMSGSIZE returned), this SKB is still
1897 * empty (so it's not too big because another
1898 * wiphy dataset is already in the skb) and
1899 * we've not tried to adjust the dump allocation
1900 * yet ... then adjust the alloc size to be
1901 * bigger, and return 1 but with the empty skb.
1902 * This results in an empty message being RX'ed
1903 * in userspace, but that is ignored.
1904 *
1905 * We can then retry with the larger buffer.
1906 */
1907 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001908 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001909 cb->min_dump_alloc < 4096) {
1910 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001911 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001912 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001913 return 1;
1914 }
1915 idx--;
1916 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001917 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001918 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001919 break;
Johannes Berg55682962007-09-20 13:09:35 -04001920 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001921 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001922
Johannes Berg86e8cf92013-06-19 10:57:22 +02001923 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001924
1925 return skb->len;
1926}
1927
Johannes Berg86e8cf92013-06-19 10:57:22 +02001928static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1929{
1930 kfree((void *)cb->args[0]);
1931 return 0;
1932}
1933
Johannes Berg55682962007-09-20 13:09:35 -04001934static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1935{
1936 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001938 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001939
Johannes Berg645e77d2013-03-01 14:03:49 +01001940 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001941 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001942 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001943
Johannes Berg3bb20552014-05-26 13:52:25 +02001944 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1945 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001946 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001947 nlmsg_free(msg);
1948 return -ENOBUFS;
1949 }
Johannes Berg55682962007-09-20 13:09:35 -04001950
Johannes Berg134e6372009-07-10 09:51:34 +00001951 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001952}
1953
Jouni Malinen31888482008-10-30 16:59:24 +02001954static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1955 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1956 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1957 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1958 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1959 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1960};
1961
1962static int parse_txq_params(struct nlattr *tb[],
1963 struct ieee80211_txq_params *txq_params)
1964{
Johannes Berga3304b02012-03-28 11:04:24 +02001965 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001966 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1967 !tb[NL80211_TXQ_ATTR_AIFS])
1968 return -EINVAL;
1969
Johannes Berga3304b02012-03-28 11:04:24 +02001970 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001971 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1972 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1973 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1974 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1975
Johannes Berga3304b02012-03-28 11:04:24 +02001976 if (txq_params->ac >= NL80211_NUM_ACS)
1977 return -EINVAL;
1978
Jouni Malinen31888482008-10-30 16:59:24 +02001979 return 0;
1980}
1981
Johannes Bergf444de02010-05-05 15:25:02 +02001982static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1983{
1984 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001985 * You can only set the channel explicitly for WDS interfaces,
1986 * all others have their channel managed via their respective
1987 * "establish a connection" command (connect, join, ...)
1988 *
1989 * For AP/GO and mesh mode, the channel can be set with the
1990 * channel userspace API, but is only stored and passed to the
1991 * low-level driver when the AP starts or the mesh is joined.
1992 * This is for backward compatibility, userspace can also give
1993 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001994 *
1995 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001996 * whatever else is going on, so they have their own special
1997 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001998 */
1999 return !wdev ||
2000 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002001 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002002 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2003 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002004}
2005
Johannes Berg683b6d32012-11-08 21:25:48 +01002006static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2007 struct genl_info *info,
2008 struct cfg80211_chan_def *chandef)
2009{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302010 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002011
2012 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2013 return -EINVAL;
2014
2015 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2016
2017 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002018 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2019 chandef->center_freq1 = control_freq;
2020 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002021
2022 /* Primary channel not allowed */
2023 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2024 return -EINVAL;
2025
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002026 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2027 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002028
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002029 chantype = nla_get_u32(
2030 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2031
2032 switch (chantype) {
2033 case NL80211_CHAN_NO_HT:
2034 case NL80211_CHAN_HT20:
2035 case NL80211_CHAN_HT40PLUS:
2036 case NL80211_CHAN_HT40MINUS:
2037 cfg80211_chandef_create(chandef, chandef->chan,
2038 chantype);
2039 break;
2040 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002041 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002042 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002043 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2044 chandef->width =
2045 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2046 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2047 chandef->center_freq1 =
2048 nla_get_u32(
2049 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2050 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2051 chandef->center_freq2 =
2052 nla_get_u32(
2053 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2054 }
2055
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002056 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002057 return -EINVAL;
2058
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002059 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2060 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002061 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002062
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002063 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2064 chandef->width == NL80211_CHAN_WIDTH_10) &&
2065 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2066 return -EINVAL;
2067
Johannes Berg683b6d32012-11-08 21:25:48 +01002068 return 0;
2069}
2070
Johannes Bergf444de02010-05-05 15:25:02 +02002071static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002072 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002073 struct genl_info *info)
2074{
Johannes Berg683b6d32012-11-08 21:25:48 +01002075 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002076 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002077 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002078 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002079
Jouni Malinene16821b2014-04-28 11:22:08 +03002080 if (dev)
2081 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002082 if (!nl80211_can_set_dev_channel(wdev))
2083 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002084 if (wdev)
2085 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002086
Johannes Berg683b6d32012-11-08 21:25:48 +01002087 result = nl80211_parse_chandef(rdev, info, &chandef);
2088 if (result)
2089 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002090
Johannes Berge8c9bd52012-06-06 08:18:22 +02002091 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002092 case NL80211_IFTYPE_AP:
2093 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002094 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2095 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002096 result = -EINVAL;
2097 break;
2098 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002099 if (wdev->beacon_interval) {
2100 if (!dev || !rdev->ops->set_ap_chanwidth ||
2101 !(rdev->wiphy.features &
2102 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2103 result = -EBUSY;
2104 break;
2105 }
2106
2107 /* Only allow dynamic channel width changes */
2108 if (chandef.chan != wdev->preset_chandef.chan) {
2109 result = -EBUSY;
2110 break;
2111 }
2112 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2113 if (result)
2114 break;
2115 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002116 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002117 result = 0;
2118 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002119 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002120 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002121 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002122 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002123 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002124 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002125 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002126 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002127 }
Johannes Bergf444de02010-05-05 15:25:02 +02002128
2129 return result;
2130}
2131
2132static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2133{
Johannes Berg4c476992010-10-04 21:36:35 +02002134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2135 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002136
Jouni Malinene16821b2014-04-28 11:22:08 +03002137 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002138}
2139
Bill Jordane8347eb2010-10-01 13:54:28 -04002140static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2141{
Johannes Berg43b19952010-10-07 13:10:30 +02002142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2143 struct net_device *dev = info->user_ptr[1];
2144 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002145 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002146
2147 if (!info->attrs[NL80211_ATTR_MAC])
2148 return -EINVAL;
2149
Johannes Berg43b19952010-10-07 13:10:30 +02002150 if (netif_running(dev))
2151 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002152
Johannes Berg43b19952010-10-07 13:10:30 +02002153 if (!rdev->ops->set_wds_peer)
2154 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002155
Johannes Berg43b19952010-10-07 13:10:30 +02002156 if (wdev->iftype != NL80211_IFTYPE_WDS)
2157 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002158
2159 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002160 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002161}
2162
Johannes Berg55682962007-09-20 13:09:35 -04002163static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2164{
2165 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002166 struct net_device *netdev = NULL;
2167 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002168 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002169 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002170 u32 changed;
2171 u8 retry_short = 0, retry_long = 0;
2172 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002173 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002174
Johannes Berg5fe231e2013-05-08 21:45:15 +02002175 ASSERT_RTNL();
2176
Johannes Bergf444de02010-05-05 15:25:02 +02002177 /*
2178 * Try to find the wiphy and netdev. Normally this
2179 * function shouldn't need the netdev, but this is
2180 * done for backward compatibility -- previously
2181 * setting the channel was done per wiphy, but now
2182 * it is per netdev. Previous userland like hostapd
2183 * also passed a netdev to set_wiphy, so that it is
2184 * possible to let that go to the right netdev!
2185 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002186
Johannes Bergf444de02010-05-05 15:25:02 +02002187 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2188 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2189
Ying Xue7f2b8562014-01-15 10:23:45 +08002190 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002191 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002192 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002193 else
Johannes Bergf444de02010-05-05 15:25:02 +02002194 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002195 }
2196
Johannes Bergf444de02010-05-05 15:25:02 +02002197 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002198 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2199 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002200 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002201 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002202 wdev = NULL;
2203 netdev = NULL;
2204 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002205 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002206 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002207
2208 /*
2209 * end workaround code, by now the rdev is available
2210 * and locked, and wdev may or may not be NULL.
2211 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002212
2213 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002214 result = cfg80211_dev_rename(
2215 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002216
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002217 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002218 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002219
Jouni Malinen31888482008-10-30 16:59:24 +02002220 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2221 struct ieee80211_txq_params txq_params;
2222 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2223
Ying Xue7f2b8562014-01-15 10:23:45 +08002224 if (!rdev->ops->set_txq_params)
2225 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002226
Ying Xue7f2b8562014-01-15 10:23:45 +08002227 if (!netdev)
2228 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002229
Johannes Berg133a3ff2011-11-03 14:50:13 +01002230 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002231 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2232 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002233
Ying Xue7f2b8562014-01-15 10:23:45 +08002234 if (!netif_running(netdev))
2235 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002236
Jouni Malinen31888482008-10-30 16:59:24 +02002237 nla_for_each_nested(nl_txq_params,
2238 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2239 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002240 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2241 nla_data(nl_txq_params),
2242 nla_len(nl_txq_params),
2243 txq_params_policy);
2244 if (result)
2245 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002246 result = parse_txq_params(tb, &txq_params);
2247 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002248 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002249
Hila Gonene35e4d22012-06-27 17:19:42 +03002250 result = rdev_set_txq_params(rdev, netdev,
2251 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002252 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002253 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002254 }
2255 }
2256
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002257 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002258 result = __nl80211_set_channel(
2259 rdev,
2260 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2261 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002262 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002263 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002264 }
2265
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002266 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002267 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002268 enum nl80211_tx_power_setting type;
2269 int idx, mbm = 0;
2270
Johannes Bergc8442112012-10-24 10:17:18 +02002271 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2272 txp_wdev = NULL;
2273
Ying Xue7f2b8562014-01-15 10:23:45 +08002274 if (!rdev->ops->set_tx_power)
2275 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002276
2277 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2278 type = nla_get_u32(info->attrs[idx]);
2279
2280 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002281 (type != NL80211_TX_POWER_AUTOMATIC))
2282 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002283
2284 if (type != NL80211_TX_POWER_AUTOMATIC) {
2285 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2286 mbm = nla_get_u32(info->attrs[idx]);
2287 }
2288
Johannes Bergc8442112012-10-24 10:17:18 +02002289 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002290 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002291 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002292 }
2293
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002294 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2295 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2296 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002297
Bruno Randolf7f531e02010-12-16 11:30:22 +09002298 if ((!rdev->wiphy.available_antennas_tx &&
2299 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002300 !rdev->ops->set_antenna)
2301 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002302
2303 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2304 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2305
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002306 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002307 * available antenna masks, except for the "all" mask */
2308 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002309 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2310 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002311
Bruno Randolf7f531e02010-12-16 11:30:22 +09002312 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2313 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002314
Hila Gonene35e4d22012-06-27 17:19:42 +03002315 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002316 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002317 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002318 }
2319
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002320 changed = 0;
2321
2322 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2323 retry_short = nla_get_u8(
2324 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002325 if (retry_short == 0)
2326 return -EINVAL;
2327
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002328 changed |= WIPHY_PARAM_RETRY_SHORT;
2329 }
2330
2331 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2332 retry_long = nla_get_u8(
2333 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002334 if (retry_long == 0)
2335 return -EINVAL;
2336
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002337 changed |= WIPHY_PARAM_RETRY_LONG;
2338 }
2339
2340 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2341 frag_threshold = nla_get_u32(
2342 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002343 if (frag_threshold < 256)
2344 return -EINVAL;
2345
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002346 if (frag_threshold != (u32) -1) {
2347 /*
2348 * Fragments (apart from the last one) are required to
2349 * have even length. Make the fragmentation code
2350 * simpler by stripping LSB should someone try to use
2351 * odd threshold value.
2352 */
2353 frag_threshold &= ~0x1;
2354 }
2355 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2356 }
2357
2358 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2359 rts_threshold = nla_get_u32(
2360 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2361 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2362 }
2363
Lukáš Turek81077e82009-12-21 22:50:47 +01002364 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002365 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2366 return -EINVAL;
2367
Lukáš Turek81077e82009-12-21 22:50:47 +01002368 coverage_class = nla_get_u8(
2369 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2370 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2371 }
2372
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002373 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2374 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2375 return -EOPNOTSUPP;
2376
2377 changed |= WIPHY_PARAM_DYN_ACK;
2378 }
2379
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002380 if (changed) {
2381 u8 old_retry_short, old_retry_long;
2382 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002383 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002384
Ying Xue7f2b8562014-01-15 10:23:45 +08002385 if (!rdev->ops->set_wiphy_params)
2386 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002387
2388 old_retry_short = rdev->wiphy.retry_short;
2389 old_retry_long = rdev->wiphy.retry_long;
2390 old_frag_threshold = rdev->wiphy.frag_threshold;
2391 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002392 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002393
2394 if (changed & WIPHY_PARAM_RETRY_SHORT)
2395 rdev->wiphy.retry_short = retry_short;
2396 if (changed & WIPHY_PARAM_RETRY_LONG)
2397 rdev->wiphy.retry_long = retry_long;
2398 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2399 rdev->wiphy.frag_threshold = frag_threshold;
2400 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2401 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002402 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2403 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002404
Hila Gonene35e4d22012-06-27 17:19:42 +03002405 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002406 if (result) {
2407 rdev->wiphy.retry_short = old_retry_short;
2408 rdev->wiphy.retry_long = old_retry_long;
2409 rdev->wiphy.frag_threshold = old_frag_threshold;
2410 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002411 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002412 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002413 }
2414 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002415 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002416}
2417
Johannes Berg71bbc992012-06-15 15:30:18 +02002418static inline u64 wdev_id(struct wireless_dev *wdev)
2419{
2420 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002421 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002422}
Johannes Berg55682962007-09-20 13:09:35 -04002423
Johannes Berg683b6d32012-11-08 21:25:48 +01002424static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002425 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002426{
Johannes Berg601555c2014-11-27 17:26:56 +01002427 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2428 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002429
Johannes Berg683b6d32012-11-08 21:25:48 +01002430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2431 chandef->chan->center_freq))
2432 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002433 switch (chandef->width) {
2434 case NL80211_CHAN_WIDTH_20_NOHT:
2435 case NL80211_CHAN_WIDTH_20:
2436 case NL80211_CHAN_WIDTH_40:
2437 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2438 cfg80211_get_chandef_type(chandef)))
2439 return -ENOBUFS;
2440 break;
2441 default:
2442 break;
2443 }
2444 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2445 return -ENOBUFS;
2446 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2447 return -ENOBUFS;
2448 if (chandef->center_freq2 &&
2449 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002450 return -ENOBUFS;
2451 return 0;
2452}
2453
Eric W. Biederman15e47302012-09-07 20:12:54 +00002454static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002455 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002456 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002457{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002458 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002459 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002460 void *hdr;
2461
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002462 if (removal)
2463 cmd = NL80211_CMD_DEL_INTERFACE;
2464
2465 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002466 if (!hdr)
2467 return -1;
2468
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002469 if (dev &&
2470 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002471 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002472 goto nla_put_failure;
2473
2474 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2475 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002476 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2477 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002478 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002479 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2480 rdev->devlist_generation ^
2481 (cfg80211_rdev_list_generation << 2)))
2482 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002483
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002484 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002485 int ret;
2486 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002487
Johannes Berg683b6d32012-11-08 21:25:48 +01002488 ret = rdev_get_channel(rdev, wdev, &chandef);
2489 if (ret == 0) {
2490 if (nl80211_send_chandef(msg, &chandef))
2491 goto nla_put_failure;
2492 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002493 }
2494
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002495 if (rdev->ops->get_tx_power) {
2496 int dbm, ret;
2497
2498 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2499 if (ret == 0 &&
2500 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2501 DBM_TO_MBM(dbm)))
2502 goto nla_put_failure;
2503 }
2504
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002505 if (wdev->ssid_len) {
2506 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2507 goto nla_put_failure;
2508 }
2509
Johannes Berg053c0952015-01-16 22:09:00 +01002510 genlmsg_end(msg, hdr);
2511 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002512
2513 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002514 genlmsg_cancel(msg, hdr);
2515 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002516}
2517
2518static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2519{
2520 int wp_idx = 0;
2521 int if_idx = 0;
2522 int wp_start = cb->args[0];
2523 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002524 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002525 struct wireless_dev *wdev;
2526
Johannes Berg5fe231e2013-05-08 21:45:15 +02002527 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002528 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2529 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002530 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002531 if (wp_idx < wp_start) {
2532 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002533 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002534 }
Johannes Berg55682962007-09-20 13:09:35 -04002535 if_idx = 0;
2536
Johannes Berg53873f12016-05-03 16:52:04 +03002537 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002538 if (if_idx < if_start) {
2539 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002540 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002541 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002542 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002543 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002544 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002545 goto out;
2546 }
2547 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002548 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002549
2550 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002551 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002552 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002553 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002554
2555 cb->args[0] = wp_idx;
2556 cb->args[1] = if_idx;
2557
2558 return skb->len;
2559}
2560
2561static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2562{
2563 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002565 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002566
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002568 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002569 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002570
Eric W. Biederman15e47302012-09-07 20:12:54 +00002571 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002572 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002573 nlmsg_free(msg);
2574 return -ENOBUFS;
2575 }
Johannes Berg55682962007-09-20 13:09:35 -04002576
Johannes Berg134e6372009-07-10 09:51:34 +00002577 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002578}
2579
Michael Wu66f7ac52008-01-31 19:48:22 +01002580static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2581 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2582 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2583 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2584 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2585 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002586 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002587};
2588
2589static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2590{
2591 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2592 int flag;
2593
2594 *mntrflags = 0;
2595
2596 if (!nla)
2597 return -EINVAL;
2598
2599 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2600 nla, mntr_flags_policy))
2601 return -EINVAL;
2602
2603 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2604 if (flags[flag])
2605 *mntrflags |= (1<<flag);
2606
2607 return 0;
2608}
2609
Johannes Berg9bc383d2009-11-19 11:55:19 +01002610static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002611 struct net_device *netdev, u8 use_4addr,
2612 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002613{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002614 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002615 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002616 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002617 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002618 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002619
2620 switch (iftype) {
2621 case NL80211_IFTYPE_AP_VLAN:
2622 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2623 return 0;
2624 break;
2625 case NL80211_IFTYPE_STATION:
2626 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2627 return 0;
2628 break;
2629 default:
2630 break;
2631 }
2632
2633 return -EOPNOTSUPP;
2634}
2635
Johannes Berg55682962007-09-20 13:09:35 -04002636static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2637{
Johannes Berg4c476992010-10-04 21:36:35 +02002638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002639 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002640 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002641 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002642 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002643 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002644 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002645
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002646 memset(&params, 0, sizeof(params));
2647
Johannes Berg04a773a2009-04-19 21:24:32 +02002648 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002649
Johannes Berg723b0382008-09-16 20:22:09 +02002650 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002651 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002652 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002653 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002654 if (ntype > NL80211_IFTYPE_MAX)
2655 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002656 }
2657
Johannes Berg92ffe052008-09-16 20:39:36 +02002658 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002659 struct wireless_dev *wdev = dev->ieee80211_ptr;
2660
Johannes Berg4c476992010-10-04 21:36:35 +02002661 if (ntype != NL80211_IFTYPE_MESH_POINT)
2662 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002663 if (netif_running(dev))
2664 return -EBUSY;
2665
2666 wdev_lock(wdev);
2667 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2668 IEEE80211_MAX_MESH_ID_LEN);
2669 wdev->mesh_id_up_len =
2670 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2671 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2672 wdev->mesh_id_up_len);
2673 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002674 }
2675
Felix Fietkau8b787642009-11-10 18:53:10 +01002676 if (info->attrs[NL80211_ATTR_4ADDR]) {
2677 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2678 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002679 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002680 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002681 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002682 } else {
2683 params.use_4addr = -1;
2684 }
2685
Johannes Berg92ffe052008-09-16 20:39:36 +02002686 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002687 if (ntype != NL80211_IFTYPE_MONITOR)
2688 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002689 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2690 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002691 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002692 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002693
2694 flags = &_flags;
2695 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002696 }
Johannes Berg3b858752009-03-12 09:55:09 +01002697
Luciano Coelho18003292013-08-29 13:26:57 +03002698 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002699 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2700 return -EOPNOTSUPP;
2701
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002702 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002703 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002704 else
2705 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002706
Johannes Berg9bc383d2009-11-19 11:55:19 +01002707 if (!err && params.use_4addr != -1)
2708 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2709
Johannes Berg55682962007-09-20 13:09:35 -04002710 return err;
2711}
2712
2713static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2714{
Johannes Berg4c476992010-10-04 21:36:35 +02002715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002716 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002717 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002718 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002719 int err;
2720 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002721 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002722
Johannes Berg78f22b62014-03-24 17:57:27 +01002723 /* to avoid failing a new interface creation due to pending removal */
2724 cfg80211_destroy_ifaces(rdev);
2725
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002726 memset(&params, 0, sizeof(params));
2727
Johannes Berg55682962007-09-20 13:09:35 -04002728 if (!info->attrs[NL80211_ATTR_IFNAME])
2729 return -EINVAL;
2730
2731 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2732 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2733 if (type > NL80211_IFTYPE_MAX)
2734 return -EINVAL;
2735 }
2736
Johannes Berg79c97e92009-07-07 03:56:12 +02002737 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002738 !(rdev->wiphy.interface_modes & (1 << type)))
2739 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002740
Ben Greeare8f479b2014-10-22 12:23:05 -07002741 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2742 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2743 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002744 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2745 ETH_ALEN);
2746 if (!is_valid_ether_addr(params.macaddr))
2747 return -EADDRNOTAVAIL;
2748 }
2749
Johannes Berg9bc383d2009-11-19 11:55:19 +01002750 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002751 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002752 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002753 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002754 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002755 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002756
Michael Wu66f7ac52008-01-31 19:48:22 +01002757 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2758 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2759 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002760
Luciano Coelho18003292013-08-29 13:26:57 +03002761 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002762 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2763 return -EOPNOTSUPP;
2764
Johannes Berga18c7192015-02-24 10:56:42 +01002765 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2766 if (!msg)
2767 return -ENOMEM;
2768
Hila Gonene35e4d22012-06-27 17:19:42 +03002769 wdev = rdev_add_virtual_intf(rdev,
2770 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002771 NET_NAME_USER, type, err ? NULL : &flags,
2772 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002773 if (WARN_ON(!wdev)) {
2774 nlmsg_free(msg);
2775 return -EPROTO;
2776 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002777 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002778 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002779 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002780
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002781 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002782 wdev->owner_nlportid = info->snd_portid;
2783
Johannes Berg98104fde2012-06-16 00:19:54 +02002784 switch (type) {
2785 case NL80211_IFTYPE_MESH_POINT:
2786 if (!info->attrs[NL80211_ATTR_MESH_ID])
2787 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002788 wdev_lock(wdev);
2789 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2790 IEEE80211_MAX_MESH_ID_LEN);
2791 wdev->mesh_id_up_len =
2792 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2793 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2794 wdev->mesh_id_up_len);
2795 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002796 break;
2797 case NL80211_IFTYPE_P2P_DEVICE:
2798 /*
2799 * P2P Device doesn't have a netdev, so doesn't go
2800 * through the netdev notifier and must be added here
2801 */
2802 mutex_init(&wdev->mtx);
2803 INIT_LIST_HEAD(&wdev->event_list);
2804 spin_lock_init(&wdev->event_lock);
2805 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2806 spin_lock_init(&wdev->mgmt_registrations_lock);
2807
Johannes Berg98104fde2012-06-16 00:19:54 +02002808 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002809 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002810 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002811 break;
2812 default:
2813 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002814 }
2815
Eric W. Biederman15e47302012-09-07 20:12:54 +00002816 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002817 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002818 nlmsg_free(msg);
2819 return -ENOBUFS;
2820 }
2821
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002822 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2823 if (event) {
2824 if (nl80211_send_iface(event, 0, 0, 0,
2825 rdev, wdev, false) < 0) {
2826 nlmsg_free(event);
2827 goto out;
2828 }
2829
2830 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2831 event, 0, NL80211_MCGRP_CONFIG,
2832 GFP_KERNEL);
2833 }
2834
2835out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002836 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002837}
2838
2839static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2840{
Johannes Berg4c476992010-10-04 21:36:35 +02002841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002842 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002843 struct sk_buff *msg;
2844 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002845
Johannes Berg4c476992010-10-04 21:36:35 +02002846 if (!rdev->ops->del_virtual_intf)
2847 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002848
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002849 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2850 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2851 nlmsg_free(msg);
2852 msg = NULL;
2853 }
2854
Johannes Berg84efbb82012-06-16 00:00:26 +02002855 /*
2856 * If we remove a wireless device without a netdev then clear
2857 * user_ptr[1] so that nl80211_post_doit won't dereference it
2858 * to check if it needs to do dev_put(). Otherwise it crashes
2859 * since the wdev has been freed, unlike with a netdev where
2860 * we need the dev_put() for the netdev to really be freed.
2861 */
2862 if (!wdev->netdev)
2863 info->user_ptr[1] = NULL;
2864
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002865 status = rdev_del_virtual_intf(rdev, wdev);
2866 if (status >= 0 && msg)
2867 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2868 msg, 0, NL80211_MCGRP_CONFIG,
2869 GFP_KERNEL);
2870 else
2871 nlmsg_free(msg);
2872
2873 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002874}
2875
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002876static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2877{
2878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2879 struct net_device *dev = info->user_ptr[1];
2880 u16 noack_map;
2881
2882 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2883 return -EINVAL;
2884
2885 if (!rdev->ops->set_noack_map)
2886 return -EOPNOTSUPP;
2887
2888 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2889
Hila Gonene35e4d22012-06-27 17:19:42 +03002890 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002891}
2892
Johannes Berg41ade002007-12-19 02:03:29 +01002893struct get_key_cookie {
2894 struct sk_buff *msg;
2895 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002896 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002897};
2898
2899static void get_key_callback(void *c, struct key_params *params)
2900{
Johannes Bergb9454e82009-07-08 13:29:08 +02002901 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002902 struct get_key_cookie *cookie = c;
2903
David S. Miller9360ffd2012-03-29 04:41:26 -04002904 if ((params->key &&
2905 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2906 params->key_len, params->key)) ||
2907 (params->seq &&
2908 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2909 params->seq_len, params->seq)) ||
2910 (params->cipher &&
2911 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2912 params->cipher)))
2913 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002914
Johannes Bergb9454e82009-07-08 13:29:08 +02002915 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2916 if (!key)
2917 goto nla_put_failure;
2918
David S. Miller9360ffd2012-03-29 04:41:26 -04002919 if ((params->key &&
2920 nla_put(cookie->msg, NL80211_KEY_DATA,
2921 params->key_len, params->key)) ||
2922 (params->seq &&
2923 nla_put(cookie->msg, NL80211_KEY_SEQ,
2924 params->seq_len, params->seq)) ||
2925 (params->cipher &&
2926 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2927 params->cipher)))
2928 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002929
David S. Miller9360ffd2012-03-29 04:41:26 -04002930 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2931 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002932
2933 nla_nest_end(cookie->msg, key);
2934
Johannes Berg41ade002007-12-19 02:03:29 +01002935 return;
2936 nla_put_failure:
2937 cookie->error = 1;
2938}
2939
2940static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2941{
Johannes Berg4c476992010-10-04 21:36:35 +02002942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002943 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002944 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002945 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002946 const u8 *mac_addr = NULL;
2947 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002948 struct get_key_cookie cookie = {
2949 .error = 0,
2950 };
2951 void *hdr;
2952 struct sk_buff *msg;
2953
2954 if (info->attrs[NL80211_ATTR_KEY_IDX])
2955 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2956
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002957 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002958 return -EINVAL;
2959
2960 if (info->attrs[NL80211_ATTR_MAC])
2961 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2962
Johannes Berge31b8212010-10-05 19:39:30 +02002963 pairwise = !!mac_addr;
2964 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2965 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002966
Johannes Berge31b8212010-10-05 19:39:30 +02002967 if (kt >= NUM_NL80211_KEYTYPES)
2968 return -EINVAL;
2969 if (kt != NL80211_KEYTYPE_GROUP &&
2970 kt != NL80211_KEYTYPE_PAIRWISE)
2971 return -EINVAL;
2972 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2973 }
2974
Johannes Berg4c476992010-10-04 21:36:35 +02002975 if (!rdev->ops->get_key)
2976 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002977
Johannes Berg0fa7b392015-01-23 11:10:12 +01002978 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2979 return -ENOENT;
2980
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002981 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002982 if (!msg)
2983 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002984
Eric W. Biederman15e47302012-09-07 20:12:54 +00002985 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002986 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002987 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002988 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002989
2990 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002991 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002992
David S. Miller9360ffd2012-03-29 04:41:26 -04002993 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2994 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2995 goto nla_put_failure;
2996 if (mac_addr &&
2997 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2998 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002999
Hila Gonene35e4d22012-06-27 17:19:42 +03003000 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3001 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003002
3003 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003004 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003005
3006 if (cookie.error)
3007 goto nla_put_failure;
3008
3009 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003010 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003011
3012 nla_put_failure:
3013 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003014 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003015 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003016 return err;
3017}
3018
3019static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3020{
Johannes Berg4c476992010-10-04 21:36:35 +02003021 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003022 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003023 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003024 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003025
Johannes Bergb9454e82009-07-08 13:29:08 +02003026 err = nl80211_parse_key(info, &key);
3027 if (err)
3028 return err;
3029
3030 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003031 return -EINVAL;
3032
Johannes Bergb9454e82009-07-08 13:29:08 +02003033 /* only support setting default key */
3034 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003035 return -EINVAL;
3036
Johannes Bergfffd0932009-07-08 14:22:54 +02003037 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003038
3039 if (key.def) {
3040 if (!rdev->ops->set_default_key) {
3041 err = -EOPNOTSUPP;
3042 goto out;
3043 }
3044
3045 err = nl80211_key_allowed(dev->ieee80211_ptr);
3046 if (err)
3047 goto out;
3048
Hila Gonene35e4d22012-06-27 17:19:42 +03003049 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003050 key.def_uni, key.def_multi);
3051
3052 if (err)
3053 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003054
Johannes Berg3d23e342009-09-29 23:27:28 +02003055#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003056 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003057#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003058 } else {
3059 if (key.def_uni || !key.def_multi) {
3060 err = -EINVAL;
3061 goto out;
3062 }
3063
3064 if (!rdev->ops->set_default_mgmt_key) {
3065 err = -EOPNOTSUPP;
3066 goto out;
3067 }
3068
3069 err = nl80211_key_allowed(dev->ieee80211_ptr);
3070 if (err)
3071 goto out;
3072
Hila Gonene35e4d22012-06-27 17:19:42 +03003073 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003074 if (err)
3075 goto out;
3076
3077#ifdef CONFIG_CFG80211_WEXT
3078 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3079#endif
3080 }
3081
3082 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003083 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003084
Johannes Berg41ade002007-12-19 02:03:29 +01003085 return err;
3086}
3087
3088static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3089{
Johannes Berg4c476992010-10-04 21:36:35 +02003090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003091 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003092 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003093 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003094 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003095
Johannes Bergb9454e82009-07-08 13:29:08 +02003096 err = nl80211_parse_key(info, &key);
3097 if (err)
3098 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003099
Johannes Bergb9454e82009-07-08 13:29:08 +02003100 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003101 return -EINVAL;
3102
Johannes Berg41ade002007-12-19 02:03:29 +01003103 if (info->attrs[NL80211_ATTR_MAC])
3104 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3105
Johannes Berge31b8212010-10-05 19:39:30 +02003106 if (key.type == -1) {
3107 if (mac_addr)
3108 key.type = NL80211_KEYTYPE_PAIRWISE;
3109 else
3110 key.type = NL80211_KEYTYPE_GROUP;
3111 }
3112
3113 /* for now */
3114 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3115 key.type != NL80211_KEYTYPE_GROUP)
3116 return -EINVAL;
3117
Johannes Berg4c476992010-10-04 21:36:35 +02003118 if (!rdev->ops->add_key)
3119 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003120
Johannes Berge31b8212010-10-05 19:39:30 +02003121 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3122 key.type == NL80211_KEYTYPE_PAIRWISE,
3123 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003124 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003125
3126 wdev_lock(dev->ieee80211_ptr);
3127 err = nl80211_key_allowed(dev->ieee80211_ptr);
3128 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003129 err = rdev_add_key(rdev, dev, key.idx,
3130 key.type == NL80211_KEYTYPE_PAIRWISE,
3131 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003132 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003133
Johannes Berg41ade002007-12-19 02:03:29 +01003134 return err;
3135}
3136
3137static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3138{
Johannes Berg4c476992010-10-04 21:36:35 +02003139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003140 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003141 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003142 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003143 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003144
Johannes Bergb9454e82009-07-08 13:29:08 +02003145 err = nl80211_parse_key(info, &key);
3146 if (err)
3147 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003148
3149 if (info->attrs[NL80211_ATTR_MAC])
3150 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3151
Johannes Berge31b8212010-10-05 19:39:30 +02003152 if (key.type == -1) {
3153 if (mac_addr)
3154 key.type = NL80211_KEYTYPE_PAIRWISE;
3155 else
3156 key.type = NL80211_KEYTYPE_GROUP;
3157 }
3158
3159 /* for now */
3160 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3161 key.type != NL80211_KEYTYPE_GROUP)
3162 return -EINVAL;
3163
Johannes Berg4c476992010-10-04 21:36:35 +02003164 if (!rdev->ops->del_key)
3165 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003166
Johannes Bergfffd0932009-07-08 14:22:54 +02003167 wdev_lock(dev->ieee80211_ptr);
3168 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003169
Johannes Berg0fa7b392015-01-23 11:10:12 +01003170 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003171 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3172 err = -ENOENT;
3173
Johannes Bergfffd0932009-07-08 14:22:54 +02003174 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003175 err = rdev_del_key(rdev, dev, key.idx,
3176 key.type == NL80211_KEYTYPE_PAIRWISE,
3177 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003178
Johannes Berg3d23e342009-09-29 23:27:28 +02003179#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003180 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003181 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003182 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003183 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003184 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3185 }
3186#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003187 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003188
Johannes Berg41ade002007-12-19 02:03:29 +01003189 return err;
3190}
3191
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303192/* This function returns an error or the number of nested attributes */
3193static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3194{
3195 struct nlattr *attr;
3196 int n_entries = 0, tmp;
3197
3198 nla_for_each_nested(attr, nl_attr, tmp) {
3199 if (nla_len(attr) != ETH_ALEN)
3200 return -EINVAL;
3201
3202 n_entries++;
3203 }
3204
3205 return n_entries;
3206}
3207
3208/*
3209 * This function parses ACL information and allocates memory for ACL data.
3210 * On successful return, the calling function is responsible to free the
3211 * ACL buffer returned by this function.
3212 */
3213static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3214 struct genl_info *info)
3215{
3216 enum nl80211_acl_policy acl_policy;
3217 struct nlattr *attr;
3218 struct cfg80211_acl_data *acl;
3219 int i = 0, n_entries, tmp;
3220
3221 if (!wiphy->max_acl_mac_addrs)
3222 return ERR_PTR(-EOPNOTSUPP);
3223
3224 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3225 return ERR_PTR(-EINVAL);
3226
3227 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3228 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3229 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3230 return ERR_PTR(-EINVAL);
3231
3232 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3233 return ERR_PTR(-EINVAL);
3234
3235 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3236 if (n_entries < 0)
3237 return ERR_PTR(n_entries);
3238
3239 if (n_entries > wiphy->max_acl_mac_addrs)
3240 return ERR_PTR(-ENOTSUPP);
3241
3242 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3243 GFP_KERNEL);
3244 if (!acl)
3245 return ERR_PTR(-ENOMEM);
3246
3247 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3248 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3249 i++;
3250 }
3251
3252 acl->n_acl_entries = n_entries;
3253 acl->acl_policy = acl_policy;
3254
3255 return acl;
3256}
3257
3258static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3259{
3260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3261 struct net_device *dev = info->user_ptr[1];
3262 struct cfg80211_acl_data *acl;
3263 int err;
3264
3265 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3266 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3267 return -EOPNOTSUPP;
3268
3269 if (!dev->ieee80211_ptr->beacon_interval)
3270 return -EINVAL;
3271
3272 acl = parse_acl_data(&rdev->wiphy, info);
3273 if (IS_ERR(acl))
3274 return PTR_ERR(acl);
3275
3276 err = rdev_set_mac_acl(rdev, dev, acl);
3277
3278 kfree(acl);
3279
3280 return err;
3281}
3282
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003283static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003284 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003285{
Johannes Berg88600202012-02-13 15:17:18 +01003286 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003287
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003288 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3289 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3290 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3291 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003292 return -EINVAL;
3293
Johannes Berg88600202012-02-13 15:17:18 +01003294 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003295
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003296 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3297 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3298 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003299 if (!bcn->head_len)
3300 return -EINVAL;
3301 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003302 }
3303
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003304 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3305 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3306 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003307 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003308 }
3309
Johannes Berg4c476992010-10-04 21:36:35 +02003310 if (!haveinfo)
3311 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003312
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003313 if (attrs[NL80211_ATTR_IE]) {
3314 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3315 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003316 }
3317
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003318 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003319 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003320 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003321 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003322 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003323 }
3324
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003325 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003326 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003327 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003328 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003329 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003330 }
3331
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003332 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3333 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3334 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003335 }
3336
Johannes Berg88600202012-02-13 15:17:18 +01003337 return 0;
3338}
3339
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003340static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3341 struct cfg80211_ap_settings *params)
3342{
3343 struct wireless_dev *wdev;
3344 bool ret = false;
3345
Johannes Berg53873f12016-05-03 16:52:04 +03003346 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003347 if (wdev->iftype != NL80211_IFTYPE_AP &&
3348 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3349 continue;
3350
Johannes Berg683b6d32012-11-08 21:25:48 +01003351 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003352 continue;
3353
Johannes Berg683b6d32012-11-08 21:25:48 +01003354 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003355 ret = true;
3356 break;
3357 }
3358
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003359 return ret;
3360}
3361
Jouni Malinene39e5b52012-09-30 19:29:39 +03003362static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3363 enum nl80211_auth_type auth_type,
3364 enum nl80211_commands cmd)
3365{
3366 if (auth_type > NL80211_AUTHTYPE_MAX)
3367 return false;
3368
3369 switch (cmd) {
3370 case NL80211_CMD_AUTHENTICATE:
3371 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3372 auth_type == NL80211_AUTHTYPE_SAE)
3373 return false;
3374 return true;
3375 case NL80211_CMD_CONNECT:
3376 case NL80211_CMD_START_AP:
3377 /* SAE not supported yet */
3378 if (auth_type == NL80211_AUTHTYPE_SAE)
3379 return false;
3380 return true;
3381 default:
3382 return false;
3383 }
3384}
3385
Johannes Berg88600202012-02-13 15:17:18 +01003386static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3387{
3388 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3389 struct net_device *dev = info->user_ptr[1];
3390 struct wireless_dev *wdev = dev->ieee80211_ptr;
3391 struct cfg80211_ap_settings params;
3392 int err;
3393
3394 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3395 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3396 return -EOPNOTSUPP;
3397
3398 if (!rdev->ops->start_ap)
3399 return -EOPNOTSUPP;
3400
3401 if (wdev->beacon_interval)
3402 return -EALREADY;
3403
3404 memset(&params, 0, sizeof(params));
3405
3406 /* these are required for START_AP */
3407 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3408 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3409 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3410 return -EINVAL;
3411
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003412 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003413 if (err)
3414 return err;
3415
3416 params.beacon_interval =
3417 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3418 params.dtim_period =
3419 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3420
3421 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3422 if (err)
3423 return err;
3424
3425 /*
3426 * In theory, some of these attributes should be required here
3427 * but since they were not used when the command was originally
3428 * added, keep them optional for old user space programs to let
3429 * them continue to work with drivers that do not need the
3430 * additional information -- drivers must check!
3431 */
3432 if (info->attrs[NL80211_ATTR_SSID]) {
3433 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3434 params.ssid_len =
3435 nla_len(info->attrs[NL80211_ATTR_SSID]);
3436 if (params.ssid_len == 0 ||
3437 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3438 return -EINVAL;
3439 }
3440
3441 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3442 params.hidden_ssid = nla_get_u32(
3443 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3444 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3445 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3446 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3447 return -EINVAL;
3448 }
3449
3450 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3451
3452 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3453 params.auth_type = nla_get_u32(
3454 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003455 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3456 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003457 return -EINVAL;
3458 } else
3459 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3460
3461 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3462 NL80211_MAX_NR_CIPHER_SUITES);
3463 if (err)
3464 return err;
3465
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303466 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3467 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3468 return -EOPNOTSUPP;
3469 params.inactivity_timeout = nla_get_u16(
3470 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3471 }
3472
Johannes Berg53cabad2012-11-14 15:17:28 +01003473 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3474 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3475 return -EINVAL;
3476 params.p2p_ctwindow =
3477 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3478 if (params.p2p_ctwindow > 127)
3479 return -EINVAL;
3480 if (params.p2p_ctwindow != 0 &&
3481 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3482 return -EINVAL;
3483 }
3484
3485 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3486 u8 tmp;
3487
3488 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3489 return -EINVAL;
3490 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3491 if (tmp > 1)
3492 return -EINVAL;
3493 params.p2p_opp_ps = tmp;
3494 if (params.p2p_opp_ps != 0 &&
3495 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3496 return -EINVAL;
3497 }
3498
Johannes Bergaa430da2012-05-16 23:50:18 +02003499 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003500 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3501 if (err)
3502 return err;
3503 } else if (wdev->preset_chandef.chan) {
3504 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003505 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003506 return -EINVAL;
3507
Arik Nemtsov923b3522015-07-08 15:41:44 +03003508 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3509 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003510 return -EINVAL;
3511
Eliad Peller18998c32014-09-10 14:07:34 +03003512 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3513 params.smps_mode =
3514 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3515 switch (params.smps_mode) {
3516 case NL80211_SMPS_OFF:
3517 break;
3518 case NL80211_SMPS_STATIC:
3519 if (!(rdev->wiphy.features &
3520 NL80211_FEATURE_STATIC_SMPS))
3521 return -EINVAL;
3522 break;
3523 case NL80211_SMPS_DYNAMIC:
3524 if (!(rdev->wiphy.features &
3525 NL80211_FEATURE_DYNAMIC_SMPS))
3526 return -EINVAL;
3527 break;
3528 default:
3529 return -EINVAL;
3530 }
3531 } else {
3532 params.smps_mode = NL80211_SMPS_OFF;
3533 }
3534
Ola Olsson4baf6be2015-10-29 07:04:58 +01003535 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3536 params.acl = parse_acl_data(&rdev->wiphy, info);
3537 if (IS_ERR(params.acl))
3538 return PTR_ERR(params.acl);
3539 }
3540
Lior David34d50512016-01-28 10:58:25 +02003541 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02003542 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
Lior David34d50512016-01-28 10:58:25 +02003543 return -EOPNOTSUPP;
3544
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003545 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003546 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003547 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003548 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003549 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003550 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003551 wdev->ssid_len = params.ssid_len;
3552 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003553 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003554 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303555
3556 kfree(params.acl);
3557
Johannes Berg56d18932011-05-09 18:41:15 +02003558 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003559}
3560
Johannes Berg88600202012-02-13 15:17:18 +01003561static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3562{
3563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3564 struct net_device *dev = info->user_ptr[1];
3565 struct wireless_dev *wdev = dev->ieee80211_ptr;
3566 struct cfg80211_beacon_data params;
3567 int err;
3568
3569 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3570 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3571 return -EOPNOTSUPP;
3572
3573 if (!rdev->ops->change_beacon)
3574 return -EOPNOTSUPP;
3575
3576 if (!wdev->beacon_interval)
3577 return -EINVAL;
3578
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003579 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003580 if (err)
3581 return err;
3582
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003583 wdev_lock(wdev);
3584 err = rdev_change_beacon(rdev, dev, &params);
3585 wdev_unlock(wdev);
3586
3587 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003588}
3589
3590static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003591{
Johannes Berg4c476992010-10-04 21:36:35 +02003592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3593 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003594
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003595 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003596}
3597
Johannes Berg5727ef12007-12-19 02:03:34 +01003598static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3599 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3600 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3601 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003602 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003603 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003604 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003605};
3606
Johannes Bergeccb8e82009-05-11 21:57:56 +03003607static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003608 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003609 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003610{
3611 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003612 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003613 int flag;
3614
Johannes Bergeccb8e82009-05-11 21:57:56 +03003615 /*
3616 * Try parsing the new attribute first so userspace
3617 * can specify both for older kernels.
3618 */
3619 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3620 if (nla) {
3621 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003622
Johannes Bergeccb8e82009-05-11 21:57:56 +03003623 sta_flags = nla_data(nla);
3624 params->sta_flags_mask = sta_flags->mask;
3625 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003626 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003627 if ((params->sta_flags_mask |
3628 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3629 return -EINVAL;
3630 return 0;
3631 }
3632
3633 /* if present, parse the old attribute */
3634
3635 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003636 if (!nla)
3637 return 0;
3638
3639 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3640 nla, sta_flags_policy))
3641 return -EINVAL;
3642
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003643 /*
3644 * Only allow certain flags for interface types so that
3645 * other attributes are silently ignored. Remember that
3646 * this is backward compatibility code with old userspace
3647 * and shouldn't be hit in other cases anyway.
3648 */
3649 switch (iftype) {
3650 case NL80211_IFTYPE_AP:
3651 case NL80211_IFTYPE_AP_VLAN:
3652 case NL80211_IFTYPE_P2P_GO:
3653 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3654 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3655 BIT(NL80211_STA_FLAG_WME) |
3656 BIT(NL80211_STA_FLAG_MFP);
3657 break;
3658 case NL80211_IFTYPE_P2P_CLIENT:
3659 case NL80211_IFTYPE_STATION:
3660 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3661 BIT(NL80211_STA_FLAG_TDLS_PEER);
3662 break;
3663 case NL80211_IFTYPE_MESH_POINT:
3664 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3665 BIT(NL80211_STA_FLAG_MFP) |
3666 BIT(NL80211_STA_FLAG_AUTHORIZED);
3667 default:
3668 return -EINVAL;
3669 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003670
Johannes Berg3383b5a2012-05-10 20:14:43 +02003671 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3672 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003673 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003674
Johannes Berg3383b5a2012-05-10 20:14:43 +02003675 /* no longer support new API additions in old API */
3676 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3677 return -EINVAL;
3678 }
3679 }
3680
Johannes Berg5727ef12007-12-19 02:03:34 +01003681 return 0;
3682}
3683
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003684static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3685 int attr)
3686{
3687 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003688 u32 bitrate;
3689 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003690 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003691
3692 rate = nla_nest_start(msg, attr);
3693 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003694 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003695
3696 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3697 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003698 /* report 16-bit bitrate only if we can */
3699 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003700 if (bitrate > 0 &&
3701 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3702 return false;
3703 if (bitrate_compat > 0 &&
3704 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3705 return false;
3706
Johannes Bergb51f3be2015-01-15 16:14:02 +01003707 switch (info->bw) {
3708 case RATE_INFO_BW_5:
3709 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3710 break;
3711 case RATE_INFO_BW_10:
3712 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3713 break;
3714 default:
3715 WARN_ON(1);
3716 /* fall through */
3717 case RATE_INFO_BW_20:
3718 rate_flg = 0;
3719 break;
3720 case RATE_INFO_BW_40:
3721 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3722 break;
3723 case RATE_INFO_BW_80:
3724 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3725 break;
3726 case RATE_INFO_BW_160:
3727 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3728 break;
3729 }
3730
3731 if (rate_flg && nla_put_flag(msg, rate_flg))
3732 return false;
3733
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003734 if (info->flags & RATE_INFO_FLAGS_MCS) {
3735 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3736 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003737 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3738 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3739 return false;
3740 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3741 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3742 return false;
3743 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3744 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003745 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3746 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3747 return false;
3748 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003749
3750 nla_nest_end(msg, rate);
3751 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003752}
3753
Felix Fietkau119363c2013-04-22 16:29:30 +02003754static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3755 int id)
3756{
3757 void *attr;
3758 int i = 0;
3759
3760 if (!mask)
3761 return true;
3762
3763 attr = nla_nest_start(msg, id);
3764 if (!attr)
3765 return false;
3766
3767 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3768 if (!(mask & BIT(i)))
3769 continue;
3770
3771 if (nla_put_u8(msg, i, signal[i]))
3772 return false;
3773 }
3774
3775 nla_nest_end(msg, attr);
3776
3777 return true;
3778}
3779
Johannes Bergcf5ead82014-11-14 17:14:00 +01003780static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3781 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003782 struct cfg80211_registered_device *rdev,
3783 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003784 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003785{
3786 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003787 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003788
Johannes Bergcf5ead82014-11-14 17:14:00 +01003789 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003790 if (!hdr)
3791 return -1;
3792
David S. Miller9360ffd2012-03-29 04:41:26 -04003793 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3794 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3795 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3796 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003797
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003798 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3799 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003800 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003801
3802#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003803 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303804 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003805 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3806 sinfo->memb)) \
3807 goto nla_put_failure; \
3808 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003809#define PUT_SINFO_U64(attr, memb) do { \
3810 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3811 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3812 sinfo->memb, NL80211_STA_INFO_PAD)) \
3813 goto nla_put_failure; \
3814 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003815
3816 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3817 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3818
3819 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3820 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003821 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003822 (u32)sinfo->rx_bytes))
3823 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003824
3825 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3826 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003827 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3828 (u32)sinfo->tx_bytes))
3829 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003830
Johannes Bergd686b922016-04-26 09:54:11 +02003831 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3832 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003833 PUT_SINFO(LLID, llid, u16);
3834 PUT_SINFO(PLID, plid, u16);
3835 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003836 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003837
John W. Linville66266b32012-03-15 13:25:41 -04003838 switch (rdev->wiphy.signal_type) {
3839 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003840 PUT_SINFO(SIGNAL, signal, u8);
3841 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003842 break;
3843 default:
3844 break;
3845 }
Johannes Berg319090b2014-11-17 14:08:11 +01003846 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003847 if (!nl80211_put_signal(msg, sinfo->chains,
3848 sinfo->chain_signal,
3849 NL80211_STA_INFO_CHAIN_SIGNAL))
3850 goto nla_put_failure;
3851 }
Johannes Berg319090b2014-11-17 14:08:11 +01003852 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003853 if (!nl80211_put_signal(msg, sinfo->chains,
3854 sinfo->chain_signal_avg,
3855 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3856 goto nla_put_failure;
3857 }
Johannes Berg319090b2014-11-17 14:08:11 +01003858 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003859 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3860 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003861 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003862 }
Johannes Berg319090b2014-11-17 14:08:11 +01003863 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003864 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3865 NL80211_STA_INFO_RX_BITRATE))
3866 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003867 }
Johannes Berg319090b2014-11-17 14:08:11 +01003868
3869 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3870 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3871 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3872 PUT_SINFO(TX_FAILED, tx_failed, u32);
3873 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3874 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3875 PUT_SINFO(LOCAL_PM, local_pm, u32);
3876 PUT_SINFO(PEER_PM, peer_pm, u32);
3877 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3878
3879 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003880 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3881 if (!bss_param)
3882 goto nla_put_failure;
3883
David S. Miller9360ffd2012-03-29 04:41:26 -04003884 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3885 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3886 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3887 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3888 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3889 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3890 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3891 sinfo->bss_param.dtim_period) ||
3892 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3893 sinfo->bss_param.beacon_interval))
3894 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003895
3896 nla_nest_end(msg, bss_param);
3897 }
Johannes Berg319090b2014-11-17 14:08:11 +01003898 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003899 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3900 sizeof(struct nl80211_sta_flag_update),
3901 &sinfo->sta_flags))
3902 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003903
Johannes Bergd686b922016-04-26 09:54:11 +02003904 PUT_SINFO_U64(T_OFFSET, t_offset);
3905 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3906 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003907 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003908
3909#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003910#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003911
3912 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3913 struct nlattr *tidsattr;
3914 int tid;
3915
3916 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3917 if (!tidsattr)
3918 goto nla_put_failure;
3919
3920 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3921 struct cfg80211_tid_stats *tidstats;
3922 struct nlattr *tidattr;
3923
3924 tidstats = &sinfo->pertid[tid];
3925
3926 if (!tidstats->filled)
3927 continue;
3928
3929 tidattr = nla_nest_start(msg, tid + 1);
3930 if (!tidattr)
3931 goto nla_put_failure;
3932
Johannes Bergd686b922016-04-26 09:54:11 +02003933#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003934 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003935 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3936 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003937 goto nla_put_failure; \
3938 } while (0)
3939
Johannes Bergd686b922016-04-26 09:54:11 +02003940 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
3941 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
3942 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
3943 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01003944
Johannes Bergd686b922016-04-26 09:54:11 +02003945#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003946 nla_nest_end(msg, tidattr);
3947 }
3948
3949 nla_nest_end(msg, tidsattr);
3950 }
3951
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003952 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003953
Johannes Berg319090b2014-11-17 14:08:11 +01003954 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003955 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3956 sinfo->assoc_req_ies))
3957 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003958
Johannes Berg053c0952015-01-16 22:09:00 +01003959 genlmsg_end(msg, hdr);
3960 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003961
3962 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003963 genlmsg_cancel(msg, hdr);
3964 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003965}
3966
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003967static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003968 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003969{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003970 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003971 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003972 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003973 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003974 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003975 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003976
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003977 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003978 if (err)
3979 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003980
Johannes Berg97990a02013-04-19 01:02:55 +02003981 if (!wdev->netdev) {
3982 err = -EINVAL;
3983 goto out_err;
3984 }
3985
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003986 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003987 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003988 goto out_err;
3989 }
3990
Johannes Bergbba95fe2008-07-29 13:22:51 +02003991 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003992 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003993 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003994 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003995 if (err == -ENOENT)
3996 break;
3997 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003998 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003999
Johannes Bergcf5ead82014-11-14 17:14:00 +01004000 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004001 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004002 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004003 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004004 &sinfo) < 0)
4005 goto out;
4006
4007 sta_idx++;
4008 }
4009
Johannes Bergbba95fe2008-07-29 13:22:51 +02004010 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004011 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004012 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004013 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004014 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004015
4016 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004017}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004018
Johannes Berg5727ef12007-12-19 02:03:34 +01004019static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4020{
Johannes Berg4c476992010-10-04 21:36:35 +02004021 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4022 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004023 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004024 struct sk_buff *msg;
4025 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004026 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004027
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004028 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004029
4030 if (!info->attrs[NL80211_ATTR_MAC])
4031 return -EINVAL;
4032
4033 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4034
Johannes Berg4c476992010-10-04 21:36:35 +02004035 if (!rdev->ops->get_station)
4036 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004037
Hila Gonene35e4d22012-06-27 17:19:42 +03004038 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004039 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004040 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004041
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004043 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004044 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004045
Johannes Bergcf5ead82014-11-14 17:14:00 +01004046 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4047 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004048 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004049 nlmsg_free(msg);
4050 return -ENOBUFS;
4051 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004052
Johannes Berg4c476992010-10-04 21:36:35 +02004053 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004054}
4055
Johannes Berg77ee7c82013-02-15 00:48:33 +01004056int cfg80211_check_station_change(struct wiphy *wiphy,
4057 struct station_parameters *params,
4058 enum cfg80211_station_type statype)
4059{
Ayala Bekere4208422015-10-23 11:20:06 +03004060 if (params->listen_interval != -1 &&
4061 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004062 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004063
Ayala Beker17b94242016-03-17 15:41:38 +02004064 if (params->support_p2p_ps != -1 &&
4065 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4066 return -EINVAL;
4067
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004068 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004069 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4070 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004071 return -EINVAL;
4072
4073 /* When you run into this, adjust the code below for the new flag */
4074 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4075
4076 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004077 case CFG80211_STA_MESH_PEER_KERNEL:
4078 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004079 /*
4080 * No ignoring the TDLS flag here -- the userspace mesh
4081 * code doesn't have the bug of including TDLS in the
4082 * mask everywhere.
4083 */
4084 if (params->sta_flags_mask &
4085 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4086 BIT(NL80211_STA_FLAG_MFP) |
4087 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4088 return -EINVAL;
4089 break;
4090 case CFG80211_STA_TDLS_PEER_SETUP:
4091 case CFG80211_STA_TDLS_PEER_ACTIVE:
4092 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4093 return -EINVAL;
4094 /* ignore since it can't change */
4095 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4096 break;
4097 default:
4098 /* disallow mesh-specific things */
4099 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4100 return -EINVAL;
4101 if (params->local_pm)
4102 return -EINVAL;
4103 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4104 return -EINVAL;
4105 }
4106
4107 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4108 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4109 /* TDLS can't be set, ... */
4110 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4111 return -EINVAL;
4112 /*
4113 * ... but don't bother the driver with it. This works around
4114 * a hostapd/wpa_supplicant issue -- it always includes the
4115 * TLDS_PEER flag in the mask even for AP mode.
4116 */
4117 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4118 }
4119
Ayala Beker47edb112015-09-21 15:49:53 +03004120 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4121 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004122 /* reject other things that can't change */
4123 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4124 return -EINVAL;
4125 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4126 return -EINVAL;
4127 if (params->supported_rates)
4128 return -EINVAL;
4129 if (params->ext_capab || params->ht_capa || params->vht_capa)
4130 return -EINVAL;
4131 }
4132
Ayala Beker47edb112015-09-21 15:49:53 +03004133 if (statype != CFG80211_STA_AP_CLIENT &&
4134 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004135 if (params->vlan)
4136 return -EINVAL;
4137 }
4138
4139 switch (statype) {
4140 case CFG80211_STA_AP_MLME_CLIENT:
4141 /* Use this only for authorizing/unauthorizing a station */
4142 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4143 return -EOPNOTSUPP;
4144 break;
4145 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004146 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004147 /* accept only the listed bits */
4148 if (params->sta_flags_mask &
4149 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4150 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4151 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4152 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4153 BIT(NL80211_STA_FLAG_WME) |
4154 BIT(NL80211_STA_FLAG_MFP)))
4155 return -EINVAL;
4156
4157 /* but authenticated/associated only if driver handles it */
4158 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4159 params->sta_flags_mask &
4160 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4161 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4162 return -EINVAL;
4163 break;
4164 case CFG80211_STA_IBSS:
4165 case CFG80211_STA_AP_STA:
4166 /* reject any changes other than AUTHORIZED */
4167 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4168 return -EINVAL;
4169 break;
4170 case CFG80211_STA_TDLS_PEER_SETUP:
4171 /* reject any changes other than AUTHORIZED or WME */
4172 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4173 BIT(NL80211_STA_FLAG_WME)))
4174 return -EINVAL;
4175 /* force (at least) rates when authorizing */
4176 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4177 !params->supported_rates)
4178 return -EINVAL;
4179 break;
4180 case CFG80211_STA_TDLS_PEER_ACTIVE:
4181 /* reject any changes */
4182 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004183 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004184 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4185 return -EINVAL;
4186 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004187 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004188 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4189 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004190 return -EINVAL;
4191 break;
4192 }
4193
4194 return 0;
4195}
4196EXPORT_SYMBOL(cfg80211_check_station_change);
4197
Johannes Berg5727ef12007-12-19 02:03:34 +01004198/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004199 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004200 */
Johannes Berg80b99892011-11-18 16:23:01 +01004201static struct net_device *get_vlan(struct genl_info *info,
4202 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004203{
Johannes Berg463d0182009-07-14 00:33:35 +02004204 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004205 struct net_device *v;
4206 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004207
Johannes Berg80b99892011-11-18 16:23:01 +01004208 if (!vlanattr)
4209 return NULL;
4210
4211 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4212 if (!v)
4213 return ERR_PTR(-ENODEV);
4214
4215 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4216 ret = -EINVAL;
4217 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004218 }
Johannes Berg80b99892011-11-18 16:23:01 +01004219
Johannes Berg77ee7c82013-02-15 00:48:33 +01004220 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4221 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4222 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4223 ret = -EINVAL;
4224 goto error;
4225 }
4226
Johannes Berg80b99892011-11-18 16:23:01 +01004227 if (!netif_running(v)) {
4228 ret = -ENETDOWN;
4229 goto error;
4230 }
4231
4232 return v;
4233 error:
4234 dev_put(v);
4235 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004236}
4237
Johannes Berg94e860f2014-01-20 23:58:15 +01004238static const struct nla_policy
4239nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004240 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4241 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4242};
4243
Johannes Bergff276692013-02-15 00:09:01 +01004244static int nl80211_parse_sta_wme(struct genl_info *info,
4245 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004246{
Jouni Malinendf881292013-02-14 21:10:54 +02004247 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4248 struct nlattr *nla;
4249 int err;
4250
Jouni Malinendf881292013-02-14 21:10:54 +02004251 /* parse WME attributes if present */
4252 if (!info->attrs[NL80211_ATTR_STA_WME])
4253 return 0;
4254
4255 nla = info->attrs[NL80211_ATTR_STA_WME];
4256 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4257 nl80211_sta_wme_policy);
4258 if (err)
4259 return err;
4260
4261 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4262 params->uapsd_queues = nla_get_u8(
4263 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4264 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4265 return -EINVAL;
4266
4267 if (tb[NL80211_STA_WME_MAX_SP])
4268 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4269
4270 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4271 return -EINVAL;
4272
4273 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4274
4275 return 0;
4276}
4277
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304278static int nl80211_parse_sta_channel_info(struct genl_info *info,
4279 struct station_parameters *params)
4280{
4281 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4282 params->supported_channels =
4283 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4284 params->supported_channels_len =
4285 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4286 /*
4287 * Need to include at least one (first channel, number of
4288 * channels) tuple for each subband, and must have proper
4289 * tuples for the rest of the data as well.
4290 */
4291 if (params->supported_channels_len < 2)
4292 return -EINVAL;
4293 if (params->supported_channels_len % 2)
4294 return -EINVAL;
4295 }
4296
4297 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4298 params->supported_oper_classes =
4299 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4300 params->supported_oper_classes_len =
4301 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4302 /*
4303 * The value of the Length field of the Supported Operating
4304 * Classes element is between 2 and 253.
4305 */
4306 if (params->supported_oper_classes_len < 2 ||
4307 params->supported_oper_classes_len > 253)
4308 return -EINVAL;
4309 }
4310 return 0;
4311}
4312
Johannes Bergff276692013-02-15 00:09:01 +01004313static int nl80211_set_station_tdls(struct genl_info *info,
4314 struct station_parameters *params)
4315{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304316 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004317 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004318 if (info->attrs[NL80211_ATTR_PEER_AID])
4319 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004320 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4321 params->ht_capa =
4322 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4323 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4324 params->vht_capa =
4325 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4326
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304327 err = nl80211_parse_sta_channel_info(info, params);
4328 if (err)
4329 return err;
4330
Johannes Bergff276692013-02-15 00:09:01 +01004331 return nl80211_parse_sta_wme(info, params);
4332}
4333
Johannes Berg5727ef12007-12-19 02:03:34 +01004334static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4335{
Johannes Berg4c476992010-10-04 21:36:35 +02004336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004337 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004338 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004339 u8 *mac_addr;
4340 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004341
4342 memset(&params, 0, sizeof(params));
4343
Johannes Berg77ee7c82013-02-15 00:48:33 +01004344 if (!rdev->ops->change_station)
4345 return -EOPNOTSUPP;
4346
Ayala Bekere4208422015-10-23 11:20:06 +03004347 /*
4348 * AID and listen_interval properties can be set only for unassociated
4349 * station. Include these parameters here and will check them in
4350 * cfg80211_check_station_change().
4351 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004352 if (info->attrs[NL80211_ATTR_STA_AID])
4353 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004354
4355 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4356 params.listen_interval =
4357 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4358 else
4359 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004360
Ayala Beker17b94242016-03-17 15:41:38 +02004361 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4362 u8 tmp;
4363
4364 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4365 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4366 return -EINVAL;
4367
4368 params.support_p2p_ps = tmp;
4369 } else {
4370 params.support_p2p_ps = -1;
4371 }
4372
Johannes Berg5727ef12007-12-19 02:03:34 +01004373 if (!info->attrs[NL80211_ATTR_MAC])
4374 return -EINVAL;
4375
4376 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4377
4378 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4379 params.supported_rates =
4380 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4381 params.supported_rates_len =
4382 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4383 }
4384
Jouni Malinen9d62a982013-02-14 21:10:13 +02004385 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4386 params.capability =
4387 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4388 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4389 }
4390
4391 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4392 params.ext_capab =
4393 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4394 params.ext_capab_len =
4395 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4396 }
4397
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004398 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004399 return -EINVAL;
4400
Johannes Bergf8bacc22013-02-14 23:27:01 +01004401 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004402 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004403 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4404 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4405 return -EINVAL;
4406 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004407
Johannes Bergf8bacc22013-02-14 23:27:01 +01004408 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004409 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004410 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4411 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4412 return -EINVAL;
4413 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4414 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004415
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004416 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4417 enum nl80211_mesh_power_mode pm = nla_get_u32(
4418 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4419
4420 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4421 pm > NL80211_MESH_POWER_MAX)
4422 return -EINVAL;
4423
4424 params.local_pm = pm;
4425 }
4426
Johannes Berg77ee7c82013-02-15 00:48:33 +01004427 /* Include parameters for TDLS peer (will check later) */
4428 err = nl80211_set_station_tdls(info, &params);
4429 if (err)
4430 return err;
4431
4432 params.vlan = get_vlan(info, rdev);
4433 if (IS_ERR(params.vlan))
4434 return PTR_ERR(params.vlan);
4435
Johannes Berga97f4422009-06-18 17:23:43 +02004436 switch (dev->ieee80211_ptr->iftype) {
4437 case NL80211_IFTYPE_AP:
4438 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004439 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004440 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004441 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004442 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004443 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004444 break;
4445 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004446 err = -EOPNOTSUPP;
4447 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004448 }
4449
Johannes Berg77ee7c82013-02-15 00:48:33 +01004450 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004451 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004452
Johannes Berg77ee7c82013-02-15 00:48:33 +01004453 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004454 if (params.vlan)
4455 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004456
Johannes Berg5727ef12007-12-19 02:03:34 +01004457 return err;
4458}
4459
4460static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4461{
Johannes Berg4c476992010-10-04 21:36:35 +02004462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004463 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004464 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004465 struct station_parameters params;
4466 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004467 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4468 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004469
4470 memset(&params, 0, sizeof(params));
4471
Johannes Berg984c3112013-02-14 23:43:25 +01004472 if (!rdev->ops->add_station)
4473 return -EOPNOTSUPP;
4474
Johannes Berg5727ef12007-12-19 02:03:34 +01004475 if (!info->attrs[NL80211_ATTR_MAC])
4476 return -EINVAL;
4477
Johannes Berg5727ef12007-12-19 02:03:34 +01004478 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4479 return -EINVAL;
4480
4481 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4482 return -EINVAL;
4483
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004484 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4485 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004486 return -EINVAL;
4487
Johannes Berg5727ef12007-12-19 02:03:34 +01004488 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4489 params.supported_rates =
4490 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4491 params.supported_rates_len =
4492 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4493 params.listen_interval =
4494 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004495
Ayala Beker17b94242016-03-17 15:41:38 +02004496 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4497 u8 tmp;
4498
4499 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4500 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4501 return -EINVAL;
4502
4503 params.support_p2p_ps = tmp;
4504 } else {
4505 /*
4506 * if not specified, assume it's supported for P2P GO interface,
4507 * and is NOT supported for AP interface
4508 */
4509 params.support_p2p_ps =
4510 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4511 }
4512
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004513 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004514 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004515 else
4516 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004517 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4518 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004519
Jouni Malinen9d62a982013-02-14 21:10:13 +02004520 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4521 params.capability =
4522 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4523 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4524 }
4525
4526 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4527 params.ext_capab =
4528 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4529 params.ext_capab_len =
4530 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4531 }
4532
Jouni Malinen36aedc902008-08-25 11:58:58 +03004533 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4534 params.ht_capa =
4535 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004536
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004537 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4538 params.vht_capa =
4539 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4540
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004541 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4542 params.opmode_notif_used = true;
4543 params.opmode_notif =
4544 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4545 }
4546
Johannes Bergf8bacc22013-02-14 23:27:01 +01004547 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004548 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004549 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4550 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4551 return -EINVAL;
4552 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004553
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304554 err = nl80211_parse_sta_channel_info(info, &params);
4555 if (err)
4556 return err;
4557
Johannes Bergff276692013-02-15 00:09:01 +01004558 err = nl80211_parse_sta_wme(info, &params);
4559 if (err)
4560 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004561
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004562 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004563 return -EINVAL;
4564
Johannes Berg496fcc22015-03-12 08:53:27 +02004565 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4566 * as userspace might just pass through the capabilities from the IEs
4567 * directly, rather than enforcing this restriction and returning an
4568 * error in this case.
4569 */
4570 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4571 params.ht_capa = NULL;
4572 params.vht_capa = NULL;
4573 }
4574
Johannes Berg77ee7c82013-02-15 00:48:33 +01004575 /* When you run into this, adjust the code below for the new flag */
4576 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4577
Johannes Bergbdd90d52011-12-14 12:20:27 +01004578 switch (dev->ieee80211_ptr->iftype) {
4579 case NL80211_IFTYPE_AP:
4580 case NL80211_IFTYPE_AP_VLAN:
4581 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004582 /* ignore WME attributes if iface/sta is not capable */
4583 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4584 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4585 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004586
Johannes Bergbdd90d52011-12-14 12:20:27 +01004587 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004588 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4589 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004590 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004591 /* but don't bother the driver with it */
4592 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004593
Johannes Bergd582cff2012-10-26 17:53:44 +02004594 /* allow authenticated/associated only if driver handles it */
4595 if (!(rdev->wiphy.features &
4596 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004597 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004598 return -EINVAL;
4599
Johannes Bergbda95eb2015-11-26 16:26:13 +01004600 /* Older userspace, or userspace wanting to be compatible with
4601 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4602 * and assoc flags in the mask, but assumes the station will be
4603 * added as associated anyway since this was the required driver
4604 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4605 * introduced.
4606 * In order to not bother drivers with this quirk in the API
4607 * set the flags in both the mask and set for new stations in
4608 * this case.
4609 */
4610 if (!(params.sta_flags_mask & auth_assoc)) {
4611 params.sta_flags_mask |= auth_assoc;
4612 params.sta_flags_set |= auth_assoc;
4613 }
4614
Johannes Bergbdd90d52011-12-14 12:20:27 +01004615 /* must be last in here for error handling */
4616 params.vlan = get_vlan(info, rdev);
4617 if (IS_ERR(params.vlan))
4618 return PTR_ERR(params.vlan);
4619 break;
4620 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004621 /* ignore uAPSD data */
4622 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4623
Johannes Bergd582cff2012-10-26 17:53:44 +02004624 /* associated is disallowed */
4625 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4626 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004627 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004628 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4629 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004630 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004631 break;
4632 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004633 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004634 /* ignore uAPSD data */
4635 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4636
Johannes Berg77ee7c82013-02-15 00:48:33 +01004637 /* these are disallowed */
4638 if (params.sta_flags_mask &
4639 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4640 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004641 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004642 /* Only TDLS peers can be added */
4643 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4644 return -EINVAL;
4645 /* Can only add if TDLS ... */
4646 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4647 return -EOPNOTSUPP;
4648 /* ... with external setup is supported */
4649 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4650 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004651 /*
4652 * Older wpa_supplicant versions always mark the TDLS peer
4653 * as authorized, but it shouldn't yet be.
4654 */
4655 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004656 break;
4657 default:
4658 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004659 }
4660
Johannes Bergbdd90d52011-12-14 12:20:27 +01004661 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004662
Hila Gonene35e4d22012-06-27 17:19:42 +03004663 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004664
Johannes Berg5727ef12007-12-19 02:03:34 +01004665 if (params.vlan)
4666 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004667 return err;
4668}
4669
4670static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4671{
Johannes Berg4c476992010-10-04 21:36:35 +02004672 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4673 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004674 struct station_del_parameters params;
4675
4676 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004677
4678 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004679 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004680
Johannes Berge80cf852009-05-11 14:43:13 +02004681 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004682 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004683 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004684 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4685 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004686
Johannes Berg4c476992010-10-04 21:36:35 +02004687 if (!rdev->ops->del_station)
4688 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004689
Jouni Malinen98856862014-10-20 13:20:45 +03004690 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4691 params.subtype =
4692 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4693 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4694 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4695 return -EINVAL;
4696 } else {
4697 /* Default to Deauthentication frame */
4698 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4699 }
4700
4701 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4702 params.reason_code =
4703 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4704 if (params.reason_code == 0)
4705 return -EINVAL; /* 0 is reserved */
4706 } else {
4707 /* Default to reason code 2 */
4708 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4709 }
4710
Jouni Malinen89c771e2014-10-10 20:52:40 +03004711 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004712}
4713
Eric W. Biederman15e47302012-09-07 20:12:54 +00004714static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004715 int flags, struct net_device *dev,
4716 u8 *dst, u8 *next_hop,
4717 struct mpath_info *pinfo)
4718{
4719 void *hdr;
4720 struct nlattr *pinfoattr;
4721
Henning Rogge1ef4c852014-11-04 16:14:58 +01004722 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004723 if (!hdr)
4724 return -1;
4725
David S. Miller9360ffd2012-03-29 04:41:26 -04004726 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4727 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4728 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4729 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4730 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004731
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004732 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4733 if (!pinfoattr)
4734 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004735 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4736 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4737 pinfo->frame_qlen))
4738 goto nla_put_failure;
4739 if (((pinfo->filled & MPATH_INFO_SN) &&
4740 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4741 ((pinfo->filled & MPATH_INFO_METRIC) &&
4742 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4743 pinfo->metric)) ||
4744 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4745 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4746 pinfo->exptime)) ||
4747 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4748 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4749 pinfo->flags)) ||
4750 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4751 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4752 pinfo->discovery_timeout)) ||
4753 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4754 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4755 pinfo->discovery_retries)))
4756 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004757
4758 nla_nest_end(msg, pinfoattr);
4759
Johannes Berg053c0952015-01-16 22:09:00 +01004760 genlmsg_end(msg, hdr);
4761 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004762
4763 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004764 genlmsg_cancel(msg, hdr);
4765 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004766}
4767
4768static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004769 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004770{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004771 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004772 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004773 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004774 u8 dst[ETH_ALEN];
4775 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004776 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004777 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004778
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004779 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004780 if (err)
4781 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004782
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004783 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004784 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004785 goto out_err;
4786 }
4787
Johannes Berg97990a02013-04-19 01:02:55 +02004788 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004789 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004790 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004791 }
4792
Johannes Bergbba95fe2008-07-29 13:22:51 +02004793 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004794 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004795 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004796 if (err == -ENOENT)
4797 break;
4798 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004799 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004800
Eric W. Biederman15e47302012-09-07 20:12:54 +00004801 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004802 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004803 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004804 &pinfo) < 0)
4805 goto out;
4806
4807 path_idx++;
4808 }
4809
Johannes Bergbba95fe2008-07-29 13:22:51 +02004810 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004811 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004812 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004813 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004814 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004815 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004816}
4817
4818static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4819{
Johannes Berg4c476992010-10-04 21:36:35 +02004820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004821 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004822 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004823 struct mpath_info pinfo;
4824 struct sk_buff *msg;
4825 u8 *dst = NULL;
4826 u8 next_hop[ETH_ALEN];
4827
4828 memset(&pinfo, 0, sizeof(pinfo));
4829
4830 if (!info->attrs[NL80211_ATTR_MAC])
4831 return -EINVAL;
4832
4833 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4834
Johannes Berg4c476992010-10-04 21:36:35 +02004835 if (!rdev->ops->get_mpath)
4836 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004837
Johannes Berg4c476992010-10-04 21:36:35 +02004838 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4839 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004840
Hila Gonene35e4d22012-06-27 17:19:42 +03004841 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004842 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004843 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004844
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004845 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004846 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004847 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004848
Eric W. Biederman15e47302012-09-07 20:12:54 +00004849 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004850 dev, dst, next_hop, &pinfo) < 0) {
4851 nlmsg_free(msg);
4852 return -ENOBUFS;
4853 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004854
Johannes Berg4c476992010-10-04 21:36:35 +02004855 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004856}
4857
4858static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4859{
Johannes Berg4c476992010-10-04 21:36:35 +02004860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4861 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004862 u8 *dst = NULL;
4863 u8 *next_hop = NULL;
4864
4865 if (!info->attrs[NL80211_ATTR_MAC])
4866 return -EINVAL;
4867
4868 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4869 return -EINVAL;
4870
4871 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4872 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4873
Johannes Berg4c476992010-10-04 21:36:35 +02004874 if (!rdev->ops->change_mpath)
4875 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004876
Johannes Berg4c476992010-10-04 21:36:35 +02004877 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4878 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004879
Hila Gonene35e4d22012-06-27 17:19:42 +03004880 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004881}
Johannes Berg4c476992010-10-04 21:36:35 +02004882
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004883static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4884{
Johannes Berg4c476992010-10-04 21:36:35 +02004885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4886 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004887 u8 *dst = NULL;
4888 u8 *next_hop = NULL;
4889
4890 if (!info->attrs[NL80211_ATTR_MAC])
4891 return -EINVAL;
4892
4893 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4894 return -EINVAL;
4895
4896 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4897 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4898
Johannes Berg4c476992010-10-04 21:36:35 +02004899 if (!rdev->ops->add_mpath)
4900 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004901
Johannes Berg4c476992010-10-04 21:36:35 +02004902 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4903 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004904
Hila Gonene35e4d22012-06-27 17:19:42 +03004905 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004906}
4907
4908static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4909{
Johannes Berg4c476992010-10-04 21:36:35 +02004910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4911 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004912 u8 *dst = NULL;
4913
4914 if (info->attrs[NL80211_ATTR_MAC])
4915 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4916
Johannes Berg4c476992010-10-04 21:36:35 +02004917 if (!rdev->ops->del_mpath)
4918 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004919
Hila Gonene35e4d22012-06-27 17:19:42 +03004920 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004921}
4922
Henning Rogge66be7d22014-09-12 08:58:49 +02004923static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4924{
4925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4926 int err;
4927 struct net_device *dev = info->user_ptr[1];
4928 struct mpath_info pinfo;
4929 struct sk_buff *msg;
4930 u8 *dst = NULL;
4931 u8 mpp[ETH_ALEN];
4932
4933 memset(&pinfo, 0, sizeof(pinfo));
4934
4935 if (!info->attrs[NL80211_ATTR_MAC])
4936 return -EINVAL;
4937
4938 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4939
4940 if (!rdev->ops->get_mpp)
4941 return -EOPNOTSUPP;
4942
4943 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4944 return -EOPNOTSUPP;
4945
4946 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4947 if (err)
4948 return err;
4949
4950 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4951 if (!msg)
4952 return -ENOMEM;
4953
4954 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4955 dev, dst, mpp, &pinfo) < 0) {
4956 nlmsg_free(msg);
4957 return -ENOBUFS;
4958 }
4959
4960 return genlmsg_reply(msg, info);
4961}
4962
4963static int nl80211_dump_mpp(struct sk_buff *skb,
4964 struct netlink_callback *cb)
4965{
4966 struct mpath_info pinfo;
4967 struct cfg80211_registered_device *rdev;
4968 struct wireless_dev *wdev;
4969 u8 dst[ETH_ALEN];
4970 u8 mpp[ETH_ALEN];
4971 int path_idx = cb->args[2];
4972 int err;
4973
4974 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4975 if (err)
4976 return err;
4977
4978 if (!rdev->ops->dump_mpp) {
4979 err = -EOPNOTSUPP;
4980 goto out_err;
4981 }
4982
4983 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4984 err = -EOPNOTSUPP;
4985 goto out_err;
4986 }
4987
4988 while (1) {
4989 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4990 mpp, &pinfo);
4991 if (err == -ENOENT)
4992 break;
4993 if (err)
4994 goto out_err;
4995
4996 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4997 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4998 wdev->netdev, dst, mpp,
4999 &pinfo) < 0)
5000 goto out;
5001
5002 path_idx++;
5003 }
5004
5005 out:
5006 cb->args[2] = path_idx;
5007 err = skb->len;
5008 out_err:
5009 nl80211_finish_wdev_dump(rdev);
5010 return err;
5011}
5012
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005013static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5014{
Johannes Berg4c476992010-10-04 21:36:35 +02005015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5016 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005017 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005018 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005019 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005020
5021 memset(&params, 0, sizeof(params));
5022 /* default to not changing parameters */
5023 params.use_cts_prot = -1;
5024 params.use_short_preamble = -1;
5025 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005026 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005027 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005028 params.p2p_ctwindow = -1;
5029 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005030
5031 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5032 params.use_cts_prot =
5033 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5034 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5035 params.use_short_preamble =
5036 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5037 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5038 params.use_short_slot_time =
5039 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005040 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5041 params.basic_rates =
5042 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5043 params.basic_rates_len =
5044 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5045 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005046 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5047 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005048 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5049 params.ht_opmode =
5050 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005051
Johannes Berg53cabad2012-11-14 15:17:28 +01005052 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5053 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5054 return -EINVAL;
5055 params.p2p_ctwindow =
5056 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5057 if (params.p2p_ctwindow < 0)
5058 return -EINVAL;
5059 if (params.p2p_ctwindow != 0 &&
5060 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5061 return -EINVAL;
5062 }
5063
5064 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5065 u8 tmp;
5066
5067 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5068 return -EINVAL;
5069 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5070 if (tmp > 1)
5071 return -EINVAL;
5072 params.p2p_opp_ps = tmp;
5073 if (params.p2p_opp_ps &&
5074 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5075 return -EINVAL;
5076 }
5077
Johannes Berg4c476992010-10-04 21:36:35 +02005078 if (!rdev->ops->change_bss)
5079 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005080
Johannes Berg074ac8d2010-09-16 14:58:22 +02005081 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005082 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5083 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005084
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005085 wdev_lock(wdev);
5086 err = rdev_change_bss(rdev, dev, &params);
5087 wdev_unlock(wdev);
5088
5089 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005090}
5091
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005092static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5093{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005094 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005095 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005096 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005097 u32 owner_nlportid;
5098
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005099 /*
5100 * You should only get this when cfg80211 hasn't yet initialized
5101 * completely when built-in to the kernel right between the time
5102 * window between nl80211_init() and regulatory_init(), if that is
5103 * even possible.
5104 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005105 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005106 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005107
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005108 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5109 user_reg_hint_type =
5110 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5111 else
5112 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5113
5114 switch (user_reg_hint_type) {
5115 case NL80211_USER_REG_HINT_USER:
5116 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005117 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5118 return -EINVAL;
5119
5120 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5121 return regulatory_hint_user(data, user_reg_hint_type);
5122 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005123 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5124 owner_nlportid = info->snd_portid;
5125 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5126 } else {
5127 owner_nlportid = 0;
5128 is_indoor = true;
5129 }
5130
5131 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005132 default:
5133 return -EINVAL;
5134 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005135}
5136
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005137static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005138 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005139{
Johannes Berg4c476992010-10-04 21:36:35 +02005140 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005141 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005142 struct wireless_dev *wdev = dev->ieee80211_ptr;
5143 struct mesh_config cur_params;
5144 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005145 void *hdr;
5146 struct nlattr *pinfoattr;
5147 struct sk_buff *msg;
5148
Johannes Berg29cbe682010-12-03 09:20:44 +01005149 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5150 return -EOPNOTSUPP;
5151
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005152 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005153 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005154
Johannes Berg29cbe682010-12-03 09:20:44 +01005155 wdev_lock(wdev);
5156 /* If not connected, get default parameters */
5157 if (!wdev->mesh_id_len)
5158 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5159 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005160 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005161 wdev_unlock(wdev);
5162
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005163 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005164 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005165
5166 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005167 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005168 if (!msg)
5169 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005170 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005171 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005172 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005173 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005174 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005175 if (!pinfoattr)
5176 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005177 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5178 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5179 cur_params.dot11MeshRetryTimeout) ||
5180 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5181 cur_params.dot11MeshConfirmTimeout) ||
5182 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5183 cur_params.dot11MeshHoldingTimeout) ||
5184 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5185 cur_params.dot11MeshMaxPeerLinks) ||
5186 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5187 cur_params.dot11MeshMaxRetries) ||
5188 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5189 cur_params.dot11MeshTTL) ||
5190 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5191 cur_params.element_ttl) ||
5192 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5193 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005194 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5195 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005196 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5197 cur_params.dot11MeshHWMPmaxPREQretries) ||
5198 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5199 cur_params.path_refresh_time) ||
5200 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5201 cur_params.min_discovery_timeout) ||
5202 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5203 cur_params.dot11MeshHWMPactivePathTimeout) ||
5204 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5205 cur_params.dot11MeshHWMPpreqMinInterval) ||
5206 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5207 cur_params.dot11MeshHWMPperrMinInterval) ||
5208 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5209 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5210 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5211 cur_params.dot11MeshHWMPRootMode) ||
5212 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5213 cur_params.dot11MeshHWMPRannInterval) ||
5214 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5215 cur_params.dot11MeshGateAnnouncementProtocol) ||
5216 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5217 cur_params.dot11MeshForwarding) ||
5218 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005219 cur_params.rssi_threshold) ||
5220 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005221 cur_params.ht_opmode) ||
5222 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5223 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5224 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005225 cur_params.dot11MeshHWMProotInterval) ||
5226 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005227 cur_params.dot11MeshHWMPconfirmationInterval) ||
5228 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5229 cur_params.power_mode) ||
5230 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005231 cur_params.dot11MeshAwakeWindowDuration) ||
5232 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5233 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005234 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005235 nla_nest_end(msg, pinfoattr);
5236 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005237 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005238
Johannes Berg3b858752009-03-12 09:55:09 +01005239 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005240 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005241 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005242 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005243 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005244}
5245
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005246static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005247 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5248 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5249 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5250 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5251 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5252 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005253 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005254 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005255 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005256 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5257 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5258 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5259 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5260 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005261 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005262 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005263 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005264 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005265 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005266 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005267 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5268 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005269 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5270 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005271 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005272 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5273 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005274 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005275};
5276
Javier Cardonac80d5452010-12-16 17:37:49 -08005277static const struct nla_policy
5278 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005279 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005280 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5281 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005282 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005283 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005284 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005285 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005286 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005287 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005288};
5289
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005290static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5291{
5292 u8 val = nla_get_u8(nla);
5293 if (val < min || val > max)
5294 return -EINVAL;
5295 *out = val;
5296 return 0;
5297}
5298
5299static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5300{
5301 u8 val = nla_get_u8(nla);
5302 if (val < min || val > max)
5303 return -EINVAL;
5304 *out = val;
5305 return 0;
5306}
5307
5308static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5309{
5310 u16 val = nla_get_u16(nla);
5311 if (val < min || val > max)
5312 return -EINVAL;
5313 *out = val;
5314 return 0;
5315}
5316
5317static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5318{
5319 u32 val = nla_get_u32(nla);
5320 if (val < min || val > max)
5321 return -EINVAL;
5322 *out = val;
5323 return 0;
5324}
5325
5326static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5327{
5328 s32 val = nla_get_s32(nla);
5329 if (val < min || val > max)
5330 return -EINVAL;
5331 *out = val;
5332 return 0;
5333}
5334
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005335static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005336 struct mesh_config *cfg,
5337 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005338{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005339 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005340 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005341
Marco Porschea54fba2013-01-07 16:04:48 +01005342#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5343do { \
5344 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005345 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005346 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005347 mask |= (1 << (attr - 1)); \
5348 } \
5349} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005350
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005351 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005352 return -EINVAL;
5353 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005354 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005355 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005356 return -EINVAL;
5357
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005358 /* This makes sure that there aren't more than 32 mesh config
5359 * parameters (otherwise our bitfield scheme would not work.) */
5360 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5361
5362 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005363 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005364 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005365 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005366 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005367 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005368 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005369 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005370 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005371 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005372 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005373 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005374 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005375 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005376 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005377 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005379 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005380 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005381 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005382 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005383 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005384 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005385 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005386 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5387 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005388 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005389 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005390 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005391 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005392 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005393 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005394 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005395 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005396 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005397 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005398 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005399 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5400 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005401 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005402 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005403 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005404 1, 65535, mask,
5405 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005406 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005407 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005408 1, 65535, mask,
5409 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005410 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005412 dot11MeshHWMPnetDiameterTraversalTime,
5413 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005414 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005415 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005416 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5417 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
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, dot11MeshHWMPRannInterval, 1, 65535,
5420 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005421 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005422 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005423 dot11MeshGateAnnouncementProtocol, 0, 1,
5424 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005425 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005426 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005427 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005428 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005429 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005430 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005431 nl80211_check_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005433 mask, NL80211_MESHCONF_HT_OPMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005434 nl80211_check_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005436 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005437 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005438 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005439 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005440 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005441 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005442 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005443 dot11MeshHWMPconfirmationInterval,
5444 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005445 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005446 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005447 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5448 NL80211_MESH_POWER_ACTIVE,
5449 NL80211_MESH_POWER_MAX,
5450 mask, NL80211_MESHCONF_POWER_MODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005451 nl80211_check_u32);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005452 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5453 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005454 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005455 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005456 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005457 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005458 if (mask_out)
5459 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005460
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005461 return 0;
5462
5463#undef FILL_IN_MESH_PARAM_IF_SET
5464}
5465
Javier Cardonac80d5452010-12-16 17:37:49 -08005466static int nl80211_parse_mesh_setup(struct genl_info *info,
5467 struct mesh_setup *setup)
5468{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005469 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005470 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5471
5472 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5473 return -EINVAL;
5474 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5475 info->attrs[NL80211_ATTR_MESH_SETUP],
5476 nl80211_mesh_setup_params_policy))
5477 return -EINVAL;
5478
Javier Cardonad299a1f2012-03-31 11:31:33 -07005479 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5480 setup->sync_method =
5481 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5482 IEEE80211_SYNC_METHOD_VENDOR :
5483 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5484
Javier Cardonac80d5452010-12-16 17:37:49 -08005485 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5486 setup->path_sel_proto =
5487 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5488 IEEE80211_PATH_PROTOCOL_VENDOR :
5489 IEEE80211_PATH_PROTOCOL_HWMP;
5490
5491 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5492 setup->path_metric =
5493 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5494 IEEE80211_PATH_METRIC_VENDOR :
5495 IEEE80211_PATH_METRIC_AIRTIME;
5496
Javier Cardona581a8b02011-04-07 15:08:27 -07005497 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005498 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005499 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005500 if (!is_valid_ie_attr(ieattr))
5501 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005502 setup->ie = nla_data(ieattr);
5503 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005504 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005505 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5506 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5507 return -EINVAL;
5508 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005509 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5510 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005511 if (setup->is_secure)
5512 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005513
Colleen Twitty6e16d902013-05-08 11:45:59 -07005514 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5515 if (!setup->user_mpm)
5516 return -EINVAL;
5517 setup->auth_id =
5518 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5519 }
5520
Javier Cardonac80d5452010-12-16 17:37:49 -08005521 return 0;
5522}
5523
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005524static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005525 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005526{
5527 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5528 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005529 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005530 struct mesh_config cfg;
5531 u32 mask;
5532 int err;
5533
Johannes Berg29cbe682010-12-03 09:20:44 +01005534 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5535 return -EOPNOTSUPP;
5536
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005537 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005538 return -EOPNOTSUPP;
5539
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005540 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005541 if (err)
5542 return err;
5543
Johannes Berg29cbe682010-12-03 09:20:44 +01005544 wdev_lock(wdev);
5545 if (!wdev->mesh_id_len)
5546 err = -ENOLINK;
5547
5548 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005549 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005550
5551 wdev_unlock(wdev);
5552
5553 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005554}
5555
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005556static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5557 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005558{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005559 struct nlattr *nl_reg_rules;
5560 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005561
Johannes Berg458f4f92012-12-06 15:47:38 +01005562 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5563 (regdom->dfs_region &&
5564 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005565 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005566
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005567 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5568 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005569 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005570
Johannes Berg458f4f92012-12-06 15:47:38 +01005571 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005572 struct nlattr *nl_reg_rule;
5573 const struct ieee80211_reg_rule *reg_rule;
5574 const struct ieee80211_freq_range *freq_range;
5575 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005576 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005577
Johannes Berg458f4f92012-12-06 15:47:38 +01005578 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005579 freq_range = &reg_rule->freq_range;
5580 power_rule = &reg_rule->power_rule;
5581
5582 nl_reg_rule = nla_nest_start(msg, i);
5583 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005584 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005585
Janusz Dziedzic97524822014-01-30 09:52:20 +01005586 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5587 if (!max_bandwidth_khz)
5588 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5589 reg_rule);
5590
David S. Miller9360ffd2012-03-29 04:41:26 -04005591 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5592 reg_rule->flags) ||
5593 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5594 freq_range->start_freq_khz) ||
5595 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5596 freq_range->end_freq_khz) ||
5597 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005598 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005599 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5600 power_rule->max_antenna_gain) ||
5601 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005602 power_rule->max_eirp) ||
5603 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5604 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005605 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005606
5607 nla_nest_end(msg, nl_reg_rule);
5608 }
5609
5610 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005611 return 0;
5612
5613nla_put_failure:
5614 return -EMSGSIZE;
5615}
5616
5617static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5618{
5619 const struct ieee80211_regdomain *regdom = NULL;
5620 struct cfg80211_registered_device *rdev;
5621 struct wiphy *wiphy = NULL;
5622 struct sk_buff *msg;
5623 void *hdr;
5624
5625 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5626 if (!msg)
5627 return -ENOBUFS;
5628
5629 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5630 NL80211_CMD_GET_REG);
5631 if (!hdr)
5632 goto put_failure;
5633
5634 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005635 bool self_managed;
5636
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005637 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5638 if (IS_ERR(rdev)) {
5639 nlmsg_free(msg);
5640 return PTR_ERR(rdev);
5641 }
5642
5643 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005644 self_managed = wiphy->regulatory_flags &
5645 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005646 regdom = get_wiphy_regdom(wiphy);
5647
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005648 /* a self-managed-reg device must have a private regdom */
5649 if (WARN_ON(!regdom && self_managed)) {
5650 nlmsg_free(msg);
5651 return -EINVAL;
5652 }
5653
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005654 if (regdom &&
5655 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5656 goto nla_put_failure;
5657 }
5658
5659 if (!wiphy && reg_last_request_cell_base() &&
5660 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5661 NL80211_USER_REG_HINT_CELL_BASE))
5662 goto nla_put_failure;
5663
5664 rcu_read_lock();
5665
5666 if (!regdom)
5667 regdom = rcu_dereference(cfg80211_regdomain);
5668
5669 if (nl80211_put_regdom(regdom, msg))
5670 goto nla_put_failure_rcu;
5671
5672 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005673
5674 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005675 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005676
Johannes Berg458f4f92012-12-06 15:47:38 +01005677nla_put_failure_rcu:
5678 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005679nla_put_failure:
5680 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005681put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005682 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005683 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005684}
5685
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005686static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5687 u32 seq, int flags, struct wiphy *wiphy,
5688 const struct ieee80211_regdomain *regdom)
5689{
5690 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5691 NL80211_CMD_GET_REG);
5692
5693 if (!hdr)
5694 return -1;
5695
5696 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5697
5698 if (nl80211_put_regdom(regdom, msg))
5699 goto nla_put_failure;
5700
5701 if (!wiphy && reg_last_request_cell_base() &&
5702 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5703 NL80211_USER_REG_HINT_CELL_BASE))
5704 goto nla_put_failure;
5705
5706 if (wiphy &&
5707 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5708 goto nla_put_failure;
5709
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005710 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5711 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5712 goto nla_put_failure;
5713
Johannes Berg053c0952015-01-16 22:09:00 +01005714 genlmsg_end(msg, hdr);
5715 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005716
5717nla_put_failure:
5718 genlmsg_cancel(msg, hdr);
5719 return -EMSGSIZE;
5720}
5721
5722static int nl80211_get_reg_dump(struct sk_buff *skb,
5723 struct netlink_callback *cb)
5724{
5725 const struct ieee80211_regdomain *regdom = NULL;
5726 struct cfg80211_registered_device *rdev;
5727 int err, reg_idx, start = cb->args[2];
5728
5729 rtnl_lock();
5730
5731 if (cfg80211_regdomain && start == 0) {
5732 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5733 NLM_F_MULTI, NULL,
5734 rtnl_dereference(cfg80211_regdomain));
5735 if (err < 0)
5736 goto out_err;
5737 }
5738
5739 /* the global regdom is idx 0 */
5740 reg_idx = 1;
5741 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5742 regdom = get_wiphy_regdom(&rdev->wiphy);
5743 if (!regdom)
5744 continue;
5745
5746 if (++reg_idx <= start)
5747 continue;
5748
5749 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5750 NLM_F_MULTI, &rdev->wiphy, regdom);
5751 if (err < 0) {
5752 reg_idx--;
5753 break;
5754 }
5755 }
5756
5757 cb->args[2] = reg_idx;
5758 err = skb->len;
5759out_err:
5760 rtnl_unlock();
5761 return err;
5762}
5763
Johannes Bergb6863032015-10-15 09:25:18 +02005764#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5765static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5766 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5767 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5768 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5769 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5770 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5771 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5772 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5773};
5774
5775static int parse_reg_rule(struct nlattr *tb[],
5776 struct ieee80211_reg_rule *reg_rule)
5777{
5778 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5779 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5780
5781 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5782 return -EINVAL;
5783 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5784 return -EINVAL;
5785 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5786 return -EINVAL;
5787 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5788 return -EINVAL;
5789 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5790 return -EINVAL;
5791
5792 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5793
5794 freq_range->start_freq_khz =
5795 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5796 freq_range->end_freq_khz =
5797 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5798 freq_range->max_bandwidth_khz =
5799 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5800
5801 power_rule->max_eirp =
5802 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5803
5804 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5805 power_rule->max_antenna_gain =
5806 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5807
5808 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5809 reg_rule->dfs_cac_ms =
5810 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5811
5812 return 0;
5813}
5814
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005815static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5816{
5817 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5818 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005819 char *alpha2;
5820 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005821 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005822 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005823 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005824
5825 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5826 return -EINVAL;
5827
5828 if (!info->attrs[NL80211_ATTR_REG_RULES])
5829 return -EINVAL;
5830
5831 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5832
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005833 if (info->attrs[NL80211_ATTR_DFS_REGION])
5834 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5835
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005836 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005837 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005838 num_rules++;
5839 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005840 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005841 }
5842
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005843 if (!reg_is_valid_request(alpha2))
5844 return -EINVAL;
5845
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005846 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005847 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005848
5849 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005850 if (!rd)
5851 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005852
5853 rd->n_reg_rules = num_rules;
5854 rd->alpha2[0] = alpha2[0];
5855 rd->alpha2[1] = alpha2[1];
5856
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005857 /*
5858 * Disable DFS master mode if the DFS region was
5859 * not supported or known on this kernel.
5860 */
5861 if (reg_supported_dfs_region(dfs_region))
5862 rd->dfs_region = dfs_region;
5863
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005864 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005865 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005866 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5867 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5868 reg_rule_policy);
5869 if (r)
5870 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005871 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5872 if (r)
5873 goto bad_reg;
5874
5875 rule_idx++;
5876
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005877 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5878 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005879 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005880 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005881 }
5882
Johannes Berg06627992016-06-09 10:40:09 +02005883 /* set_regdom takes ownership of rd */
5884 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02005885 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005886 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005887 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005888}
Johannes Bergb6863032015-10-15 09:25:18 +02005889#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005890
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005891static int validate_scan_freqs(struct nlattr *freqs)
5892{
5893 struct nlattr *attr1, *attr2;
5894 int n_channels = 0, tmp1, tmp2;
5895
5896 nla_for_each_nested(attr1, freqs, tmp1) {
5897 n_channels++;
5898 /*
5899 * Some hardware has a limited channel list for
5900 * scanning, and it is pretty much nonsensical
5901 * to scan for a channel twice, so disallow that
5902 * and don't require drivers to check that the
5903 * channel list they get isn't longer than what
5904 * they can scan, as long as they can scan all
5905 * the channels they registered at once.
5906 */
5907 nla_for_each_nested(attr2, freqs, tmp2)
5908 if (attr1 != attr2 &&
5909 nla_get_u32(attr1) == nla_get_u32(attr2))
5910 return 0;
5911 }
5912
5913 return n_channels;
5914}
5915
Johannes Berg57fbcce2016-04-12 15:56:15 +02005916static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005917{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005918 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005919}
5920
5921static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5922 struct cfg80211_bss_selection *bss_select)
5923{
5924 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5925 struct nlattr *nest;
5926 int err;
5927 bool found = false;
5928 int i;
5929
5930 /* only process one nested attribute */
5931 nest = nla_data(nla);
5932 if (!nla_ok(nest, nla_len(nest)))
5933 return -EINVAL;
5934
5935 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5936 nla_len(nest), nl80211_bss_select_policy);
5937 if (err)
5938 return err;
5939
5940 /* only one attribute may be given */
5941 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
5942 if (attr[i]) {
5943 if (found)
5944 return -EINVAL;
5945 found = true;
5946 }
5947 }
5948
5949 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
5950
5951 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
5952 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
5953
5954 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
5955 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
5956 bss_select->param.band_pref =
5957 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
5958 if (!is_band_valid(wiphy, bss_select->param.band_pref))
5959 return -EINVAL;
5960 }
5961
5962 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
5963 struct nl80211_bss_select_rssi_adjust *adj_param;
5964
5965 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
5966 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
5967 bss_select->param.adjust.band = adj_param->band;
5968 bss_select->param.adjust.delta = adj_param->delta;
5969 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
5970 return -EINVAL;
5971 }
5972
5973 /* user-space did not provide behaviour attribute */
5974 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
5975 return -EINVAL;
5976
5977 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
5978 return -EINVAL;
5979
5980 return 0;
5981}
5982
Johannes Bergad2b26a2014-06-12 21:39:05 +02005983static int nl80211_parse_random_mac(struct nlattr **attrs,
5984 u8 *mac_addr, u8 *mac_addr_mask)
5985{
5986 int i;
5987
5988 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005989 eth_zero_addr(mac_addr);
5990 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005991 mac_addr[0] = 0x2;
5992 mac_addr_mask[0] = 0x3;
5993
5994 return 0;
5995 }
5996
5997 /* need both or none */
5998 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5999 return -EINVAL;
6000
6001 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6002 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6003
6004 /* don't allow or configure an mcast address */
6005 if (!is_multicast_ether_addr(mac_addr_mask) ||
6006 is_multicast_ether_addr(mac_addr))
6007 return -EINVAL;
6008
6009 /*
6010 * allow users to pass a MAC address that has bits set outside
6011 * of the mask, but don't bother drivers with having to deal
6012 * with such bits
6013 */
6014 for (i = 0; i < ETH_ALEN; i++)
6015 mac_addr[i] &= mac_addr_mask[i];
6016
6017 return 0;
6018}
6019
Johannes Berg2a519312009-02-10 21:25:55 +01006020static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6021{
Johannes Berg4c476992010-10-04 21:36:35 +02006022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006023 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006024 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006025 struct nlattr *attr;
6026 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006027 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006028 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006029
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006030 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6031 return -EINVAL;
6032
Johannes Berg79c97e92009-07-07 03:56:12 +02006033 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006034
Johannes Berg4c476992010-10-04 21:36:35 +02006035 if (!rdev->ops->scan)
6036 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006037
Johannes Bergf9d15d12014-01-22 11:14:19 +02006038 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006039 err = -EBUSY;
6040 goto unlock;
6041 }
Johannes Berg2a519312009-02-10 21:25:55 +01006042
6043 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006044 n_channels = validate_scan_freqs(
6045 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006046 if (!n_channels) {
6047 err = -EINVAL;
6048 goto unlock;
6049 }
Johannes Berg2a519312009-02-10 21:25:55 +01006050 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006051 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006052 }
6053
6054 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6055 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6056 n_ssids++;
6057
Johannes Bergf9f47522013-03-19 15:04:07 +01006058 if (n_ssids > wiphy->max_scan_ssids) {
6059 err = -EINVAL;
6060 goto unlock;
6061 }
Johannes Berg2a519312009-02-10 21:25:55 +01006062
Jouni Malinen70692ad2009-02-16 19:39:13 +02006063 if (info->attrs[NL80211_ATTR_IE])
6064 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6065 else
6066 ie_len = 0;
6067
Johannes Bergf9f47522013-03-19 15:04:07 +01006068 if (ie_len > wiphy->max_scan_ie_len) {
6069 err = -EINVAL;
6070 goto unlock;
6071 }
Johannes Berg18a83652009-03-31 12:12:05 +02006072
Johannes Berg2a519312009-02-10 21:25:55 +01006073 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006074 + sizeof(*request->ssids) * n_ssids
6075 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006076 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006077 if (!request) {
6078 err = -ENOMEM;
6079 goto unlock;
6080 }
Johannes Berg2a519312009-02-10 21:25:55 +01006081
Johannes Berg2a519312009-02-10 21:25:55 +01006082 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006083 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006084 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006085 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006086 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006087 request->ie = (void *)(request->ssids + n_ssids);
6088 else
6089 request->ie = (void *)(request->channels + n_channels);
6090 }
Johannes Berg2a519312009-02-10 21:25:55 +01006091
Johannes Berg584991d2009-11-02 13:32:03 +01006092 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006093 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6094 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006095 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006096 struct ieee80211_channel *chan;
6097
6098 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6099
6100 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006101 err = -EINVAL;
6102 goto out_free;
6103 }
Johannes Berg584991d2009-11-02 13:32:03 +01006104
6105 /* ignore disabled channels */
6106 if (chan->flags & IEEE80211_CHAN_DISABLED)
6107 continue;
6108
6109 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006110 i++;
6111 }
6112 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006113 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006114
Johannes Berg2a519312009-02-10 21:25:55 +01006115 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006116 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006117 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006118
Johannes Berg2a519312009-02-10 21:25:55 +01006119 if (!wiphy->bands[band])
6120 continue;
6121 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006122 struct ieee80211_channel *chan;
6123
6124 chan = &wiphy->bands[band]->channels[j];
6125
6126 if (chan->flags & IEEE80211_CHAN_DISABLED)
6127 continue;
6128
6129 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006130 i++;
6131 }
6132 }
6133 }
6134
Johannes Berg584991d2009-11-02 13:32:03 +01006135 if (!i) {
6136 err = -EINVAL;
6137 goto out_free;
6138 }
6139
6140 request->n_channels = i;
6141
Johannes Berg2a519312009-02-10 21:25:55 +01006142 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006143 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006144 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006145 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006146 err = -EINVAL;
6147 goto out_free;
6148 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006149 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006150 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006151 i++;
6152 }
6153 }
6154
Jouni Malinen70692ad2009-02-16 19:39:13 +02006155 if (info->attrs[NL80211_ATTR_IE]) {
6156 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006157 memcpy((void *)request->ie,
6158 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006159 request->ie_len);
6160 }
6161
Johannes Berg57fbcce2016-04-12 15:56:15 +02006162 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006163 if (wiphy->bands[i])
6164 request->rates[i] =
6165 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006166
6167 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6168 nla_for_each_nested(attr,
6169 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6170 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006171 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006172
Johannes Berg57fbcce2016-04-12 15:56:15 +02006173 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006174 err = -EINVAL;
6175 goto out_free;
6176 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006177
6178 if (!wiphy->bands[band])
6179 continue;
6180
Johannes Berg34850ab2011-07-18 18:08:35 +02006181 err = ieee80211_get_ratemask(wiphy->bands[band],
6182 nla_data(attr),
6183 nla_len(attr),
6184 &request->rates[band]);
6185 if (err)
6186 goto out_free;
6187 }
6188 }
6189
Sam Leffler46856bb2012-10-11 21:03:32 -07006190 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006191 request->flags = nla_get_u32(
6192 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006193 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6194 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006195 err = -EOPNOTSUPP;
6196 goto out_free;
6197 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006198
6199 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6200 if (!(wiphy->features &
6201 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6202 err = -EOPNOTSUPP;
6203 goto out_free;
6204 }
6205
6206 if (wdev->current_bss) {
6207 err = -EOPNOTSUPP;
6208 goto out_free;
6209 }
6210
6211 err = nl80211_parse_random_mac(info->attrs,
6212 request->mac_addr,
6213 request->mac_addr_mask);
6214 if (err)
6215 goto out_free;
6216 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006217 }
Sam Lefflered4737712012-10-11 21:03:31 -07006218
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306219 request->no_cck =
6220 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6221
Jouni Malinen818965d2016-02-26 22:12:47 +02006222 if (info->attrs[NL80211_ATTR_MAC])
6223 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6224 ETH_ALEN);
6225 else
6226 eth_broadcast_addr(request->bssid);
6227
Johannes Bergfd014282012-06-18 19:17:03 +02006228 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006229 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006230 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006231
Johannes Berg79c97e92009-07-07 03:56:12 +02006232 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006233 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006234
Johannes Berg463d0182009-07-14 00:33:35 +02006235 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006236 nl80211_send_scan_start(rdev, wdev);
6237 if (wdev->netdev)
6238 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006239 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006240 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006241 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006242 kfree(request);
6243 }
Johannes Berg3b858752009-03-12 09:55:09 +01006244
Johannes Bergf9f47522013-03-19 15:04:07 +01006245 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006246 return err;
6247}
6248
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306249static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6250{
6251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6252 struct wireless_dev *wdev = info->user_ptr[1];
6253
6254 if (!rdev->ops->abort_scan)
6255 return -EOPNOTSUPP;
6256
6257 if (rdev->scan_msg)
6258 return 0;
6259
6260 if (!rdev->scan_req)
6261 return -ENOENT;
6262
6263 rdev_abort_scan(rdev, wdev);
6264 return 0;
6265}
6266
Avraham Stern3b06d272015-10-12 09:51:34 +03006267static int
6268nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6269 struct cfg80211_sched_scan_request *request,
6270 struct nlattr **attrs)
6271{
6272 int tmp, err, i = 0;
6273 struct nlattr *attr;
6274
6275 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6276 u32 interval;
6277
6278 /*
6279 * If scan plans are not specified,
6280 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6281 * case one scan plan will be set with the specified scan
6282 * interval and infinite number of iterations.
6283 */
6284 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6285 return -EINVAL;
6286
6287 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6288 if (!interval)
6289 return -EINVAL;
6290
6291 request->scan_plans[0].interval =
6292 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6293 if (!request->scan_plans[0].interval)
6294 return -EINVAL;
6295
6296 if (request->scan_plans[0].interval >
6297 wiphy->max_sched_scan_plan_interval)
6298 request->scan_plans[0].interval =
6299 wiphy->max_sched_scan_plan_interval;
6300
6301 return 0;
6302 }
6303
6304 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6305 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6306
6307 if (WARN_ON(i >= n_plans))
6308 return -EINVAL;
6309
6310 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6311 nla_data(attr), nla_len(attr),
6312 nl80211_plan_policy);
6313 if (err)
6314 return err;
6315
6316 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6317 return -EINVAL;
6318
6319 request->scan_plans[i].interval =
6320 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6321 if (!request->scan_plans[i].interval ||
6322 request->scan_plans[i].interval >
6323 wiphy->max_sched_scan_plan_interval)
6324 return -EINVAL;
6325
6326 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6327 request->scan_plans[i].iterations =
6328 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6329 if (!request->scan_plans[i].iterations ||
6330 (request->scan_plans[i].iterations >
6331 wiphy->max_sched_scan_plan_iterations))
6332 return -EINVAL;
6333 } else if (i < n_plans - 1) {
6334 /*
6335 * All scan plans but the last one must specify
6336 * a finite number of iterations
6337 */
6338 return -EINVAL;
6339 }
6340
6341 i++;
6342 }
6343
6344 /*
6345 * The last scan plan must not specify the number of
6346 * iterations, it is supposed to run infinitely
6347 */
6348 if (request->scan_plans[n_plans - 1].iterations)
6349 return -EINVAL;
6350
6351 return 0;
6352}
6353
Luciano Coelho256da022014-11-10 16:13:46 +02006354static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006355nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006356 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006357{
6358 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006359 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006360 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006361 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006362 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006363 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006364 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006365
Luciano Coelho256da022014-11-10 16:13:46 +02006366 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6367 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006368
Luciano Coelho256da022014-11-10 16:13:46 +02006369 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006370 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006371 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006372 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006373 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006374 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006375 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006376 }
6377
Luciano Coelho256da022014-11-10 16:13:46 +02006378 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6379 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006380 tmp)
6381 n_ssids++;
6382
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006383 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006384 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006385
Johannes Bergea73cbc2014-01-24 10:53:53 +01006386 /*
6387 * First, count the number of 'real' matchsets. Due to an issue with
6388 * the old implementation, matchsets containing only the RSSI attribute
6389 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6390 * RSSI for all matchsets, rather than their own matchset for reporting
6391 * all APs with a strong RSSI. This is needed to be compatible with
6392 * older userspace that treated a matchset with only the RSSI as the
6393 * global RSSI for all other matchsets - if there are other matchsets.
6394 */
Luciano Coelho256da022014-11-10 16:13:46 +02006395 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006396 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006397 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006398 tmp) {
6399 struct nlattr *rssi;
6400
6401 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6402 nla_data(attr), nla_len(attr),
6403 nl80211_match_policy);
6404 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006405 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006406 /* add other standalone attributes here */
6407 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6408 n_match_sets++;
6409 continue;
6410 }
6411 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6412 if (rssi)
6413 default_match_rssi = nla_get_s32(rssi);
6414 }
6415 }
6416
6417 /* However, if there's no other matchset, add the RSSI one */
6418 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6419 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006420
6421 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006422 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006423
Luciano Coelho256da022014-11-10 16:13:46 +02006424 if (attrs[NL80211_ATTR_IE])
6425 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006426 else
6427 ie_len = 0;
6428
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006429 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006430 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006431
Avraham Stern3b06d272015-10-12 09:51:34 +03006432 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6433 /*
6434 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6435 * each scan plan already specifies its own interval
6436 */
6437 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6438 return ERR_PTR(-EINVAL);
6439
6440 nla_for_each_nested(attr,
6441 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6442 n_plans++;
6443 } else {
6444 /*
6445 * The scan interval attribute is kept for backward
6446 * compatibility. If no scan plans are specified and sched scan
6447 * interval is specified, one scan plan will be set with this
6448 * scan interval and infinite number of iterations.
6449 */
6450 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6451 return ERR_PTR(-EINVAL);
6452
6453 n_plans = 1;
6454 }
6455
6456 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6457 return ERR_PTR(-EINVAL);
6458
Luciano Coelho807f8a82011-05-11 17:09:35 +03006459 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006460 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006461 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006462 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006463 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006464 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006465 if (!request)
6466 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006467
6468 if (n_ssids)
6469 request->ssids = (void *)&request->channels[n_channels];
6470 request->n_ssids = n_ssids;
6471 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006472 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006473 request->ie = (void *)(request->ssids + n_ssids);
6474 else
6475 request->ie = (void *)(request->channels + n_channels);
6476 }
6477
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006478 if (n_match_sets) {
6479 if (request->ie)
6480 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006481 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006482 request->match_sets =
6483 (void *)(request->ssids + n_ssids);
6484 else
6485 request->match_sets =
6486 (void *)(request->channels + n_channels);
6487 }
6488 request->n_match_sets = n_match_sets;
6489
Avraham Stern3b06d272015-10-12 09:51:34 +03006490 if (n_match_sets)
6491 request->scan_plans = (void *)(request->match_sets +
6492 n_match_sets);
6493 else if (request->ie)
6494 request->scan_plans = (void *)(request->ie + ie_len);
6495 else if (n_ssids)
6496 request->scan_plans = (void *)(request->ssids + n_ssids);
6497 else
6498 request->scan_plans = (void *)(request->channels + n_channels);
6499
6500 request->n_scan_plans = n_plans;
6501
Luciano Coelho807f8a82011-05-11 17:09:35 +03006502 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006503 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006504 /* user specified, bail out if channel not found */
6505 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006506 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006507 tmp) {
6508 struct ieee80211_channel *chan;
6509
6510 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6511
6512 if (!chan) {
6513 err = -EINVAL;
6514 goto out_free;
6515 }
6516
6517 /* ignore disabled channels */
6518 if (chan->flags & IEEE80211_CHAN_DISABLED)
6519 continue;
6520
6521 request->channels[i] = chan;
6522 i++;
6523 }
6524 } else {
6525 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006526 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006527 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006528
Luciano Coelho807f8a82011-05-11 17:09:35 +03006529 if (!wiphy->bands[band])
6530 continue;
6531 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6532 struct ieee80211_channel *chan;
6533
6534 chan = &wiphy->bands[band]->channels[j];
6535
6536 if (chan->flags & IEEE80211_CHAN_DISABLED)
6537 continue;
6538
6539 request->channels[i] = chan;
6540 i++;
6541 }
6542 }
6543 }
6544
6545 if (!i) {
6546 err = -EINVAL;
6547 goto out_free;
6548 }
6549
6550 request->n_channels = i;
6551
6552 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006553 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006554 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006555 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006556 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006557 err = -EINVAL;
6558 goto out_free;
6559 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006560 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006561 memcpy(request->ssids[i].ssid, nla_data(attr),
6562 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006563 i++;
6564 }
6565 }
6566
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006567 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006568 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006569 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006570 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006571 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006572 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006573
Johannes Bergae811e22014-01-24 10:17:47 +01006574 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6575 nla_data(attr), nla_len(attr),
6576 nl80211_match_policy);
6577 if (err)
6578 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006579 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006580 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006581 if (WARN_ON(i >= n_match_sets)) {
6582 /* this indicates a programming error,
6583 * the loop above should have verified
6584 * things properly
6585 */
6586 err = -EINVAL;
6587 goto out_free;
6588 }
6589
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006590 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6591 err = -EINVAL;
6592 goto out_free;
6593 }
6594 memcpy(request->match_sets[i].ssid.ssid,
6595 nla_data(ssid), nla_len(ssid));
6596 request->match_sets[i].ssid.ssid_len =
6597 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07006598 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01006599 request->match_sets[i].rssi_thold =
6600 default_match_rssi;
6601 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6602 if (rssi)
6603 request->match_sets[i].rssi_thold =
6604 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006605 }
6606 i++;
6607 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006608
6609 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006610 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006611 request->match_sets[0].rssi_thold = default_match_rssi;
6612
6613 request->min_rssi_thold = INT_MAX;
6614 for (i = 0; i < n_match_sets; i++)
6615 request->min_rssi_thold =
6616 min(request->match_sets[i].rssi_thold,
6617 request->min_rssi_thold);
6618 } else {
6619 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006620 }
6621
Johannes Berg9900e482014-02-04 21:01:25 +01006622 if (ie_len) {
6623 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006624 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006625 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006626 request->ie_len);
6627 }
6628
Luciano Coelho256da022014-11-10 16:13:46 +02006629 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006630 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006631 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006632 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6633 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006634 err = -EOPNOTSUPP;
6635 goto out_free;
6636 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006637
6638 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6639 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6640
6641 if (!wdev) /* must be net-detect */
6642 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6643
6644 if (!(wiphy->features & flg)) {
6645 err = -EOPNOTSUPP;
6646 goto out_free;
6647 }
6648
6649 if (wdev && wdev->current_bss) {
6650 err = -EOPNOTSUPP;
6651 goto out_free;
6652 }
6653
6654 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6655 request->mac_addr_mask);
6656 if (err)
6657 goto out_free;
6658 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006659 }
Sam Lefflered4737712012-10-11 21:03:31 -07006660
Luciano Coelho9c748932015-01-16 16:04:09 +02006661 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6662 request->delay =
6663 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6664
Avraham Stern3b06d272015-10-12 09:51:34 +03006665 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6666 if (err)
6667 goto out_free;
6668
Sam Leffler15d60302012-10-11 21:03:34 -07006669 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006670
Luciano Coelho256da022014-11-10 16:13:46 +02006671 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006672
6673out_free:
6674 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006675 return ERR_PTR(err);
6676}
6677
6678static int nl80211_start_sched_scan(struct sk_buff *skb,
6679 struct genl_info *info)
6680{
6681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6682 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006683 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006684 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006685 int err;
6686
6687 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6688 !rdev->ops->sched_scan_start)
6689 return -EOPNOTSUPP;
6690
6691 if (rdev->sched_scan_req)
6692 return -EINPROGRESS;
6693
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006694 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6695 info->attrs);
6696
6697 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006698 if (err)
6699 goto out_err;
6700
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006701 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006702 if (err)
6703 goto out_free;
6704
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006705 sched_scan_req->dev = dev;
6706 sched_scan_req->wiphy = &rdev->wiphy;
6707
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006708 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6709 sched_scan_req->owner_nlportid = info->snd_portid;
6710
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006711 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006712
6713 nl80211_send_sched_scan(rdev, dev,
6714 NL80211_CMD_START_SCHED_SCAN);
6715 return 0;
6716
6717out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006718 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006719out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006720 return err;
6721}
6722
6723static int nl80211_stop_sched_scan(struct sk_buff *skb,
6724 struct genl_info *info)
6725{
6726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6727
6728 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6729 !rdev->ops->sched_scan_stop)
6730 return -EOPNOTSUPP;
6731
Johannes Berg5fe231e2013-05-08 21:45:15 +02006732 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006733}
6734
Simon Wunderlich04f39042013-02-08 18:16:19 +01006735static int nl80211_start_radar_detection(struct sk_buff *skb,
6736 struct genl_info *info)
6737{
6738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6739 struct net_device *dev = info->user_ptr[1];
6740 struct wireless_dev *wdev = dev->ieee80211_ptr;
6741 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006742 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006743 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006744 int err;
6745
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006746 dfs_region = reg_get_dfs_region(wdev->wiphy);
6747 if (dfs_region == NL80211_DFS_UNSET)
6748 return -EINVAL;
6749
Simon Wunderlich04f39042013-02-08 18:16:19 +01006750 err = nl80211_parse_chandef(rdev, info, &chandef);
6751 if (err)
6752 return err;
6753
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006754 if (netif_carrier_ok(dev))
6755 return -EBUSY;
6756
Simon Wunderlich04f39042013-02-08 18:16:19 +01006757 if (wdev->cac_started)
6758 return -EBUSY;
6759
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006760 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006761 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006762 if (err < 0)
6763 return err;
6764
6765 if (err == 0)
6766 return -EINVAL;
6767
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006768 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006769 return -EINVAL;
6770
6771 if (!rdev->ops->start_radar_detection)
6772 return -EOPNOTSUPP;
6773
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006774 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6775 if (WARN_ON(!cac_time_ms))
6776 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6777
Ilan Peera1056b12015-10-22 22:27:46 +03006778 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006779 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006780 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006781 wdev->cac_started = true;
6782 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006783 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006784 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006785 return err;
6786}
6787
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006788static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6789{
6790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6791 struct net_device *dev = info->user_ptr[1];
6792 struct wireless_dev *wdev = dev->ieee80211_ptr;
6793 struct cfg80211_csa_settings params;
6794 /* csa_attrs is defined static to avoid waste of stack size - this
6795 * function is called under RTNL lock, so this should not be a problem.
6796 */
6797 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006798 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006799 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006800 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006801 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006802
6803 if (!rdev->ops->channel_switch ||
6804 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6805 return -EOPNOTSUPP;
6806
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006807 switch (dev->ieee80211_ptr->iftype) {
6808 case NL80211_IFTYPE_AP:
6809 case NL80211_IFTYPE_P2P_GO:
6810 need_new_beacon = true;
6811
6812 /* useless if AP is not running */
6813 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006814 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006815 break;
6816 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006817 if (!wdev->ssid_len)
6818 return -ENOTCONN;
6819 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006820 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006821 if (!wdev->mesh_id_len)
6822 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006823 break;
6824 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006825 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006826 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006827
6828 memset(&params, 0, sizeof(params));
6829
6830 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6831 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6832 return -EINVAL;
6833
6834 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006835 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006836 return -EINVAL;
6837
Luciano Coelho252e07c2014-10-08 09:48:34 +03006838 /* Even though the attribute is u32, the specification says
6839 * u8, so let's make sure we don't overflow.
6840 */
6841 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6842 if (cs_count > 255)
6843 return -EINVAL;
6844
6845 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006846
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006847 if (!need_new_beacon)
6848 goto skip_beacons;
6849
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006850 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6851 if (err)
6852 return err;
6853
6854 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6855 info->attrs[NL80211_ATTR_CSA_IES],
6856 nl80211_policy);
6857 if (err)
6858 return err;
6859
6860 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6861 if (err)
6862 return err;
6863
6864 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6865 return -EINVAL;
6866
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006867 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6868 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006869 return -EINVAL;
6870
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006871 params.n_counter_offsets_beacon = len / sizeof(u16);
6872 if (rdev->wiphy.max_num_csa_counters &&
6873 (params.n_counter_offsets_beacon >
6874 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006875 return -EINVAL;
6876
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006877 params.counter_offsets_beacon =
6878 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6879
6880 /* sanity checks - counters should fit and be the same */
6881 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6882 u16 offset = params.counter_offsets_beacon[i];
6883
6884 if (offset >= params.beacon_csa.tail_len)
6885 return -EINVAL;
6886
6887 if (params.beacon_csa.tail[offset] != params.count)
6888 return -EINVAL;
6889 }
6890
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006891 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006892 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6893 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006894 return -EINVAL;
6895
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006896 params.n_counter_offsets_presp = len / sizeof(u16);
6897 if (rdev->wiphy.max_num_csa_counters &&
6898 (params.n_counter_offsets_beacon >
6899 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006900 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006901
6902 params.counter_offsets_presp =
6903 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6904
6905 /* sanity checks - counters should fit and be the same */
6906 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6907 u16 offset = params.counter_offsets_presp[i];
6908
6909 if (offset >= params.beacon_csa.probe_resp_len)
6910 return -EINVAL;
6911
6912 if (params.beacon_csa.probe_resp[offset] !=
6913 params.count)
6914 return -EINVAL;
6915 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006916 }
6917
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006918skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006919 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6920 if (err)
6921 return err;
6922
Arik Nemtsov923b3522015-07-08 15:41:44 +03006923 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6924 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006925 return -EINVAL;
6926
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006927 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6928 &params.chandef,
6929 wdev->iftype);
6930 if (err < 0)
6931 return err;
6932
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006933 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006934 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006935
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006936 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6937 params.block_tx = true;
6938
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006939 wdev_lock(wdev);
6940 err = rdev_channel_switch(rdev, dev, &params);
6941 wdev_unlock(wdev);
6942
6943 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006944}
6945
Johannes Berg9720bb32011-06-21 09:45:33 +02006946static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6947 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006948 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006949 struct wireless_dev *wdev,
6950 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006951{
Johannes Berg48ab9052009-07-10 18:42:31 +02006952 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006953 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006954 void *hdr;
6955 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006956
6957 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006958
Eric W. Biederman15e47302012-09-07 20:12:54 +00006959 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006960 NL80211_CMD_NEW_SCAN_RESULTS);
6961 if (!hdr)
6962 return -1;
6963
Johannes Berg9720bb32011-06-21 09:45:33 +02006964 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6965
Johannes Berg97990a02013-04-19 01:02:55 +02006966 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6967 goto nla_put_failure;
6968 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006969 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6970 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006971 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
6972 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02006973 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006974
6975 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6976 if (!bss)
6977 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006978 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006979 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006980 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006981
6982 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006983 /* indicate whether we have probe response data or not */
6984 if (rcu_access_pointer(res->proberesp_ies) &&
6985 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6986 goto fail_unlock_rcu;
6987
6988 /* this pointer prefers to be pointed to probe response data
6989 * but is always valid
6990 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006991 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006992 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006993 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
6994 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006995 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006996 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6997 ies->len, ies->data))
6998 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006999 }
Johannes Berg0e227082014-08-12 20:34:30 +02007000
7001 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007002 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007003 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007004 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7005 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007006 goto fail_unlock_rcu;
7007 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7008 ies->len, ies->data))
7009 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007010 }
7011 rcu_read_unlock();
7012
David S. Miller9360ffd2012-03-29 04:41:26 -04007013 if (res->beacon_interval &&
7014 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7015 goto nla_put_failure;
7016 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7017 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007018 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007019 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7020 jiffies_to_msecs(jiffies - intbss->ts)))
7021 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007022
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007023 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007024 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7025 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007026 goto nla_put_failure;
7027
Johannes Berg77965c92009-02-18 18:45:06 +01007028 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007029 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007030 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7031 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007032 break;
7033 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007034 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7035 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007036 break;
7037 default:
7038 break;
7039 }
7040
Johannes Berg48ab9052009-07-10 18:42:31 +02007041 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007042 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007043 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007044 if (intbss == wdev->current_bss &&
7045 nla_put_u32(msg, NL80211_BSS_STATUS,
7046 NL80211_BSS_STATUS_ASSOCIATED))
7047 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007048 break;
7049 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007050 if (intbss == wdev->current_bss &&
7051 nla_put_u32(msg, NL80211_BSS_STATUS,
7052 NL80211_BSS_STATUS_IBSS_JOINED))
7053 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007054 break;
7055 default:
7056 break;
7057 }
7058
Johannes Berg2a519312009-02-10 21:25:55 +01007059 nla_nest_end(msg, bss);
7060
Johannes Berg053c0952015-01-16 22:09:00 +01007061 genlmsg_end(msg, hdr);
7062 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007063
Johannes Berg8cef2c92013-02-05 16:54:31 +01007064 fail_unlock_rcu:
7065 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007066 nla_put_failure:
7067 genlmsg_cancel(msg, hdr);
7068 return -EMSGSIZE;
7069}
7070
Johannes Berg97990a02013-04-19 01:02:55 +02007071static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007072{
Johannes Berg48ab9052009-07-10 18:42:31 +02007073 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007074 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007075 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007076 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007077 int err;
7078
Johannes Berg97990a02013-04-19 01:02:55 +02007079 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007080 if (err)
7081 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007082
Johannes Berg48ab9052009-07-10 18:42:31 +02007083 wdev_lock(wdev);
7084 spin_lock_bh(&rdev->bss_lock);
7085 cfg80211_bss_expire(rdev);
7086
Johannes Berg9720bb32011-06-21 09:45:33 +02007087 cb->seq = rdev->bss_generation;
7088
Johannes Berg48ab9052009-07-10 18:42:31 +02007089 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007090 if (++idx <= start)
7091 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007092 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007093 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007094 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007095 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007096 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007097 }
7098 }
7099
Johannes Berg48ab9052009-07-10 18:42:31 +02007100 spin_unlock_bh(&rdev->bss_lock);
7101 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007102
Johannes Berg97990a02013-04-19 01:02:55 +02007103 cb->args[2] = idx;
7104 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007105
Johannes Berg67748892010-10-04 21:14:06 +02007106 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007107}
7108
Eric W. Biederman15e47302012-09-07 20:12:54 +00007109static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007110 int flags, struct net_device *dev,
7111 bool allow_radio_stats,
7112 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007113{
7114 void *hdr;
7115 struct nlattr *infoattr;
7116
Johannes Berg11f78ac2014-11-14 16:43:50 +01007117 /* skip radio stats if userspace didn't request them */
7118 if (!survey->channel && !allow_radio_stats)
7119 return 0;
7120
Eric W. Biederman15e47302012-09-07 20:12:54 +00007121 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007122 NL80211_CMD_NEW_SURVEY_RESULTS);
7123 if (!hdr)
7124 return -ENOMEM;
7125
David S. Miller9360ffd2012-03-29 04:41:26 -04007126 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7127 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007128
7129 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7130 if (!infoattr)
7131 goto nla_put_failure;
7132
Johannes Berg11f78ac2014-11-14 16:43:50 +01007133 if (survey->channel &&
7134 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007135 survey->channel->center_freq))
7136 goto nla_put_failure;
7137
7138 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7139 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7140 goto nla_put_failure;
7141 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7142 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7143 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007144 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007145 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7146 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007147 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007148 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007149 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7150 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007151 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007152 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007153 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7154 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007155 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007156 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007157 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7158 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007159 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007160 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007161 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7162 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007163 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007164 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007165 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7166 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007167 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007168
7169 nla_nest_end(msg, infoattr);
7170
Johannes Berg053c0952015-01-16 22:09:00 +01007171 genlmsg_end(msg, hdr);
7172 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007173
7174 nla_put_failure:
7175 genlmsg_cancel(msg, hdr);
7176 return -EMSGSIZE;
7177}
7178
Johannes Berg11f78ac2014-11-14 16:43:50 +01007179static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007180{
7181 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007182 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007183 struct wireless_dev *wdev;
7184 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007185 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007186 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007187
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007188 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007189 if (res)
7190 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007191
Johannes Berg11f78ac2014-11-14 16:43:50 +01007192 /* prepare_wdev_dump parsed the attributes */
7193 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7194
Johannes Berg97990a02013-04-19 01:02:55 +02007195 if (!wdev->netdev) {
7196 res = -EINVAL;
7197 goto out_err;
7198 }
7199
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007200 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007201 res = -EOPNOTSUPP;
7202 goto out_err;
7203 }
7204
7205 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007206 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007207 if (res == -ENOENT)
7208 break;
7209 if (res)
7210 goto out_err;
7211
Johannes Berg11f78ac2014-11-14 16:43:50 +01007212 /* don't send disabled channels, but do send non-channel data */
7213 if (survey.channel &&
7214 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007215 survey_idx++;
7216 continue;
7217 }
7218
Holger Schurig61fa7132009-11-11 12:25:40 +01007219 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007220 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007221 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007222 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007223 goto out;
7224 survey_idx++;
7225 }
7226
7227 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007228 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007229 res = skb->len;
7230 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007231 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007232 return res;
7233}
7234
Samuel Ortizb23aa672009-07-01 21:26:54 +02007235static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7236{
7237 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7238 NL80211_WPA_VERSION_2));
7239}
7240
Jouni Malinen636a5d32009-03-19 13:39:22 +02007241static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7242{
Johannes Berg4c476992010-10-04 21:36:35 +02007243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7244 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007245 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007246 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7247 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007248 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007249 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007250 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007251
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007252 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7253 return -EINVAL;
7254
7255 if (!info->attrs[NL80211_ATTR_MAC])
7256 return -EINVAL;
7257
Jouni Malinen17780922009-03-27 20:52:47 +02007258 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7259 return -EINVAL;
7260
Johannes Berg19957bb2009-07-02 17:20:43 +02007261 if (!info->attrs[NL80211_ATTR_SSID])
7262 return -EINVAL;
7263
7264 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7265 return -EINVAL;
7266
Johannes Bergfffd0932009-07-08 14:22:54 +02007267 err = nl80211_parse_key(info, &key);
7268 if (err)
7269 return err;
7270
7271 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007272 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7273 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007274 if (!key.p.key || !key.p.key_len)
7275 return -EINVAL;
7276 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7277 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7278 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7279 key.p.key_len != WLAN_KEY_LEN_WEP104))
7280 return -EINVAL;
7281 if (key.idx > 4)
7282 return -EINVAL;
7283 } else {
7284 key.p.key_len = 0;
7285 key.p.key = NULL;
7286 }
7287
Johannes Bergafea0b72010-08-10 09:46:42 +02007288 if (key.idx >= 0) {
7289 int i;
7290 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007291
Johannes Bergafea0b72010-08-10 09:46:42 +02007292 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7293 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7294 ok = true;
7295 break;
7296 }
7297 }
Johannes Berg4c476992010-10-04 21:36:35 +02007298 if (!ok)
7299 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007300 }
7301
Johannes Berg4c476992010-10-04 21:36:35 +02007302 if (!rdev->ops->auth)
7303 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007304
Johannes Berg074ac8d2010-09-16 14:58:22 +02007305 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007306 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7307 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007308
Johannes Berg19957bb2009-07-02 17:20:43 +02007309 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007310 chan = nl80211_get_valid_chan(&rdev->wiphy,
7311 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7312 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007313 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007314
Johannes Berg19957bb2009-07-02 17:20:43 +02007315 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7316 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7317
7318 if (info->attrs[NL80211_ATTR_IE]) {
7319 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7320 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7321 }
7322
7323 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007324 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007325 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007326
Jouni Malinene39e5b52012-09-30 19:29:39 +03007327 if (auth_type == NL80211_AUTHTYPE_SAE &&
7328 !info->attrs[NL80211_ATTR_SAE_DATA])
7329 return -EINVAL;
7330
7331 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7332 if (auth_type != NL80211_AUTHTYPE_SAE)
7333 return -EINVAL;
7334 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7335 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7336 /* need to include at least Auth Transaction and Status Code */
7337 if (sae_data_len < 4)
7338 return -EINVAL;
7339 }
7340
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007341 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7342
Johannes Berg95de8172012-01-20 13:55:25 +01007343 /*
7344 * Since we no longer track auth state, ignore
7345 * requests to only change local state.
7346 */
7347 if (local_state_change)
7348 return 0;
7349
Johannes Berg91bf9b22013-05-15 17:44:01 +02007350 wdev_lock(dev->ieee80211_ptr);
7351 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7352 ssid, ssid_len, ie, ie_len,
7353 key.p.key, key.p.key_len, key.idx,
7354 sae_data, sae_data_len);
7355 wdev_unlock(dev->ieee80211_ptr);
7356 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007357}
7358
Johannes Bergc0692b82010-08-27 14:26:53 +03007359static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7360 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007361 struct cfg80211_crypto_settings *settings,
7362 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007363{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007364 memset(settings, 0, sizeof(*settings));
7365
Samuel Ortizb23aa672009-07-01 21:26:54 +02007366 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7367
Johannes Bergc0692b82010-08-27 14:26:53 +03007368 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7369 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007370
Johannes Bergc0692b82010-08-27 14:26:53 +03007371 proto = nla_get_u16(
7372 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7373 settings->control_port_ethertype = cpu_to_be16(proto);
7374 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7375 proto != ETH_P_PAE)
7376 return -EINVAL;
7377 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7378 settings->control_port_no_encrypt = true;
7379 } else
7380 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7381
Samuel Ortizb23aa672009-07-01 21:26:54 +02007382 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7383 void *data;
7384 int len, i;
7385
7386 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7387 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7388 settings->n_ciphers_pairwise = len / sizeof(u32);
7389
7390 if (len % sizeof(u32))
7391 return -EINVAL;
7392
Johannes Berg3dc27d22009-07-02 21:36:37 +02007393 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007394 return -EINVAL;
7395
7396 memcpy(settings->ciphers_pairwise, data, len);
7397
7398 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007399 if (!cfg80211_supported_cipher_suite(
7400 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007401 settings->ciphers_pairwise[i]))
7402 return -EINVAL;
7403 }
7404
7405 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7406 settings->cipher_group =
7407 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007408 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7409 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007410 return -EINVAL;
7411 }
7412
7413 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7414 settings->wpa_versions =
7415 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7416 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7417 return -EINVAL;
7418 }
7419
7420 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7421 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007422 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007423
7424 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7425 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7426 settings->n_akm_suites = len / sizeof(u32);
7427
7428 if (len % sizeof(u32))
7429 return -EINVAL;
7430
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007431 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7432 return -EINVAL;
7433
Samuel Ortizb23aa672009-07-01 21:26:54 +02007434 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007435 }
7436
7437 return 0;
7438}
7439
Jouni Malinen636a5d32009-03-19 13:39:22 +02007440static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7441{
Johannes Berg4c476992010-10-04 21:36:35 +02007442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7443 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007444 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007445 struct cfg80211_assoc_request req = {};
7446 const u8 *bssid, *ssid;
7447 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007448
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007449 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7450 return -EINVAL;
7451
7452 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007453 !info->attrs[NL80211_ATTR_SSID] ||
7454 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007455 return -EINVAL;
7456
Johannes Berg4c476992010-10-04 21:36:35 +02007457 if (!rdev->ops->assoc)
7458 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007459
Johannes Berg074ac8d2010-09-16 14:58:22 +02007460 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007461 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7462 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007463
Johannes Berg19957bb2009-07-02 17:20:43 +02007464 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007465
Jouni Malinen664834d2014-01-15 00:01:44 +02007466 chan = nl80211_get_valid_chan(&rdev->wiphy,
7467 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7468 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007469 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007470
Johannes Berg19957bb2009-07-02 17:20:43 +02007471 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7472 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007473
7474 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007475 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7476 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007477 }
7478
Jouni Malinendc6382c2009-05-06 22:09:37 +03007479 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007480 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007481 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007482 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007483 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007484 else if (mfp != NL80211_MFP_NO)
7485 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007486 }
7487
Johannes Berg3e5d7642009-07-07 14:37:26 +02007488 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007489 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007490
Ben Greear7e7c8922011-11-18 11:31:59 -08007491 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007492 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007493
7494 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007495 memcpy(&req.ht_capa_mask,
7496 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7497 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007498
7499 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007500 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007501 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007502 memcpy(&req.ht_capa,
7503 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7504 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007505 }
7506
Johannes Bergee2aca32013-02-21 17:36:01 +01007507 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007508 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007509
7510 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007511 memcpy(&req.vht_capa_mask,
7512 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7513 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007514
7515 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007516 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007517 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007518 memcpy(&req.vht_capa,
7519 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7520 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007521 }
7522
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007523 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007524 if (!((rdev->wiphy.features &
7525 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7526 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7527 !wiphy_ext_feature_isset(&rdev->wiphy,
7528 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007529 return -EINVAL;
7530 req.flags |= ASSOC_REQ_USE_RRM;
7531 }
7532
Johannes Bergf62fab72013-02-21 20:09:09 +01007533 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007534 if (!err) {
7535 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007536 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7537 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007538 wdev_unlock(dev->ieee80211_ptr);
7539 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007540
Jouni Malinen636a5d32009-03-19 13:39:22 +02007541 return err;
7542}
7543
7544static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7545{
Johannes Berg4c476992010-10-04 21:36:35 +02007546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7547 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007548 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007549 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007550 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007551 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007552
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007553 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7554 return -EINVAL;
7555
7556 if (!info->attrs[NL80211_ATTR_MAC])
7557 return -EINVAL;
7558
7559 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7560 return -EINVAL;
7561
Johannes Berg4c476992010-10-04 21:36:35 +02007562 if (!rdev->ops->deauth)
7563 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007564
Johannes Berg074ac8d2010-09-16 14:58:22 +02007565 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007566 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7567 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007568
Johannes Berg19957bb2009-07-02 17:20:43 +02007569 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007570
Johannes Berg19957bb2009-07-02 17:20:43 +02007571 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7572 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007573 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007574 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007575 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007576
7577 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007578 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7579 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007580 }
7581
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007582 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7583
Johannes Berg91bf9b22013-05-15 17:44:01 +02007584 wdev_lock(dev->ieee80211_ptr);
7585 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7586 local_state_change);
7587 wdev_unlock(dev->ieee80211_ptr);
7588 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007589}
7590
7591static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7592{
Johannes Berg4c476992010-10-04 21:36:35 +02007593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7594 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007595 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007596 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007597 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007598 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007599
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007600 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7601 return -EINVAL;
7602
7603 if (!info->attrs[NL80211_ATTR_MAC])
7604 return -EINVAL;
7605
7606 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7607 return -EINVAL;
7608
Johannes Berg4c476992010-10-04 21:36:35 +02007609 if (!rdev->ops->disassoc)
7610 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007611
Johannes Berg074ac8d2010-09-16 14:58:22 +02007612 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007613 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7614 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007615
Johannes Berg19957bb2009-07-02 17:20:43 +02007616 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007617
Johannes Berg19957bb2009-07-02 17:20:43 +02007618 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7619 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007620 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007621 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007622 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007623
7624 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007625 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7626 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007627 }
7628
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007629 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7630
Johannes Berg91bf9b22013-05-15 17:44:01 +02007631 wdev_lock(dev->ieee80211_ptr);
7632 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7633 local_state_change);
7634 wdev_unlock(dev->ieee80211_ptr);
7635 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007636}
7637
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007638static bool
7639nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007640 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007641 int rateval)
7642{
7643 struct wiphy *wiphy = &rdev->wiphy;
7644 bool found = false;
7645 int band, i;
7646
Johannes Berg57fbcce2016-04-12 15:56:15 +02007647 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007648 struct ieee80211_supported_band *sband;
7649
7650 sband = wiphy->bands[band];
7651 if (!sband)
7652 continue;
7653
7654 for (i = 0; i < sband->n_bitrates; i++) {
7655 if (sband->bitrates[i].bitrate == rateval) {
7656 mcast_rate[band] = i + 1;
7657 found = true;
7658 break;
7659 }
7660 }
7661 }
7662
7663 return found;
7664}
7665
Johannes Berg04a773a2009-04-19 21:24:32 +02007666static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7667{
Johannes Berg4c476992010-10-04 21:36:35 +02007668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7669 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007670 struct cfg80211_ibss_params ibss;
7671 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007672 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007673 int err;
7674
Johannes Berg8e30bc52009-04-22 17:45:38 +02007675 memset(&ibss, 0, sizeof(ibss));
7676
Johannes Berg04a773a2009-04-19 21:24:32 +02007677 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7678 return -EINVAL;
7679
Johannes Berg683b6d32012-11-08 21:25:48 +01007680 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007681 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7682 return -EINVAL;
7683
Johannes Berg8e30bc52009-04-22 17:45:38 +02007684 ibss.beacon_interval = 100;
7685
7686 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7687 ibss.beacon_interval =
7688 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7689 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7690 return -EINVAL;
7691 }
7692
Johannes Berg4c476992010-10-04 21:36:35 +02007693 if (!rdev->ops->join_ibss)
7694 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007695
Johannes Berg4c476992010-10-04 21:36:35 +02007696 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7697 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007698
Johannes Berg79c97e92009-07-07 03:56:12 +02007699 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007700
Johannes Berg39193492011-09-16 13:45:25 +02007701 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007702 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007703
7704 if (!is_valid_ether_addr(ibss.bssid))
7705 return -EINVAL;
7706 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007707 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7708 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7709
7710 if (info->attrs[NL80211_ATTR_IE]) {
7711 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7712 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7713 }
7714
Johannes Berg683b6d32012-11-08 21:25:48 +01007715 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7716 if (err)
7717 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007718
Ilan Peer174e0cd2014-02-23 09:13:01 +02007719 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7720 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007721 return -EINVAL;
7722
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007723 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007724 case NL80211_CHAN_WIDTH_5:
7725 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007726 case NL80211_CHAN_WIDTH_20_NOHT:
7727 break;
7728 case NL80211_CHAN_WIDTH_20:
7729 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007730 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7731 return -EINVAL;
7732 break;
7733 case NL80211_CHAN_WIDTH_80:
7734 case NL80211_CHAN_WIDTH_80P80:
7735 case NL80211_CHAN_WIDTH_160:
7736 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7737 return -EINVAL;
7738 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7739 NL80211_EXT_FEATURE_VHT_IBSS))
7740 return -EINVAL;
7741 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007742 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007743 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007744 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007745
Johannes Berg04a773a2009-04-19 21:24:32 +02007746 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007747 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007748
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007749 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7750 u8 *rates =
7751 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7752 int n_rates =
7753 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7754 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007755 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007756
Johannes Berg34850ab2011-07-18 18:08:35 +02007757 err = ieee80211_get_ratemask(sband, rates, n_rates,
7758 &ibss.basic_rates);
7759 if (err)
7760 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007761 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007762
Simon Wunderlich803768f2013-06-28 10:39:58 +02007763 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7764 memcpy(&ibss.ht_capa_mask,
7765 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7766 sizeof(ibss.ht_capa_mask));
7767
7768 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7769 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7770 return -EINVAL;
7771 memcpy(&ibss.ht_capa,
7772 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7773 sizeof(ibss.ht_capa));
7774 }
7775
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007776 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7777 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7778 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7779 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007780
Johannes Berg4c476992010-10-04 21:36:35 +02007781 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307782 bool no_ht = false;
7783
Johannes Berg4c476992010-10-04 21:36:35 +02007784 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307785 info->attrs[NL80211_ATTR_KEYS],
7786 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007787 if (IS_ERR(connkeys))
7788 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307789
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007790 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7791 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007792 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307793 return -EINVAL;
7794 }
Johannes Berg4c476992010-10-04 21:36:35 +02007795 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007796
Antonio Quartulli267335d2012-01-31 20:25:47 +01007797 ibss.control_port =
7798 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7799
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007800 ibss.userspace_handles_dfs =
7801 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7802
Johannes Berg4c476992010-10-04 21:36:35 +02007803 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007804 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007805 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007806 return err;
7807}
7808
7809static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7810{
Johannes Berg4c476992010-10-04 21:36:35 +02007811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7812 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007813
Johannes Berg4c476992010-10-04 21:36:35 +02007814 if (!rdev->ops->leave_ibss)
7815 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007816
Johannes Berg4c476992010-10-04 21:36:35 +02007817 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7818 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007819
Johannes Berg4c476992010-10-04 21:36:35 +02007820 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007821}
7822
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007823static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7824{
7825 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7826 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007827 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007828 u32 nla_rate;
7829 int err;
7830
7831 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007832 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7833 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007834 return -EOPNOTSUPP;
7835
7836 if (!rdev->ops->set_mcast_rate)
7837 return -EOPNOTSUPP;
7838
7839 memset(mcast_rate, 0, sizeof(mcast_rate));
7840
7841 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7842 return -EINVAL;
7843
7844 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7845 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7846 return -EINVAL;
7847
Ilan Peera1056b12015-10-22 22:27:46 +03007848 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007849
7850 return err;
7851}
7852
Johannes Bergad7e7182013-11-13 13:37:47 +01007853static struct sk_buff *
7854__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007855 struct wireless_dev *wdev, int approxlen,
7856 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007857 enum nl80211_attrs attr,
7858 const struct nl80211_vendor_cmd_info *info,
7859 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007860{
7861 struct sk_buff *skb;
7862 void *hdr;
7863 struct nlattr *data;
7864
7865 skb = nlmsg_new(approxlen + 100, gfp);
7866 if (!skb)
7867 return NULL;
7868
7869 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7870 if (!hdr) {
7871 kfree_skb(skb);
7872 return NULL;
7873 }
7874
7875 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7876 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007877
7878 if (info) {
7879 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7880 info->vendor_id))
7881 goto nla_put_failure;
7882 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7883 info->subcmd))
7884 goto nla_put_failure;
7885 }
7886
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007887 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007888 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7889 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007890 goto nla_put_failure;
7891 if (wdev->netdev &&
7892 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7893 wdev->netdev->ifindex))
7894 goto nla_put_failure;
7895 }
7896
Johannes Bergad7e7182013-11-13 13:37:47 +01007897 data = nla_nest_start(skb, attr);
7898
7899 ((void **)skb->cb)[0] = rdev;
7900 ((void **)skb->cb)[1] = hdr;
7901 ((void **)skb->cb)[2] = data;
7902
7903 return skb;
7904
7905 nla_put_failure:
7906 kfree_skb(skb);
7907 return NULL;
7908}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007909
Johannes Berge03ad6e2014-01-01 17:22:30 +01007910struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007911 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007912 enum nl80211_commands cmd,
7913 enum nl80211_attrs attr,
7914 int vendor_event_idx,
7915 int approxlen, gfp_t gfp)
7916{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007917 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007918 const struct nl80211_vendor_cmd_info *info;
7919
7920 switch (cmd) {
7921 case NL80211_CMD_TESTMODE:
7922 if (WARN_ON(vendor_event_idx != -1))
7923 return NULL;
7924 info = NULL;
7925 break;
7926 case NL80211_CMD_VENDOR:
7927 if (WARN_ON(vendor_event_idx < 0 ||
7928 vendor_event_idx >= wiphy->n_vendor_events))
7929 return NULL;
7930 info = &wiphy->vendor_events[vendor_event_idx];
7931 break;
7932 default:
7933 WARN_ON(1);
7934 return NULL;
7935 }
7936
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007937 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007938 cmd, attr, info, gfp);
7939}
7940EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7941
7942void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7943{
7944 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7945 void *hdr = ((void **)skb->cb)[1];
7946 struct nlattr *data = ((void **)skb->cb)[2];
7947 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7948
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007949 /* clear CB data for netlink core to own from now on */
7950 memset(skb->cb, 0, sizeof(skb->cb));
7951
Johannes Berge03ad6e2014-01-01 17:22:30 +01007952 nla_nest_end(skb, data);
7953 genlmsg_end(skb, hdr);
7954
7955 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7956 mcgrp = NL80211_MCGRP_VENDOR;
7957
7958 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7959 mcgrp, gfp);
7960}
7961EXPORT_SYMBOL(__cfg80211_send_event_skb);
7962
Johannes Bergaff89a92009-07-01 21:26:51 +02007963#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007964static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7965{
Johannes Berg4c476992010-10-04 21:36:35 +02007966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007967 struct wireless_dev *wdev =
7968 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007969 int err;
7970
David Spinadelfc73f112013-07-31 18:04:15 +03007971 if (!rdev->ops->testmode_cmd)
7972 return -EOPNOTSUPP;
7973
7974 if (IS_ERR(wdev)) {
7975 err = PTR_ERR(wdev);
7976 if (err != -EINVAL)
7977 return err;
7978 wdev = NULL;
7979 } else if (wdev->wiphy != &rdev->wiphy) {
7980 return -EINVAL;
7981 }
7982
Johannes Bergaff89a92009-07-01 21:26:51 +02007983 if (!info->attrs[NL80211_ATTR_TESTDATA])
7984 return -EINVAL;
7985
Johannes Bergad7e7182013-11-13 13:37:47 +01007986 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007987 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007988 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7989 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007990 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007991
Johannes Bergaff89a92009-07-01 21:26:51 +02007992 return err;
7993}
7994
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007995static int nl80211_testmode_dump(struct sk_buff *skb,
7996 struct netlink_callback *cb)
7997{
Johannes Berg00918d32011-12-13 17:22:05 +01007998 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007999 int err;
8000 long phy_idx;
8001 void *data = NULL;
8002 int data_len = 0;
8003
Johannes Berg5fe231e2013-05-08 21:45:15 +02008004 rtnl_lock();
8005
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008006 if (cb->args[0]) {
8007 /*
8008 * 0 is a valid index, but not valid for args[0],
8009 * so we need to offset by 1.
8010 */
8011 phy_idx = cb->args[0] - 1;
8012 } else {
8013 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8014 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8015 nl80211_policy);
8016 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008017 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008018
Johannes Berg2bd7e352012-06-15 14:23:16 +02008019 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8020 nl80211_fam.attrbuf);
8021 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008022 err = PTR_ERR(rdev);
8023 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008024 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008025 phy_idx = rdev->wiphy_idx;
8026 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008027
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008028 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8029 cb->args[1] =
8030 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8031 }
8032
8033 if (cb->args[1]) {
8034 data = nla_data((void *)cb->args[1]);
8035 data_len = nla_len((void *)cb->args[1]);
8036 }
8037
Johannes Berg00918d32011-12-13 17:22:05 +01008038 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8039 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008040 err = -ENOENT;
8041 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008042 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008043
Johannes Berg00918d32011-12-13 17:22:05 +01008044 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008045 err = -EOPNOTSUPP;
8046 goto out_err;
8047 }
8048
8049 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008050 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008051 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8052 NL80211_CMD_TESTMODE);
8053 struct nlattr *tmdata;
8054
Dan Carpentercb35fba2013-08-14 14:50:01 +03008055 if (!hdr)
8056 break;
8057
David S. Miller9360ffd2012-03-29 04:41:26 -04008058 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008059 genlmsg_cancel(skb, hdr);
8060 break;
8061 }
8062
8063 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8064 if (!tmdata) {
8065 genlmsg_cancel(skb, hdr);
8066 break;
8067 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008068 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008069 nla_nest_end(skb, tmdata);
8070
8071 if (err == -ENOBUFS || err == -ENOENT) {
8072 genlmsg_cancel(skb, hdr);
8073 break;
8074 } else if (err) {
8075 genlmsg_cancel(skb, hdr);
8076 goto out_err;
8077 }
8078
8079 genlmsg_end(skb, hdr);
8080 }
8081
8082 err = skb->len;
8083 /* see above */
8084 cb->args[0] = phy_idx + 1;
8085 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008086 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008087 return err;
8088}
Johannes Bergaff89a92009-07-01 21:26:51 +02008089#endif
8090
Samuel Ortizb23aa672009-07-01 21:26:54 +02008091static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8092{
Johannes Berg4c476992010-10-04 21:36:35 +02008093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8094 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008095 struct cfg80211_connect_params connect;
8096 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008097 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008098 int err;
8099
8100 memset(&connect, 0, sizeof(connect));
8101
8102 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8103 return -EINVAL;
8104
8105 if (!info->attrs[NL80211_ATTR_SSID] ||
8106 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8107 return -EINVAL;
8108
8109 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8110 connect.auth_type =
8111 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008112 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8113 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008114 return -EINVAL;
8115 } else
8116 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8117
8118 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8119
Johannes Bergc0692b82010-08-27 14:26:53 +03008120 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008121 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008122 if (err)
8123 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008124
Johannes Berg074ac8d2010-09-16 14:58:22 +02008125 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008126 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8127 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008128
Johannes Berg79c97e92009-07-07 03:56:12 +02008129 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008130
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308131 connect.bg_scan_period = -1;
8132 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8133 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8134 connect.bg_scan_period =
8135 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8136 }
8137
Samuel Ortizb23aa672009-07-01 21:26:54 +02008138 if (info->attrs[NL80211_ATTR_MAC])
8139 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008140 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8141 connect.bssid_hint =
8142 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008143 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8144 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8145
8146 if (info->attrs[NL80211_ATTR_IE]) {
8147 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8148 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8149 }
8150
Jouni Malinencee00a92013-01-15 17:15:57 +02008151 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8152 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8153 if (connect.mfp != NL80211_MFP_REQUIRED &&
8154 connect.mfp != NL80211_MFP_NO)
8155 return -EINVAL;
8156 } else {
8157 connect.mfp = NL80211_MFP_NO;
8158 }
8159
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008160 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8161 connect.prev_bssid =
8162 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8163
Samuel Ortizb23aa672009-07-01 21:26:54 +02008164 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008165 connect.channel = nl80211_get_valid_chan(
8166 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8167 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008168 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008169 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008170 connect.channel_hint = nl80211_get_valid_chan(
8171 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8172 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008173 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008174 }
8175
Johannes Bergfffd0932009-07-08 14:22:54 +02008176 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8177 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308178 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008179 if (IS_ERR(connkeys))
8180 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008181 }
8182
Ben Greear7e7c8922011-11-18 11:31:59 -08008183 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8184 connect.flags |= ASSOC_REQ_DISABLE_HT;
8185
8186 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8187 memcpy(&connect.ht_capa_mask,
8188 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8189 sizeof(connect.ht_capa_mask));
8190
8191 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008192 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008193 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008194 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008195 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008196 memcpy(&connect.ht_capa,
8197 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8198 sizeof(connect.ht_capa));
8199 }
8200
Johannes Bergee2aca32013-02-21 17:36:01 +01008201 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8202 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8203
8204 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8205 memcpy(&connect.vht_capa_mask,
8206 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8207 sizeof(connect.vht_capa_mask));
8208
8209 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8210 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008211 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008212 return -EINVAL;
8213 }
8214 memcpy(&connect.vht_capa,
8215 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8216 sizeof(connect.vht_capa));
8217 }
8218
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008219 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008220 if (!((rdev->wiphy.features &
8221 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8222 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8223 !wiphy_ext_feature_isset(&rdev->wiphy,
8224 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008225 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008226 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008227 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008228 connect.flags |= ASSOC_REQ_USE_RRM;
8229 }
8230
Lior David34d50512016-01-28 10:58:25 +02008231 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008232 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008233 kzfree(connkeys);
8234 return -EOPNOTSUPP;
8235 }
8236
Arend van Spriel38de03d2016-03-02 20:37:18 +01008237 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8238 /* bss selection makes no sense if bssid is set */
8239 if (connect.bssid) {
8240 kzfree(connkeys);
8241 return -EINVAL;
8242 }
8243
8244 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8245 wiphy, &connect.bss_select);
8246 if (err) {
8247 kzfree(connkeys);
8248 return err;
8249 }
8250 }
8251
Johannes Berg83739b02013-05-15 17:44:01 +02008252 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008253 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8254 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008255 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008256 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008257 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008258 return err;
8259}
8260
8261static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8262{
Johannes Berg4c476992010-10-04 21:36:35 +02008263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8264 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008265 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008266 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008267
8268 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8269 reason = WLAN_REASON_DEAUTH_LEAVING;
8270 else
8271 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8272
8273 if (reason == 0)
8274 return -EINVAL;
8275
Johannes Berg074ac8d2010-09-16 14:58:22 +02008276 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008277 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8278 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008279
Johannes Berg83739b02013-05-15 17:44:01 +02008280 wdev_lock(dev->ieee80211_ptr);
8281 ret = cfg80211_disconnect(rdev, dev, reason, true);
8282 wdev_unlock(dev->ieee80211_ptr);
8283 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008284}
8285
Johannes Berg463d0182009-07-14 00:33:35 +02008286static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8287{
Johannes Berg4c476992010-10-04 21:36:35 +02008288 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008289 struct net *net;
8290 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008291
Vadim Kochan4b681c82015-01-12 16:34:05 +02008292 if (info->attrs[NL80211_ATTR_PID]) {
8293 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8294
8295 net = get_net_ns_by_pid(pid);
8296 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8297 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8298
8299 net = get_net_ns_by_fd(fd);
8300 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008301 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008302 }
Johannes Berg463d0182009-07-14 00:33:35 +02008303
Johannes Berg4c476992010-10-04 21:36:35 +02008304 if (IS_ERR(net))
8305 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008306
8307 err = 0;
8308
8309 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008310 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8311 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008312
Johannes Berg463d0182009-07-14 00:33:35 +02008313 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008314 return err;
8315}
8316
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008317static int nl80211_setdel_pmksa(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];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008320 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8321 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008322 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008323 struct cfg80211_pmksa pmksa;
8324
8325 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8326
8327 if (!info->attrs[NL80211_ATTR_MAC])
8328 return -EINVAL;
8329
8330 if (!info->attrs[NL80211_ATTR_PMKID])
8331 return -EINVAL;
8332
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008333 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8334 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8335
Johannes Berg074ac8d2010-09-16 14:58:22 +02008336 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008337 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8338 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008339
8340 switch (info->genlhdr->cmd) {
8341 case NL80211_CMD_SET_PMKSA:
8342 rdev_ops = rdev->ops->set_pmksa;
8343 break;
8344 case NL80211_CMD_DEL_PMKSA:
8345 rdev_ops = rdev->ops->del_pmksa;
8346 break;
8347 default:
8348 WARN_ON(1);
8349 break;
8350 }
8351
Johannes Berg4c476992010-10-04 21:36:35 +02008352 if (!rdev_ops)
8353 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008354
Johannes Berg4c476992010-10-04 21:36:35 +02008355 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008356}
8357
8358static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8359{
Johannes Berg4c476992010-10-04 21:36:35 +02008360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8361 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008362
Johannes Berg074ac8d2010-09-16 14:58:22 +02008363 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008364 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8365 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008366
Johannes Berg4c476992010-10-04 21:36:35 +02008367 if (!rdev->ops->flush_pmksa)
8368 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008369
Hila Gonene35e4d22012-06-27 17:19:42 +03008370 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008371}
8372
Arik Nemtsov109086c2011-09-28 14:12:50 +03008373static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8374{
8375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8376 struct net_device *dev = info->user_ptr[1];
8377 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308378 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008379 u16 status_code;
8380 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008381 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008382
8383 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8384 !rdev->ops->tdls_mgmt)
8385 return -EOPNOTSUPP;
8386
8387 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8388 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8389 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8390 !info->attrs[NL80211_ATTR_IE] ||
8391 !info->attrs[NL80211_ATTR_MAC])
8392 return -EINVAL;
8393
8394 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8395 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8396 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8397 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008398 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308399 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8400 peer_capability =
8401 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008402
Hila Gonene35e4d22012-06-27 17:19:42 +03008403 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308404 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008405 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008406 nla_data(info->attrs[NL80211_ATTR_IE]),
8407 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008408}
8409
8410static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8411{
8412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8413 struct net_device *dev = info->user_ptr[1];
8414 enum nl80211_tdls_operation operation;
8415 u8 *peer;
8416
8417 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8418 !rdev->ops->tdls_oper)
8419 return -EOPNOTSUPP;
8420
8421 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8422 !info->attrs[NL80211_ATTR_MAC])
8423 return -EINVAL;
8424
8425 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8426 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8427
Hila Gonene35e4d22012-06-27 17:19:42 +03008428 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008429}
8430
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008431static int nl80211_remain_on_channel(struct sk_buff *skb,
8432 struct genl_info *info)
8433{
Johannes Berg4c476992010-10-04 21:36:35 +02008434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008435 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008436 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008437 struct sk_buff *msg;
8438 void *hdr;
8439 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008440 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008441 int err;
8442
8443 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8444 !info->attrs[NL80211_ATTR_DURATION])
8445 return -EINVAL;
8446
8447 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8448
Johannes Berg7c4ef712011-11-18 15:33:48 +01008449 if (!rdev->ops->remain_on_channel ||
8450 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008451 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008452
Johannes Bergebf348f2012-06-01 12:50:54 +02008453 /*
8454 * We should be on that channel for at least a minimum amount of
8455 * time (10ms) but no longer than the driver supports.
8456 */
8457 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8458 duration > rdev->wiphy.max_remain_on_channel_duration)
8459 return -EINVAL;
8460
Johannes Berg683b6d32012-11-08 21:25:48 +01008461 err = nl80211_parse_chandef(rdev, info, &chandef);
8462 if (err)
8463 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008464
8465 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008466 if (!msg)
8467 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008468
Eric W. Biederman15e47302012-09-07 20:12:54 +00008469 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008470 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008471 if (!hdr) {
8472 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008473 goto free_msg;
8474 }
8475
Johannes Berg683b6d32012-11-08 21:25:48 +01008476 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8477 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008478
8479 if (err)
8480 goto free_msg;
8481
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008482 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8483 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008484 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008485
8486 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008487
8488 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008489
8490 nla_put_failure:
8491 err = -ENOBUFS;
8492 free_msg:
8493 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008494 return err;
8495}
8496
8497static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8498 struct genl_info *info)
8499{
Johannes Berg4c476992010-10-04 21:36:35 +02008500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008501 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008502 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008503
8504 if (!info->attrs[NL80211_ATTR_COOKIE])
8505 return -EINVAL;
8506
Johannes Berg4c476992010-10-04 21:36:35 +02008507 if (!rdev->ops->cancel_remain_on_channel)
8508 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008509
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008510 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8511
Hila Gonene35e4d22012-06-27 17:19:42 +03008512 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008513}
8514
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008515static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8516 u8 *rates, u8 rates_len)
8517{
8518 u8 i;
8519 u32 mask = 0;
8520
8521 for (i = 0; i < rates_len; i++) {
8522 int rate = (rates[i] & 0x7f) * 5;
8523 int ridx;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008524
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008525 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8526 struct ieee80211_rate *srate =
8527 &sband->bitrates[ridx];
8528 if (rate == srate->bitrate) {
8529 mask |= 1 << ridx;
8530 break;
8531 }
8532 }
8533 if (ridx == sband->n_bitrates)
8534 return 0; /* rate not found */
8535 }
8536
8537 return mask;
8538}
8539
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008540static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8541 u8 *rates, u8 rates_len,
8542 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8543{
8544 u8 i;
8545
8546 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8547
8548 for (i = 0; i < rates_len; i++) {
8549 int ridx, rbit;
8550
8551 ridx = rates[i] / 8;
8552 rbit = BIT(rates[i] % 8);
8553
8554 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008555 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008556 return false;
8557
8558 /* check availability */
8559 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8560 mcs[ridx] |= rbit;
8561 else
8562 return false;
8563 }
8564
8565 return true;
8566}
8567
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008568static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8569{
8570 u16 mcs_mask = 0;
8571
8572 switch (vht_mcs_map) {
8573 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8574 break;
8575 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8576 mcs_mask = 0x00FF;
8577 break;
8578 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8579 mcs_mask = 0x01FF;
8580 break;
8581 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8582 mcs_mask = 0x03FF;
8583 break;
8584 default:
8585 break;
8586 }
8587
8588 return mcs_mask;
8589}
8590
8591static void vht_build_mcs_mask(u16 vht_mcs_map,
8592 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8593{
8594 u8 nss;
8595
8596 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8597 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8598 vht_mcs_map >>= 2;
8599 }
8600}
8601
8602static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8603 struct nl80211_txrate_vht *txrate,
8604 u16 mcs[NL80211_VHT_NSS_MAX])
8605{
8606 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8607 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8608 u8 i;
8609
8610 if (!sband->vht_cap.vht_supported)
8611 return false;
8612
8613 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8614
8615 /* Build vht_mcs_mask from VHT capabilities */
8616 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8617
8618 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8619 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8620 mcs[i] = txrate->mcs[i];
8621 else
8622 return false;
8623 }
8624
8625 return true;
8626}
8627
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008628static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008629 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8630 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008631 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8632 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008633 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008634 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008635};
8636
8637static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8638 struct genl_info *info)
8639{
8640 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008642 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008643 int rem, i;
8644 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008645 struct nlattr *tx_rates;
8646 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008647 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008648
Johannes Berg4c476992010-10-04 21:36:35 +02008649 if (!rdev->ops->set_bitrate_mask)
8650 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008651
8652 memset(&mask, 0, sizeof(mask));
8653 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008654 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008655 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008656
8657 if (!sband)
8658 continue;
8659
8660 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008661 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008662 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008663 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008664
8665 if (!sband->vht_cap.vht_supported)
8666 continue;
8667
8668 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8669 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008670 }
8671
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008672 /* if no rates are given set it back to the defaults */
8673 if (!info->attrs[NL80211_ATTR_TX_RATES])
8674 goto out;
8675
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008676 /*
8677 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008678 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008679 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008680 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008681 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008682 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008683 int err;
8684
Johannes Berg57fbcce2016-04-12 15:56:15 +02008685 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008686 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008687 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008688 if (sband == NULL)
8689 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008690 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8691 nla_len(tx_rates), nl80211_txattr_policy);
8692 if (err)
8693 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008694 if (tb[NL80211_TXRATE_LEGACY]) {
8695 mask.control[band].legacy = rateset_to_mask(
8696 sband,
8697 nla_data(tb[NL80211_TXRATE_LEGACY]),
8698 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308699 if ((mask.control[band].legacy == 0) &&
8700 nla_len(tb[NL80211_TXRATE_LEGACY]))
8701 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008702 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008703 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008704 if (!ht_rateset_to_mask(
8705 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008706 nla_data(tb[NL80211_TXRATE_HT]),
8707 nla_len(tb[NL80211_TXRATE_HT]),
8708 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008709 return -EINVAL;
8710 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008711 if (tb[NL80211_TXRATE_VHT]) {
8712 if (!vht_set_mcs_mask(
8713 sband,
8714 nla_data(tb[NL80211_TXRATE_VHT]),
8715 mask.control[band].vht_mcs))
8716 return -EINVAL;
8717 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008718 if (tb[NL80211_TXRATE_GI]) {
8719 mask.control[band].gi =
8720 nla_get_u8(tb[NL80211_TXRATE_GI]);
8721 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8722 return -EINVAL;
8723 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008724
8725 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008726 /* don't allow empty legacy rates if HT or VHT
8727 * are not even supported.
8728 */
8729 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8730 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008731 return -EINVAL;
8732
8733 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008734 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008735 goto out;
8736
8737 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8738 if (mask.control[band].vht_mcs[i])
8739 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008740
8741 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008742 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008743 }
8744 }
8745
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008746out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008747 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008748}
8749
Johannes Berg2e161f72010-08-12 15:38:38 +02008750static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008751{
Johannes Berg4c476992010-10-04 21:36:35 +02008752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008753 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008754 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008755
8756 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8757 return -EINVAL;
8758
Johannes Berg2e161f72010-08-12 15:38:38 +02008759 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8760 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008761
Johannes Berg71bbc992012-06-15 15:30:18 +02008762 switch (wdev->iftype) {
8763 case NL80211_IFTYPE_STATION:
8764 case NL80211_IFTYPE_ADHOC:
8765 case NL80211_IFTYPE_P2P_CLIENT:
8766 case NL80211_IFTYPE_AP:
8767 case NL80211_IFTYPE_AP_VLAN:
8768 case NL80211_IFTYPE_MESH_POINT:
8769 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008770 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008771 break;
8772 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008773 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008774 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008775
8776 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008777 if (!rdev->ops->mgmt_tx)
8778 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008779
Eric W. Biederman15e47302012-09-07 20:12:54 +00008780 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008781 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8782 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008783}
8784
Johannes Berg2e161f72010-08-12 15:38:38 +02008785static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008786{
Johannes Berg4c476992010-10-04 21:36:35 +02008787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008788 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008789 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008790 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008791 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008792 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008793 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008794 struct cfg80211_mgmt_tx_params params = {
8795 .dont_wait_for_ack =
8796 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8797 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008798
Johannes Berg683b6d32012-11-08 21:25:48 +01008799 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008800 return -EINVAL;
8801
Johannes Berg4c476992010-10-04 21:36:35 +02008802 if (!rdev->ops->mgmt_tx)
8803 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008804
Johannes Berg71bbc992012-06-15 15:30:18 +02008805 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008806 case NL80211_IFTYPE_P2P_DEVICE:
8807 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8808 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008809 case NL80211_IFTYPE_STATION:
8810 case NL80211_IFTYPE_ADHOC:
8811 case NL80211_IFTYPE_P2P_CLIENT:
8812 case NL80211_IFTYPE_AP:
8813 case NL80211_IFTYPE_AP_VLAN:
8814 case NL80211_IFTYPE_MESH_POINT:
8815 case NL80211_IFTYPE_P2P_GO:
8816 break;
8817 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008818 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008819 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008820
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008821 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008822 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008823 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008824 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008825
8826 /*
8827 * We should wait on the channel for at least a minimum amount
8828 * of time (10ms) but no longer than the driver supports.
8829 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008830 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8831 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008832 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008833 }
8834
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008835 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008836
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008837 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008838 return -EINVAL;
8839
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008840 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308841
Antonio Quartulliea141b752013-06-11 14:20:03 +02008842 /* get the channel if any has been specified, otherwise pass NULL to
8843 * the driver. The latter will use the current one
8844 */
8845 chandef.chan = NULL;
8846 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8847 err = nl80211_parse_chandef(rdev, info, &chandef);
8848 if (err)
8849 return err;
8850 }
8851
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008852 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008853 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008854
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008855 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8856 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8857
8858 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8859 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8860 int i;
8861
8862 if (len % sizeof(u16))
8863 return -EINVAL;
8864
8865 params.n_csa_offsets = len / sizeof(u16);
8866 params.csa_offsets =
8867 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8868
8869 /* check that all the offsets fit the frame */
8870 for (i = 0; i < params.n_csa_offsets; i++) {
8871 if (params.csa_offsets[i] >= params.len)
8872 return -EINVAL;
8873 }
8874 }
8875
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008876 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008877 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8878 if (!msg)
8879 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008880
Eric W. Biederman15e47302012-09-07 20:12:54 +00008881 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008882 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008883 if (!hdr) {
8884 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008885 goto free_msg;
8886 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008887 }
Johannes Berge247bd902011-11-04 11:18:21 +01008888
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008889 params.chan = chandef.chan;
8890 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008891 if (err)
8892 goto free_msg;
8893
Johannes Berge247bd902011-11-04 11:18:21 +01008894 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008895 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8896 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008897 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008898
Johannes Berge247bd902011-11-04 11:18:21 +01008899 genlmsg_end(msg, hdr);
8900 return genlmsg_reply(msg, info);
8901 }
8902
8903 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008904
8905 nla_put_failure:
8906 err = -ENOBUFS;
8907 free_msg:
8908 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008909 return err;
8910}
8911
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008912static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8913{
8914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008915 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008916 u64 cookie;
8917
8918 if (!info->attrs[NL80211_ATTR_COOKIE])
8919 return -EINVAL;
8920
8921 if (!rdev->ops->mgmt_tx_cancel_wait)
8922 return -EOPNOTSUPP;
8923
Johannes Berg71bbc992012-06-15 15:30:18 +02008924 switch (wdev->iftype) {
8925 case NL80211_IFTYPE_STATION:
8926 case NL80211_IFTYPE_ADHOC:
8927 case NL80211_IFTYPE_P2P_CLIENT:
8928 case NL80211_IFTYPE_AP:
8929 case NL80211_IFTYPE_AP_VLAN:
8930 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008931 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008932 break;
8933 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008934 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008935 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008936
8937 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8938
Hila Gonene35e4d22012-06-27 17:19:42 +03008939 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008940}
8941
Kalle Valoffb9eb32010-02-17 17:58:10 +02008942static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8943{
Johannes Berg4c476992010-10-04 21:36:35 +02008944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008945 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008946 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008947 u8 ps_state;
8948 bool state;
8949 int err;
8950
Johannes Berg4c476992010-10-04 21:36:35 +02008951 if (!info->attrs[NL80211_ATTR_PS_STATE])
8952 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008953
8954 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8955
Johannes Berg4c476992010-10-04 21:36:35 +02008956 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8957 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008958
8959 wdev = dev->ieee80211_ptr;
8960
Johannes Berg4c476992010-10-04 21:36:35 +02008961 if (!rdev->ops->set_power_mgmt)
8962 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008963
8964 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8965
8966 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008967 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008968
Hila Gonene35e4d22012-06-27 17:19:42 +03008969 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008970 if (!err)
8971 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008972 return err;
8973}
8974
8975static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8976{
Johannes Berg4c476992010-10-04 21:36:35 +02008977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008978 enum nl80211_ps_state ps_state;
8979 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008980 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008981 struct sk_buff *msg;
8982 void *hdr;
8983 int err;
8984
Kalle Valoffb9eb32010-02-17 17:58:10 +02008985 wdev = dev->ieee80211_ptr;
8986
Johannes Berg4c476992010-10-04 21:36:35 +02008987 if (!rdev->ops->set_power_mgmt)
8988 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008989
8990 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008991 if (!msg)
8992 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008993
Eric W. Biederman15e47302012-09-07 20:12:54 +00008994 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008995 NL80211_CMD_GET_POWER_SAVE);
8996 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008997 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008998 goto free_msg;
8999 }
9000
9001 if (wdev->ps)
9002 ps_state = NL80211_PS_ENABLED;
9003 else
9004 ps_state = NL80211_PS_DISABLED;
9005
David S. Miller9360ffd2012-03-29 04:41:26 -04009006 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9007 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009008
9009 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009010 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009011
Johannes Berg4c476992010-10-04 21:36:35 +02009012 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009013 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009014 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009015 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009016 return err;
9017}
9018
Johannes Berg94e860f2014-01-20 23:58:15 +01009019static const struct nla_policy
9020nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009021 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9022 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9023 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009024 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9025 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9026 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009027};
9028
Thomas Pedersen84f10702012-07-12 16:17:33 -07009029static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009030 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009031{
9032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009033 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009034 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009035
Johannes Bergd9d8b012012-11-26 12:51:52 +01009036 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009037 return -EINVAL;
9038
Thomas Pedersen84f10702012-07-12 16:17:33 -07009039 if (!rdev->ops->set_cqm_txe_config)
9040 return -EOPNOTSUPP;
9041
9042 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9043 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9044 return -EOPNOTSUPP;
9045
Hila Gonene35e4d22012-06-27 17:19:42 +03009046 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009047}
9048
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009049static int nl80211_set_cqm_rssi(struct genl_info *info,
9050 s32 threshold, u32 hysteresis)
9051{
Johannes Berg4c476992010-10-04 21:36:35 +02009052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009053 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009054 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009055
9056 if (threshold > 0)
9057 return -EINVAL;
9058
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009059 /* disabling - hysteresis should also be zero then */
9060 if (threshold == 0)
9061 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009062
Johannes Berg4c476992010-10-04 21:36:35 +02009063 if (!rdev->ops->set_cqm_rssi_config)
9064 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009065
Johannes Berg074ac8d2010-09-16 14:58:22 +02009066 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009067 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9068 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009069
Hila Gonene35e4d22012-06-27 17:19:42 +03009070 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009071}
9072
9073static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9074{
9075 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9076 struct nlattr *cqm;
9077 int err;
9078
9079 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009080 if (!cqm)
9081 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009082
9083 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9084 nl80211_attr_cqm_policy);
9085 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009086 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009087
9088 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9089 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009090 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9091 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009092
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009093 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9094 }
9095
9096 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9097 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9098 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9099 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9100 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9101 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9102
9103 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9104 }
9105
9106 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009107}
9108
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009109static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9110{
9111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9112 struct net_device *dev = info->user_ptr[1];
9113 struct ocb_setup setup = {};
9114 int err;
9115
9116 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9117 if (err)
9118 return err;
9119
9120 return cfg80211_join_ocb(rdev, dev, &setup);
9121}
9122
9123static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9124{
9125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9126 struct net_device *dev = info->user_ptr[1];
9127
9128 return cfg80211_leave_ocb(rdev, dev);
9129}
9130
Johannes Berg29cbe682010-12-03 09:20:44 +01009131static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9132{
9133 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9134 struct net_device *dev = info->user_ptr[1];
9135 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009136 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009137 int err;
9138
9139 /* start with default */
9140 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009141 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009142
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009143 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009144 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009145 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009146 if (err)
9147 return err;
9148 }
9149
9150 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9151 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9152 return -EINVAL;
9153
Javier Cardonac80d5452010-12-16 17:37:49 -08009154 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9155 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9156
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009157 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9158 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9159 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9160 return -EINVAL;
9161
Marco Porsch9bdbf042013-01-07 16:04:51 +01009162 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9163 setup.beacon_interval =
9164 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9165 if (setup.beacon_interval < 10 ||
9166 setup.beacon_interval > 10000)
9167 return -EINVAL;
9168 }
9169
9170 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9171 setup.dtim_period =
9172 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9173 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9174 return -EINVAL;
9175 }
9176
Javier Cardonac80d5452010-12-16 17:37:49 -08009177 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9178 /* parse additional setup parameters if given */
9179 err = nl80211_parse_mesh_setup(info, &setup);
9180 if (err)
9181 return err;
9182 }
9183
Thomas Pedersend37bb182013-03-04 13:06:13 -08009184 if (setup.user_mpm)
9185 cfg.auto_open_plinks = false;
9186
Johannes Bergcc1d2802012-05-16 23:50:20 +02009187 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009188 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9189 if (err)
9190 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009191 } else {
9192 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009193 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009194 }
9195
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009196 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9197 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9198 int n_rates =
9199 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9200 struct ieee80211_supported_band *sband;
9201
9202 if (!setup.chandef.chan)
9203 return -EINVAL;
9204
9205 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9206
9207 err = ieee80211_get_ratemask(sband, rates, n_rates,
9208 &setup.basic_rates);
9209 if (err)
9210 return err;
9211 }
9212
Javier Cardonac80d5452010-12-16 17:37:49 -08009213 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009214}
9215
9216static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9217{
9218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9219 struct net_device *dev = info->user_ptr[1];
9220
9221 return cfg80211_leave_mesh(rdev, dev);
9222}
9223
Johannes Bergdfb89c52012-06-27 09:23:48 +02009224#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009225static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9226 struct cfg80211_registered_device *rdev)
9227{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009228 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009229 struct nlattr *nl_pats, *nl_pat;
9230 int i, pat_len;
9231
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009232 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009233 return 0;
9234
9235 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9236 if (!nl_pats)
9237 return -ENOBUFS;
9238
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009239 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009240 nl_pat = nla_nest_start(msg, i + 1);
9241 if (!nl_pat)
9242 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009243 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009244 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009245 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009246 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9247 wowlan->patterns[i].pattern) ||
9248 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009249 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009250 return -ENOBUFS;
9251 nla_nest_end(msg, nl_pat);
9252 }
9253 nla_nest_end(msg, nl_pats);
9254
9255 return 0;
9256}
9257
Johannes Berg2a0e0472013-01-23 22:57:40 +01009258static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9259 struct cfg80211_wowlan_tcp *tcp)
9260{
9261 struct nlattr *nl_tcp;
9262
9263 if (!tcp)
9264 return 0;
9265
9266 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9267 if (!nl_tcp)
9268 return -ENOBUFS;
9269
Jiri Benc930345e2015-03-29 16:59:25 +02009270 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9271 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009272 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9273 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9274 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9275 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9276 tcp->payload_len, tcp->payload) ||
9277 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9278 tcp->data_interval) ||
9279 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9280 tcp->wake_len, tcp->wake_data) ||
9281 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9282 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9283 return -ENOBUFS;
9284
9285 if (tcp->payload_seq.len &&
9286 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9287 sizeof(tcp->payload_seq), &tcp->payload_seq))
9288 return -ENOBUFS;
9289
9290 if (tcp->payload_tok.len &&
9291 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9292 sizeof(tcp->payload_tok) + tcp->tokens_size,
9293 &tcp->payload_tok))
9294 return -ENOBUFS;
9295
Johannes Berge248ad32013-05-16 10:24:28 +02009296 nla_nest_end(msg, nl_tcp);
9297
Johannes Berg2a0e0472013-01-23 22:57:40 +01009298 return 0;
9299}
9300
Luciano Coelho75453cc2015-01-09 14:06:37 +02009301static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9302 struct cfg80211_sched_scan_request *req)
9303{
Avraham Stern3b06d272015-10-12 09:51:34 +03009304 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009305 int i;
9306
9307 if (!req)
9308 return 0;
9309
9310 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9311 if (!nd)
9312 return -ENOBUFS;
9313
Avraham Stern3b06d272015-10-12 09:51:34 +03009314 if (req->n_scan_plans == 1 &&
9315 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9316 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009317 return -ENOBUFS;
9318
Luciano Coelho21fea562015-03-17 16:36:01 +02009319 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9320 return -ENOBUFS;
9321
Luciano Coelho75453cc2015-01-09 14:06:37 +02009322 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9323 if (!freqs)
9324 return -ENOBUFS;
9325
9326 for (i = 0; i < req->n_channels; i++)
9327 nla_put_u32(msg, i, req->channels[i]->center_freq);
9328
9329 nla_nest_end(msg, freqs);
9330
9331 if (req->n_match_sets) {
9332 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9333 for (i = 0; i < req->n_match_sets; i++) {
9334 match = nla_nest_start(msg, i);
9335 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9336 req->match_sets[i].ssid.ssid_len,
9337 req->match_sets[i].ssid.ssid);
9338 nla_nest_end(msg, match);
9339 }
9340 nla_nest_end(msg, matches);
9341 }
9342
Avraham Stern3b06d272015-10-12 09:51:34 +03009343 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9344 if (!scan_plans)
9345 return -ENOBUFS;
9346
9347 for (i = 0; i < req->n_scan_plans; i++) {
9348 scan_plan = nla_nest_start(msg, i + 1);
9349 if (!scan_plan ||
9350 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9351 req->scan_plans[i].interval) ||
9352 (req->scan_plans[i].iterations &&
9353 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9354 req->scan_plans[i].iterations)))
9355 return -ENOBUFS;
9356 nla_nest_end(msg, scan_plan);
9357 }
9358 nla_nest_end(msg, scan_plans);
9359
Luciano Coelho75453cc2015-01-09 14:06:37 +02009360 nla_nest_end(msg, nd);
9361
9362 return 0;
9363}
9364
Johannes Bergff1b6e62011-05-04 15:37:28 +02009365static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9366{
9367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9368 struct sk_buff *msg;
9369 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009370 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009371
Johannes Berg964dc9e2013-06-03 17:25:34 +02009372 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009373 return -EOPNOTSUPP;
9374
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009375 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009376 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009377 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9378 rdev->wiphy.wowlan_config->tcp->payload_len +
9379 rdev->wiphy.wowlan_config->tcp->wake_len +
9380 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009381 }
9382
9383 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009384 if (!msg)
9385 return -ENOMEM;
9386
Eric W. Biederman15e47302012-09-07 20:12:54 +00009387 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009388 NL80211_CMD_GET_WOWLAN);
9389 if (!hdr)
9390 goto nla_put_failure;
9391
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009392 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009393 struct nlattr *nl_wowlan;
9394
9395 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9396 if (!nl_wowlan)
9397 goto nla_put_failure;
9398
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009399 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009400 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009401 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009402 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009403 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009404 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009405 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009406 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009407 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009408 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009409 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009410 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009411 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009412 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9413 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009414
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009415 if (nl80211_send_wowlan_patterns(msg, rdev))
9416 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009417
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009418 if (nl80211_send_wowlan_tcp(msg,
9419 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009420 goto nla_put_failure;
9421
Luciano Coelho75453cc2015-01-09 14:06:37 +02009422 if (nl80211_send_wowlan_nd(
9423 msg,
9424 rdev->wiphy.wowlan_config->nd_config))
9425 goto nla_put_failure;
9426
Johannes Bergff1b6e62011-05-04 15:37:28 +02009427 nla_nest_end(msg, nl_wowlan);
9428 }
9429
9430 genlmsg_end(msg, hdr);
9431 return genlmsg_reply(msg, info);
9432
9433nla_put_failure:
9434 nlmsg_free(msg);
9435 return -ENOBUFS;
9436}
9437
Johannes Berg2a0e0472013-01-23 22:57:40 +01009438static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9439 struct nlattr *attr,
9440 struct cfg80211_wowlan *trig)
9441{
9442 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9443 struct cfg80211_wowlan_tcp *cfg;
9444 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9445 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9446 u32 size;
9447 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9448 int err, port;
9449
Johannes Berg964dc9e2013-06-03 17:25:34 +02009450 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009451 return -EINVAL;
9452
9453 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9454 nla_data(attr), nla_len(attr),
9455 nl80211_wowlan_tcp_policy);
9456 if (err)
9457 return err;
9458
9459 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9460 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9461 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9462 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9463 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9464 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9465 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9466 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9467 return -EINVAL;
9468
9469 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009470 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009471 return -EINVAL;
9472
9473 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009474 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009475 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009476 return -EINVAL;
9477
9478 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009479 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009480 return -EINVAL;
9481
9482 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9483 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9484 return -EINVAL;
9485
9486 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9487 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9488
9489 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9490 tokens_size = tokln - sizeof(*tok);
9491
9492 if (!tok->len || tokens_size % tok->len)
9493 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009494 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009495 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009496 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009497 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009498 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009499 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009500 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009501 return -EINVAL;
9502 if (tok->offset + tok->len > data_size)
9503 return -EINVAL;
9504 }
9505
9506 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9507 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009508 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009509 return -EINVAL;
9510 if (seq->len == 0 || seq->len > 4)
9511 return -EINVAL;
9512 if (seq->len + seq->offset > data_size)
9513 return -EINVAL;
9514 }
9515
9516 size = sizeof(*cfg);
9517 size += data_size;
9518 size += wake_size + wake_mask_size;
9519 size += tokens_size;
9520
9521 cfg = kzalloc(size, GFP_KERNEL);
9522 if (!cfg)
9523 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009524 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9525 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009526 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9527 ETH_ALEN);
9528 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9529 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9530 else
9531 port = 0;
9532#ifdef CONFIG_INET
9533 /* allocate a socket and port for it and use it */
9534 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9535 IPPROTO_TCP, &cfg->sock, 1);
9536 if (err) {
9537 kfree(cfg);
9538 return err;
9539 }
9540 if (inet_csk_get_port(cfg->sock->sk, port)) {
9541 sock_release(cfg->sock);
9542 kfree(cfg);
9543 return -EADDRINUSE;
9544 }
9545 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9546#else
9547 if (!port) {
9548 kfree(cfg);
9549 return -EINVAL;
9550 }
9551 cfg->src_port = port;
9552#endif
9553
9554 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9555 cfg->payload_len = data_size;
9556 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9557 memcpy((void *)cfg->payload,
9558 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9559 data_size);
9560 if (seq)
9561 cfg->payload_seq = *seq;
9562 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9563 cfg->wake_len = wake_size;
9564 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9565 memcpy((void *)cfg->wake_data,
9566 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9567 wake_size);
9568 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9569 data_size + wake_size;
9570 memcpy((void *)cfg->wake_mask,
9571 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9572 wake_mask_size);
9573 if (tok) {
9574 cfg->tokens_size = tokens_size;
9575 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9576 }
9577
9578 trig->tcp = cfg;
9579
9580 return 0;
9581}
9582
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009583static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9584 const struct wiphy_wowlan_support *wowlan,
9585 struct nlattr *attr,
9586 struct cfg80211_wowlan *trig)
9587{
9588 struct nlattr **tb;
9589 int err;
9590
9591 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9592 if (!tb)
9593 return -ENOMEM;
9594
9595 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9596 err = -EOPNOTSUPP;
9597 goto out;
9598 }
9599
9600 err = nla_parse(tb, NL80211_ATTR_MAX,
9601 nla_data(attr), nla_len(attr),
9602 nl80211_policy);
9603 if (err)
9604 goto out;
9605
Johannes Bergad2b26a2014-06-12 21:39:05 +02009606 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009607 err = PTR_ERR_OR_ZERO(trig->nd_config);
9608 if (err)
9609 trig->nd_config = NULL;
9610
9611out:
9612 kfree(tb);
9613 return err;
9614}
9615
Johannes Bergff1b6e62011-05-04 15:37:28 +02009616static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9617{
9618 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9619 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009620 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009621 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009622 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009623 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009624 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009625 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009626
Johannes Berg964dc9e2013-06-03 17:25:34 +02009627 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009628 return -EOPNOTSUPP;
9629
Johannes Bergae33bd82012-07-12 16:25:02 +02009630 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9631 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009632 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009633 goto set_wakeup;
9634 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009635
9636 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9637 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9638 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9639 nl80211_wowlan_policy);
9640 if (err)
9641 return err;
9642
9643 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9644 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9645 return -EINVAL;
9646 new_triggers.any = true;
9647 }
9648
9649 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9650 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9651 return -EINVAL;
9652 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009653 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009654 }
9655
9656 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9657 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9658 return -EINVAL;
9659 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009660 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009661 }
9662
Johannes Berg77dbbb12011-07-13 10:48:55 +02009663 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9664 return -EINVAL;
9665
9666 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9667 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9668 return -EINVAL;
9669 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009670 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009671 }
9672
9673 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9674 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9675 return -EINVAL;
9676 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009677 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009678 }
9679
9680 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9681 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9682 return -EINVAL;
9683 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009684 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009685 }
9686
9687 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9688 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9689 return -EINVAL;
9690 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009691 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009692 }
9693
Johannes Bergff1b6e62011-05-04 15:37:28 +02009694 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9695 struct nlattr *pat;
9696 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009697 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009698 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009699
Johannes Berg98fc4382015-03-01 09:10:13 +02009700 regular = true;
9701
Johannes Bergff1b6e62011-05-04 15:37:28 +02009702 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9703 rem)
9704 n_patterns++;
9705 if (n_patterns > wowlan->n_patterns)
9706 return -EINVAL;
9707
9708 new_triggers.patterns = kcalloc(n_patterns,
9709 sizeof(new_triggers.patterns[0]),
9710 GFP_KERNEL);
9711 if (!new_triggers.patterns)
9712 return -ENOMEM;
9713
9714 new_triggers.n_patterns = n_patterns;
9715 i = 0;
9716
9717 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9718 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009719 u8 *mask_pat;
9720
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009721 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9722 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009723 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009724 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9725 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009726 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009727 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009728 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009729 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009730 goto error;
9731 if (pat_len > wowlan->pattern_max_len ||
9732 pat_len < wowlan->pattern_min_len)
9733 goto error;
9734
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009735 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009736 pkt_offset = 0;
9737 else
9738 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009739 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009740 if (pkt_offset > wowlan->max_pkt_offset)
9741 goto error;
9742 new_triggers.patterns[i].pkt_offset = pkt_offset;
9743
Johannes Berg922bd802014-05-19 17:59:50 +02009744 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9745 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009746 err = -ENOMEM;
9747 goto error;
9748 }
Johannes Berg922bd802014-05-19 17:59:50 +02009749 new_triggers.patterns[i].mask = mask_pat;
9750 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009751 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009752 mask_pat += mask_len;
9753 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009754 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009755 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009756 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009757 pat_len);
9758 i++;
9759 }
9760 }
9761
Johannes Berg2a0e0472013-01-23 22:57:40 +01009762 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009763 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009764 err = nl80211_parse_wowlan_tcp(
9765 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9766 &new_triggers);
9767 if (err)
9768 goto error;
9769 }
9770
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009771 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009772 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009773 err = nl80211_parse_wowlan_nd(
9774 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9775 &new_triggers);
9776 if (err)
9777 goto error;
9778 }
9779
Johannes Berg98fc4382015-03-01 09:10:13 +02009780 /* The 'any' trigger means the device continues operating more or less
9781 * as in its normal operation mode and wakes up the host on most of the
9782 * normal interrupts (like packet RX, ...)
9783 * It therefore makes little sense to combine with the more constrained
9784 * wakeup trigger modes.
9785 */
9786 if (new_triggers.any && regular) {
9787 err = -EINVAL;
9788 goto error;
9789 }
9790
Johannes Bergae33bd82012-07-12 16:25:02 +02009791 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9792 if (!ntrig) {
9793 err = -ENOMEM;
9794 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009795 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009796 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009797 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009798
Johannes Bergae33bd82012-07-12 16:25:02 +02009799 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009800 if (rdev->ops->set_wakeup &&
9801 prev_enabled != !!rdev->wiphy.wowlan_config)
9802 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009803
Johannes Bergff1b6e62011-05-04 15:37:28 +02009804 return 0;
9805 error:
9806 for (i = 0; i < new_triggers.n_patterns; i++)
9807 kfree(new_triggers.patterns[i].mask);
9808 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009809 if (new_triggers.tcp && new_triggers.tcp->sock)
9810 sock_release(new_triggers.tcp->sock);
9811 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009812 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009813 return err;
9814}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009815#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009816
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009817static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9818 struct cfg80211_registered_device *rdev)
9819{
9820 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9821 int i, j, pat_len;
9822 struct cfg80211_coalesce_rules *rule;
9823
9824 if (!rdev->coalesce->n_rules)
9825 return 0;
9826
9827 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9828 if (!nl_rules)
9829 return -ENOBUFS;
9830
9831 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9832 nl_rule = nla_nest_start(msg, i + 1);
9833 if (!nl_rule)
9834 return -ENOBUFS;
9835
9836 rule = &rdev->coalesce->rules[i];
9837 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9838 rule->delay))
9839 return -ENOBUFS;
9840
9841 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9842 rule->condition))
9843 return -ENOBUFS;
9844
9845 nl_pats = nla_nest_start(msg,
9846 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9847 if (!nl_pats)
9848 return -ENOBUFS;
9849
9850 for (j = 0; j < rule->n_patterns; j++) {
9851 nl_pat = nla_nest_start(msg, j + 1);
9852 if (!nl_pat)
9853 return -ENOBUFS;
9854 pat_len = rule->patterns[j].pattern_len;
9855 if (nla_put(msg, NL80211_PKTPAT_MASK,
9856 DIV_ROUND_UP(pat_len, 8),
9857 rule->patterns[j].mask) ||
9858 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9859 rule->patterns[j].pattern) ||
9860 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9861 rule->patterns[j].pkt_offset))
9862 return -ENOBUFS;
9863 nla_nest_end(msg, nl_pat);
9864 }
9865 nla_nest_end(msg, nl_pats);
9866 nla_nest_end(msg, nl_rule);
9867 }
9868 nla_nest_end(msg, nl_rules);
9869
9870 return 0;
9871}
9872
9873static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9874{
9875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9876 struct sk_buff *msg;
9877 void *hdr;
9878
9879 if (!rdev->wiphy.coalesce)
9880 return -EOPNOTSUPP;
9881
9882 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9883 if (!msg)
9884 return -ENOMEM;
9885
9886 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9887 NL80211_CMD_GET_COALESCE);
9888 if (!hdr)
9889 goto nla_put_failure;
9890
9891 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9892 goto nla_put_failure;
9893
9894 genlmsg_end(msg, hdr);
9895 return genlmsg_reply(msg, info);
9896
9897nla_put_failure:
9898 nlmsg_free(msg);
9899 return -ENOBUFS;
9900}
9901
9902void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9903{
9904 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9905 int i, j;
9906 struct cfg80211_coalesce_rules *rule;
9907
9908 if (!coalesce)
9909 return;
9910
9911 for (i = 0; i < coalesce->n_rules; i++) {
9912 rule = &coalesce->rules[i];
9913 for (j = 0; j < rule->n_patterns; j++)
9914 kfree(rule->patterns[j].mask);
9915 kfree(rule->patterns);
9916 }
9917 kfree(coalesce->rules);
9918 kfree(coalesce);
9919 rdev->coalesce = NULL;
9920}
9921
9922static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9923 struct nlattr *rule,
9924 struct cfg80211_coalesce_rules *new_rule)
9925{
9926 int err, i;
9927 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9928 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9929 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9930 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9931
9932 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9933 nla_len(rule), nl80211_coalesce_policy);
9934 if (err)
9935 return err;
9936
9937 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9938 new_rule->delay =
9939 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9940 if (new_rule->delay > coalesce->max_delay)
9941 return -EINVAL;
9942
9943 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9944 new_rule->condition =
9945 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9946 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9947 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9948 return -EINVAL;
9949
9950 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9951 return -EINVAL;
9952
9953 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9954 rem)
9955 n_patterns++;
9956 if (n_patterns > coalesce->n_patterns)
9957 return -EINVAL;
9958
9959 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9960 GFP_KERNEL);
9961 if (!new_rule->patterns)
9962 return -ENOMEM;
9963
9964 new_rule->n_patterns = n_patterns;
9965 i = 0;
9966
9967 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9968 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009969 u8 *mask_pat;
9970
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009971 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9972 nla_len(pat), NULL);
9973 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9974 !pat_tb[NL80211_PKTPAT_PATTERN])
9975 return -EINVAL;
9976 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9977 mask_len = DIV_ROUND_UP(pat_len, 8);
9978 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9979 return -EINVAL;
9980 if (pat_len > coalesce->pattern_max_len ||
9981 pat_len < coalesce->pattern_min_len)
9982 return -EINVAL;
9983
9984 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9985 pkt_offset = 0;
9986 else
9987 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9988 if (pkt_offset > coalesce->max_pkt_offset)
9989 return -EINVAL;
9990 new_rule->patterns[i].pkt_offset = pkt_offset;
9991
Johannes Berg922bd802014-05-19 17:59:50 +02009992 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9993 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009994 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009995
9996 new_rule->patterns[i].mask = mask_pat;
9997 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9998 mask_len);
9999
10000 mask_pat += mask_len;
10001 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010002 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010003 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10004 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010005 i++;
10006 }
10007
10008 return 0;
10009}
10010
10011static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10012{
10013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10014 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10015 struct cfg80211_coalesce new_coalesce = {};
10016 struct cfg80211_coalesce *n_coalesce;
10017 int err, rem_rule, n_rules = 0, i, j;
10018 struct nlattr *rule;
10019 struct cfg80211_coalesce_rules *tmp_rule;
10020
10021 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10022 return -EOPNOTSUPP;
10023
10024 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10025 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010026 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010027 return 0;
10028 }
10029
10030 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10031 rem_rule)
10032 n_rules++;
10033 if (n_rules > coalesce->n_rules)
10034 return -EINVAL;
10035
10036 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10037 GFP_KERNEL);
10038 if (!new_coalesce.rules)
10039 return -ENOMEM;
10040
10041 new_coalesce.n_rules = n_rules;
10042 i = 0;
10043
10044 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10045 rem_rule) {
10046 err = nl80211_parse_coalesce_rule(rdev, rule,
10047 &new_coalesce.rules[i]);
10048 if (err)
10049 goto error;
10050
10051 i++;
10052 }
10053
Ilan Peera1056b12015-10-22 22:27:46 +030010054 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010055 if (err)
10056 goto error;
10057
10058 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10059 if (!n_coalesce) {
10060 err = -ENOMEM;
10061 goto error;
10062 }
10063 cfg80211_rdev_free_coalesce(rdev);
10064 rdev->coalesce = n_coalesce;
10065
10066 return 0;
10067error:
10068 for (i = 0; i < new_coalesce.n_rules; i++) {
10069 tmp_rule = &new_coalesce.rules[i];
10070 for (j = 0; j < tmp_rule->n_patterns; j++)
10071 kfree(tmp_rule->patterns[j].mask);
10072 kfree(tmp_rule->patterns);
10073 }
10074 kfree(new_coalesce.rules);
10075
10076 return err;
10077}
10078
Johannes Berge5497d72011-07-05 16:35:40 +020010079static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10080{
10081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10082 struct net_device *dev = info->user_ptr[1];
10083 struct wireless_dev *wdev = dev->ieee80211_ptr;
10084 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10085 struct cfg80211_gtk_rekey_data rekey_data;
10086 int err;
10087
10088 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10089 return -EINVAL;
10090
10091 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10092 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10093 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10094 nl80211_rekey_policy);
10095 if (err)
10096 return err;
10097
10098 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10099 return -ERANGE;
10100 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10101 return -ERANGE;
10102 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10103 return -ERANGE;
10104
Johannes Berg78f686c2014-09-10 22:28:06 +030010105 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10106 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10107 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010108
10109 wdev_lock(wdev);
10110 if (!wdev->current_bss) {
10111 err = -ENOTCONN;
10112 goto out;
10113 }
10114
10115 if (!rdev->ops->set_rekey_data) {
10116 err = -EOPNOTSUPP;
10117 goto out;
10118 }
10119
Hila Gonene35e4d22012-06-27 17:19:42 +030010120 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010121 out:
10122 wdev_unlock(wdev);
10123 return err;
10124}
10125
Johannes Berg28946da2011-11-04 11:18:12 +010010126static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10127 struct genl_info *info)
10128{
10129 struct net_device *dev = info->user_ptr[1];
10130 struct wireless_dev *wdev = dev->ieee80211_ptr;
10131
10132 if (wdev->iftype != NL80211_IFTYPE_AP &&
10133 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10134 return -EINVAL;
10135
Eric W. Biederman15e47302012-09-07 20:12:54 +000010136 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010137 return -EBUSY;
10138
Eric W. Biederman15e47302012-09-07 20:12:54 +000010139 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010140 return 0;
10141}
10142
Johannes Berg7f6cf312011-11-04 11:18:15 +010010143static int nl80211_probe_client(struct sk_buff *skb,
10144 struct genl_info *info)
10145{
10146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10147 struct net_device *dev = info->user_ptr[1];
10148 struct wireless_dev *wdev = dev->ieee80211_ptr;
10149 struct sk_buff *msg;
10150 void *hdr;
10151 const u8 *addr;
10152 u64 cookie;
10153 int err;
10154
10155 if (wdev->iftype != NL80211_IFTYPE_AP &&
10156 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10157 return -EOPNOTSUPP;
10158
10159 if (!info->attrs[NL80211_ATTR_MAC])
10160 return -EINVAL;
10161
10162 if (!rdev->ops->probe_client)
10163 return -EOPNOTSUPP;
10164
10165 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10166 if (!msg)
10167 return -ENOMEM;
10168
Eric W. Biederman15e47302012-09-07 20:12:54 +000010169 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010170 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010171 if (!hdr) {
10172 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010173 goto free_msg;
10174 }
10175
10176 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10177
Hila Gonene35e4d22012-06-27 17:19:42 +030010178 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010179 if (err)
10180 goto free_msg;
10181
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010182 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10183 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010184 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010185
10186 genlmsg_end(msg, hdr);
10187
10188 return genlmsg_reply(msg, info);
10189
10190 nla_put_failure:
10191 err = -ENOBUFS;
10192 free_msg:
10193 nlmsg_free(msg);
10194 return err;
10195}
10196
Johannes Berg5e7602302011-11-04 11:18:17 +010010197static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10198{
10199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010200 struct cfg80211_beacon_registration *reg, *nreg;
10201 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010202
10203 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10204 return -EOPNOTSUPP;
10205
Ben Greear37c73b52012-10-26 14:49:25 -070010206 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10207 if (!nreg)
10208 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010209
Ben Greear37c73b52012-10-26 14:49:25 -070010210 /* First, check if already registered. */
10211 spin_lock_bh(&rdev->beacon_registrations_lock);
10212 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10213 if (reg->nlportid == info->snd_portid) {
10214 rv = -EALREADY;
10215 goto out_err;
10216 }
10217 }
10218 /* Add it to the list */
10219 nreg->nlportid = info->snd_portid;
10220 list_add(&nreg->list, &rdev->beacon_registrations);
10221
10222 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010223
10224 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010225out_err:
10226 spin_unlock_bh(&rdev->beacon_registrations_lock);
10227 kfree(nreg);
10228 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010229}
10230
Johannes Berg98104fde2012-06-16 00:19:54 +020010231static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10232{
10233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10234 struct wireless_dev *wdev = info->user_ptr[1];
10235 int err;
10236
10237 if (!rdev->ops->start_p2p_device)
10238 return -EOPNOTSUPP;
10239
10240 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10241 return -EOPNOTSUPP;
10242
10243 if (wdev->p2p_started)
10244 return 0;
10245
Luciano Coelhob6a55012014-02-27 11:07:21 +020010246 if (rfkill_blocked(rdev->rfkill))
10247 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010248
Johannes Bergeeb126e2012-10-23 15:16:50 +020010249 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010250 if (err)
10251 return err;
10252
10253 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010254 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010255
10256 return 0;
10257}
10258
10259static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10260{
10261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10262 struct wireless_dev *wdev = info->user_ptr[1];
10263
10264 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10265 return -EOPNOTSUPP;
10266
10267 if (!rdev->ops->stop_p2p_device)
10268 return -EOPNOTSUPP;
10269
Johannes Bergf9f47522013-03-19 15:04:07 +010010270 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010271
10272 return 0;
10273}
10274
Johannes Berg3713b4e2013-02-14 16:19:38 +010010275static int nl80211_get_protocol_features(struct sk_buff *skb,
10276 struct genl_info *info)
10277{
10278 void *hdr;
10279 struct sk_buff *msg;
10280
10281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10282 if (!msg)
10283 return -ENOMEM;
10284
10285 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10286 NL80211_CMD_GET_PROTOCOL_FEATURES);
10287 if (!hdr)
10288 goto nla_put_failure;
10289
10290 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10291 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10292 goto nla_put_failure;
10293
10294 genlmsg_end(msg, hdr);
10295 return genlmsg_reply(msg, info);
10296
10297 nla_put_failure:
10298 kfree_skb(msg);
10299 return -ENOBUFS;
10300}
10301
Jouni Malinen355199e2013-02-27 17:14:27 +020010302static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10303{
10304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10305 struct cfg80211_update_ft_ies_params ft_params;
10306 struct net_device *dev = info->user_ptr[1];
10307
10308 if (!rdev->ops->update_ft_ies)
10309 return -EOPNOTSUPP;
10310
10311 if (!info->attrs[NL80211_ATTR_MDID] ||
10312 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10313 return -EINVAL;
10314
10315 memset(&ft_params, 0, sizeof(ft_params));
10316 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10317 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10318 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10319
10320 return rdev_update_ft_ies(rdev, dev, &ft_params);
10321}
10322
Arend van Spriel5de17982013-04-18 15:49:00 +020010323static int nl80211_crit_protocol_start(struct sk_buff *skb,
10324 struct genl_info *info)
10325{
10326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10327 struct wireless_dev *wdev = info->user_ptr[1];
10328 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10329 u16 duration;
10330 int ret;
10331
10332 if (!rdev->ops->crit_proto_start)
10333 return -EOPNOTSUPP;
10334
10335 if (WARN_ON(!rdev->ops->crit_proto_stop))
10336 return -EINVAL;
10337
10338 if (rdev->crit_proto_nlportid)
10339 return -EBUSY;
10340
10341 /* determine protocol if provided */
10342 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10343 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10344
10345 if (proto >= NUM_NL80211_CRIT_PROTO)
10346 return -EINVAL;
10347
10348 /* timeout must be provided */
10349 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10350 return -EINVAL;
10351
10352 duration =
10353 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10354
10355 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10356 return -ERANGE;
10357
10358 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10359 if (!ret)
10360 rdev->crit_proto_nlportid = info->snd_portid;
10361
10362 return ret;
10363}
10364
10365static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10366 struct genl_info *info)
10367{
10368 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10369 struct wireless_dev *wdev = info->user_ptr[1];
10370
10371 if (!rdev->ops->crit_proto_stop)
10372 return -EOPNOTSUPP;
10373
10374 if (rdev->crit_proto_nlportid) {
10375 rdev->crit_proto_nlportid = 0;
10376 rdev_crit_proto_stop(rdev, wdev);
10377 }
10378 return 0;
10379}
10380
Johannes Bergad7e7182013-11-13 13:37:47 +010010381static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10382{
10383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10384 struct wireless_dev *wdev =
10385 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10386 int i, err;
10387 u32 vid, subcmd;
10388
10389 if (!rdev->wiphy.vendor_commands)
10390 return -EOPNOTSUPP;
10391
10392 if (IS_ERR(wdev)) {
10393 err = PTR_ERR(wdev);
10394 if (err != -EINVAL)
10395 return err;
10396 wdev = NULL;
10397 } else if (wdev->wiphy != &rdev->wiphy) {
10398 return -EINVAL;
10399 }
10400
10401 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10402 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10403 return -EINVAL;
10404
10405 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10406 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10407 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10408 const struct wiphy_vendor_command *vcmd;
10409 void *data = NULL;
10410 int len = 0;
10411
10412 vcmd = &rdev->wiphy.vendor_commands[i];
10413
10414 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10415 continue;
10416
10417 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10418 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10419 if (!wdev)
10420 return -EINVAL;
10421 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10422 !wdev->netdev)
10423 return -EINVAL;
10424
10425 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10426 if (wdev->netdev &&
10427 !netif_running(wdev->netdev))
10428 return -ENETDOWN;
10429 if (!wdev->netdev && !wdev->p2p_started)
10430 return -ENETDOWN;
10431 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010432
10433 if (!vcmd->doit)
10434 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010435 } else {
10436 wdev = NULL;
10437 }
10438
10439 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10440 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10441 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10442 }
10443
10444 rdev->cur_cmd_info = info;
10445 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10446 data, len);
10447 rdev->cur_cmd_info = NULL;
10448 return err;
10449 }
10450
10451 return -EOPNOTSUPP;
10452}
10453
Johannes Berg7bdbe402015-08-15 22:39:49 +030010454static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10455 struct netlink_callback *cb,
10456 struct cfg80211_registered_device **rdev,
10457 struct wireless_dev **wdev)
10458{
10459 u32 vid, subcmd;
10460 unsigned int i;
10461 int vcmd_idx = -1;
10462 int err;
10463 void *data = NULL;
10464 unsigned int data_len = 0;
10465
10466 rtnl_lock();
10467
10468 if (cb->args[0]) {
10469 /* subtract the 1 again here */
10470 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10471 struct wireless_dev *tmp;
10472
10473 if (!wiphy) {
10474 err = -ENODEV;
10475 goto out_unlock;
10476 }
10477 *rdev = wiphy_to_rdev(wiphy);
10478 *wdev = NULL;
10479
10480 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010481 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010482 if (tmp->identifier == cb->args[1] - 1) {
10483 *wdev = tmp;
10484 break;
10485 }
10486 }
10487 }
10488
10489 /* keep rtnl locked in successful case */
10490 return 0;
10491 }
10492
10493 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10494 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10495 nl80211_policy);
10496 if (err)
10497 goto out_unlock;
10498
10499 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10500 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10501 err = -EINVAL;
10502 goto out_unlock;
10503 }
10504
10505 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10506 nl80211_fam.attrbuf);
10507 if (IS_ERR(*wdev))
10508 *wdev = NULL;
10509
10510 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10511 nl80211_fam.attrbuf);
10512 if (IS_ERR(*rdev)) {
10513 err = PTR_ERR(*rdev);
10514 goto out_unlock;
10515 }
10516
10517 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10518 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10519
10520 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10521 const struct wiphy_vendor_command *vcmd;
10522
10523 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10524
10525 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10526 continue;
10527
10528 if (!vcmd->dumpit) {
10529 err = -EOPNOTSUPP;
10530 goto out_unlock;
10531 }
10532
10533 vcmd_idx = i;
10534 break;
10535 }
10536
10537 if (vcmd_idx < 0) {
10538 err = -EOPNOTSUPP;
10539 goto out_unlock;
10540 }
10541
10542 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10543 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10544 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10545 }
10546
10547 /* 0 is the first index - add 1 to parse only once */
10548 cb->args[0] = (*rdev)->wiphy_idx + 1;
10549 /* add 1 to know if it was NULL */
10550 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10551 cb->args[2] = vcmd_idx;
10552 cb->args[3] = (unsigned long)data;
10553 cb->args[4] = data_len;
10554
10555 /* keep rtnl locked in successful case */
10556 return 0;
10557 out_unlock:
10558 rtnl_unlock();
10559 return err;
10560}
10561
10562static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10563 struct netlink_callback *cb)
10564{
10565 struct cfg80211_registered_device *rdev;
10566 struct wireless_dev *wdev;
10567 unsigned int vcmd_idx;
10568 const struct wiphy_vendor_command *vcmd;
10569 void *data;
10570 int data_len;
10571 int err;
10572 struct nlattr *vendor_data;
10573
10574 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10575 if (err)
10576 return err;
10577
10578 vcmd_idx = cb->args[2];
10579 data = (void *)cb->args[3];
10580 data_len = cb->args[4];
10581 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10582
10583 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10584 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10585 if (!wdev)
10586 return -EINVAL;
10587 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10588 !wdev->netdev)
10589 return -EINVAL;
10590
10591 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10592 if (wdev->netdev &&
10593 !netif_running(wdev->netdev))
10594 return -ENETDOWN;
10595 if (!wdev->netdev && !wdev->p2p_started)
10596 return -ENETDOWN;
10597 }
10598 }
10599
10600 while (1) {
10601 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10602 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10603 NL80211_CMD_VENDOR);
10604 if (!hdr)
10605 break;
10606
10607 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010608 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10609 wdev_id(wdev),
10610 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010611 genlmsg_cancel(skb, hdr);
10612 break;
10613 }
10614
10615 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10616 if (!vendor_data) {
10617 genlmsg_cancel(skb, hdr);
10618 break;
10619 }
10620
10621 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10622 (unsigned long *)&cb->args[5]);
10623 nla_nest_end(skb, vendor_data);
10624
10625 if (err == -ENOBUFS || err == -ENOENT) {
10626 genlmsg_cancel(skb, hdr);
10627 break;
10628 } else if (err) {
10629 genlmsg_cancel(skb, hdr);
10630 goto out;
10631 }
10632
10633 genlmsg_end(skb, hdr);
10634 }
10635
10636 err = skb->len;
10637 out:
10638 rtnl_unlock();
10639 return err;
10640}
10641
Johannes Bergad7e7182013-11-13 13:37:47 +010010642struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10643 enum nl80211_commands cmd,
10644 enum nl80211_attrs attr,
10645 int approxlen)
10646{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010647 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010648
10649 if (WARN_ON(!rdev->cur_cmd_info))
10650 return NULL;
10651
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010652 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010653 rdev->cur_cmd_info->snd_portid,
10654 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010655 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010656}
10657EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10658
10659int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10660{
10661 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10662 void *hdr = ((void **)skb->cb)[1];
10663 struct nlattr *data = ((void **)skb->cb)[2];
10664
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010665 /* clear CB data for netlink core to own from now on */
10666 memset(skb->cb, 0, sizeof(skb->cb));
10667
Johannes Bergad7e7182013-11-13 13:37:47 +010010668 if (WARN_ON(!rdev->cur_cmd_info)) {
10669 kfree_skb(skb);
10670 return -EINVAL;
10671 }
10672
10673 nla_nest_end(skb, data);
10674 genlmsg_end(skb, hdr);
10675 return genlmsg_reply(skb, rdev->cur_cmd_info);
10676}
10677EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10678
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010679static int nl80211_set_qos_map(struct sk_buff *skb,
10680 struct genl_info *info)
10681{
10682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10683 struct cfg80211_qos_map *qos_map = NULL;
10684 struct net_device *dev = info->user_ptr[1];
10685 u8 *pos, len, num_des, des_len, des;
10686 int ret;
10687
10688 if (!rdev->ops->set_qos_map)
10689 return -EOPNOTSUPP;
10690
10691 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10692 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10693 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10694
10695 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10696 len > IEEE80211_QOS_MAP_LEN_MAX)
10697 return -EINVAL;
10698
10699 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10700 if (!qos_map)
10701 return -ENOMEM;
10702
10703 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10704 if (num_des) {
10705 des_len = num_des *
10706 sizeof(struct cfg80211_dscp_exception);
10707 memcpy(qos_map->dscp_exception, pos, des_len);
10708 qos_map->num_des = num_des;
10709 for (des = 0; des < num_des; des++) {
10710 if (qos_map->dscp_exception[des].up > 7) {
10711 kfree(qos_map);
10712 return -EINVAL;
10713 }
10714 }
10715 pos += des_len;
10716 }
10717 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10718 }
10719
10720 wdev_lock(dev->ieee80211_ptr);
10721 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10722 if (!ret)
10723 ret = rdev_set_qos_map(rdev, dev, qos_map);
10724 wdev_unlock(dev->ieee80211_ptr);
10725
10726 kfree(qos_map);
10727 return ret;
10728}
10729
Johannes Berg960d01a2014-09-09 22:55:35 +030010730static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10731{
10732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10733 struct net_device *dev = info->user_ptr[1];
10734 struct wireless_dev *wdev = dev->ieee80211_ptr;
10735 const u8 *peer;
10736 u8 tsid, up;
10737 u16 admitted_time = 0;
10738 int err;
10739
Johannes Berg723e73a2014-10-22 09:25:06 +020010740 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010741 return -EOPNOTSUPP;
10742
10743 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10744 !info->attrs[NL80211_ATTR_USER_PRIO])
10745 return -EINVAL;
10746
10747 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10748 if (tsid >= IEEE80211_NUM_TIDS)
10749 return -EINVAL;
10750
10751 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10752 if (up >= IEEE80211_NUM_UPS)
10753 return -EINVAL;
10754
10755 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010756 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010757 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010758 * need more attributes for that (e.g. BA session requirement);
10759 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010760 */
10761 return -EINVAL;
10762 }
10763
10764 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10765
10766 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10767 admitted_time =
10768 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10769 if (!admitted_time)
10770 return -EINVAL;
10771 }
10772
10773 wdev_lock(wdev);
10774 switch (wdev->iftype) {
10775 case NL80211_IFTYPE_STATION:
10776 case NL80211_IFTYPE_P2P_CLIENT:
10777 if (wdev->current_bss)
10778 break;
10779 err = -ENOTCONN;
10780 goto out;
10781 default:
10782 err = -EOPNOTSUPP;
10783 goto out;
10784 }
10785
10786 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10787
10788 out:
10789 wdev_unlock(wdev);
10790 return err;
10791}
10792
10793static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10794{
10795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10796 struct net_device *dev = info->user_ptr[1];
10797 struct wireless_dev *wdev = dev->ieee80211_ptr;
10798 const u8 *peer;
10799 u8 tsid;
10800 int err;
10801
10802 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10803 return -EINVAL;
10804
10805 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10806 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10807
10808 wdev_lock(wdev);
10809 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10810 wdev_unlock(wdev);
10811
10812 return err;
10813}
10814
Arik Nemtsov1057d352014-11-19 12:54:26 +020010815static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10816 struct genl_info *info)
10817{
10818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10819 struct net_device *dev = info->user_ptr[1];
10820 struct wireless_dev *wdev = dev->ieee80211_ptr;
10821 struct cfg80211_chan_def chandef = {};
10822 const u8 *addr;
10823 u8 oper_class;
10824 int err;
10825
10826 if (!rdev->ops->tdls_channel_switch ||
10827 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10828 return -EOPNOTSUPP;
10829
10830 switch (dev->ieee80211_ptr->iftype) {
10831 case NL80211_IFTYPE_STATION:
10832 case NL80211_IFTYPE_P2P_CLIENT:
10833 break;
10834 default:
10835 return -EOPNOTSUPP;
10836 }
10837
10838 if (!info->attrs[NL80211_ATTR_MAC] ||
10839 !info->attrs[NL80211_ATTR_OPER_CLASS])
10840 return -EINVAL;
10841
10842 err = nl80211_parse_chandef(rdev, info, &chandef);
10843 if (err)
10844 return err;
10845
10846 /*
10847 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10848 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10849 * specification is not defined for them.
10850 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010851 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010852 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10853 chandef.width != NL80211_CHAN_WIDTH_20)
10854 return -EINVAL;
10855
10856 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010857 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10858 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010859 return -EINVAL;
10860
10861 /* don't allow switching to DFS channels */
10862 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10863 return -EINVAL;
10864
10865 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10866 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10867
10868 wdev_lock(wdev);
10869 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10870 wdev_unlock(wdev);
10871
10872 return err;
10873}
10874
10875static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10876 struct genl_info *info)
10877{
10878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10879 struct net_device *dev = info->user_ptr[1];
10880 struct wireless_dev *wdev = dev->ieee80211_ptr;
10881 const u8 *addr;
10882
10883 if (!rdev->ops->tdls_channel_switch ||
10884 !rdev->ops->tdls_cancel_channel_switch ||
10885 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10886 return -EOPNOTSUPP;
10887
10888 switch (dev->ieee80211_ptr->iftype) {
10889 case NL80211_IFTYPE_STATION:
10890 case NL80211_IFTYPE_P2P_CLIENT:
10891 break;
10892 default:
10893 return -EOPNOTSUPP;
10894 }
10895
10896 if (!info->attrs[NL80211_ATTR_MAC])
10897 return -EINVAL;
10898
10899 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10900
10901 wdev_lock(wdev);
10902 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10903 wdev_unlock(wdev);
10904
10905 return 0;
10906}
10907
Johannes Berg4c476992010-10-04 21:36:35 +020010908#define NL80211_FLAG_NEED_WIPHY 0x01
10909#define NL80211_FLAG_NEED_NETDEV 0x02
10910#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010911#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10912#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10913 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010914#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010915/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010916#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10917 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010918#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010919
Johannes Bergf84f7712013-11-14 17:14:45 +010010920static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010921 struct genl_info *info)
10922{
10923 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010924 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010925 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010926 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10927
10928 if (rtnl)
10929 rtnl_lock();
10930
10931 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010932 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010933 if (IS_ERR(rdev)) {
10934 if (rtnl)
10935 rtnl_unlock();
10936 return PTR_ERR(rdev);
10937 }
10938 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010939 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10940 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010941 ASSERT_RTNL();
10942
Johannes Berg89a54e42012-06-15 14:33:17 +020010943 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10944 info->attrs);
10945 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010946 if (rtnl)
10947 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010948 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010949 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010950
Johannes Berg89a54e42012-06-15 14:33:17 +020010951 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010952 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010953
Johannes Berg1bf614e2012-06-15 15:23:36 +020010954 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10955 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010956 if (rtnl)
10957 rtnl_unlock();
10958 return -EINVAL;
10959 }
10960
10961 info->user_ptr[1] = dev;
10962 } else {
10963 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010964 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010965
Johannes Berg1bf614e2012-06-15 15:23:36 +020010966 if (dev) {
10967 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10968 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010969 if (rtnl)
10970 rtnl_unlock();
10971 return -ENETDOWN;
10972 }
10973
10974 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010975 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10976 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010977 if (rtnl)
10978 rtnl_unlock();
10979 return -ENETDOWN;
10980 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010981 }
10982
Johannes Berg4c476992010-10-04 21:36:35 +020010983 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010984 }
10985
10986 return 0;
10987}
10988
Johannes Bergf84f7712013-11-14 17:14:45 +010010989static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010990 struct genl_info *info)
10991{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010992 if (info->user_ptr[1]) {
10993 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10994 struct wireless_dev *wdev = info->user_ptr[1];
10995
10996 if (wdev->netdev)
10997 dev_put(wdev->netdev);
10998 } else {
10999 dev_put(info->user_ptr[1]);
11000 }
11001 }
Johannes Berg5393b912014-09-10 15:00:16 +030011002
Johannes Berg4c476992010-10-04 21:36:35 +020011003 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11004 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011005
11006 /* If needed, clear the netlink message payload from the SKB
11007 * as it might contain key data that shouldn't stick around on
11008 * the heap after the SKB is freed. The netlink message header
11009 * is still needed for further processing, so leave it intact.
11010 */
11011 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11012 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11013
11014 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11015 }
Johannes Berg4c476992010-10-04 21:36:35 +020011016}
11017
Johannes Berg4534de82013-11-14 17:14:46 +010011018static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011019 {
11020 .cmd = NL80211_CMD_GET_WIPHY,
11021 .doit = nl80211_get_wiphy,
11022 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011023 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011024 .policy = nl80211_policy,
11025 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011026 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11027 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011028 },
11029 {
11030 .cmd = NL80211_CMD_SET_WIPHY,
11031 .doit = nl80211_set_wiphy,
11032 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011033 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011034 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011035 },
11036 {
11037 .cmd = NL80211_CMD_GET_INTERFACE,
11038 .doit = nl80211_get_interface,
11039 .dumpit = nl80211_dump_interface,
11040 .policy = nl80211_policy,
11041 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011042 .internal_flags = NL80211_FLAG_NEED_WDEV |
11043 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011044 },
11045 {
11046 .cmd = NL80211_CMD_SET_INTERFACE,
11047 .doit = nl80211_set_interface,
11048 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011049 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011050 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11051 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011052 },
11053 {
11054 .cmd = NL80211_CMD_NEW_INTERFACE,
11055 .doit = nl80211_new_interface,
11056 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011057 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011058 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11059 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011060 },
11061 {
11062 .cmd = NL80211_CMD_DEL_INTERFACE,
11063 .doit = nl80211_del_interface,
11064 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011065 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011066 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011067 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011068 },
Johannes Berg41ade002007-12-19 02:03:29 +010011069 {
11070 .cmd = NL80211_CMD_GET_KEY,
11071 .doit = nl80211_get_key,
11072 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011073 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011074 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011075 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011076 },
11077 {
11078 .cmd = NL80211_CMD_SET_KEY,
11079 .doit = nl80211_set_key,
11080 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011081 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011083 NL80211_FLAG_NEED_RTNL |
11084 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011085 },
11086 {
11087 .cmd = NL80211_CMD_NEW_KEY,
11088 .doit = nl80211_new_key,
11089 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011090 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011091 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011092 NL80211_FLAG_NEED_RTNL |
11093 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011094 },
11095 {
11096 .cmd = NL80211_CMD_DEL_KEY,
11097 .doit = nl80211_del_key,
11098 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011099 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011101 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011102 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011103 {
11104 .cmd = NL80211_CMD_SET_BEACON,
11105 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011106 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011107 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011108 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011109 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011110 },
11111 {
Johannes Berg88600202012-02-13 15:17:18 +010011112 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011113 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011114 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011115 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011117 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011118 },
11119 {
Johannes Berg88600202012-02-13 15:17:18 +010011120 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011121 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011122 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011123 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011125 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011126 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011127 {
11128 .cmd = NL80211_CMD_GET_STATION,
11129 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011130 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011131 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011132 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11133 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011134 },
11135 {
11136 .cmd = NL80211_CMD_SET_STATION,
11137 .doit = nl80211_set_station,
11138 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011139 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011141 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011142 },
11143 {
11144 .cmd = NL80211_CMD_NEW_STATION,
11145 .doit = nl80211_new_station,
11146 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011147 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011149 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011150 },
11151 {
11152 .cmd = NL80211_CMD_DEL_STATION,
11153 .doit = nl80211_del_station,
11154 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011155 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011157 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011158 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011159 {
11160 .cmd = NL80211_CMD_GET_MPATH,
11161 .doit = nl80211_get_mpath,
11162 .dumpit = nl80211_dump_mpath,
11163 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011164 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011165 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011166 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011167 },
11168 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011169 .cmd = NL80211_CMD_GET_MPP,
11170 .doit = nl80211_get_mpp,
11171 .dumpit = nl80211_dump_mpp,
11172 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011173 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011174 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11175 NL80211_FLAG_NEED_RTNL,
11176 },
11177 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011178 .cmd = NL80211_CMD_SET_MPATH,
11179 .doit = nl80211_set_mpath,
11180 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011181 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011182 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011183 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011184 },
11185 {
11186 .cmd = NL80211_CMD_NEW_MPATH,
11187 .doit = nl80211_new_mpath,
11188 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011189 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011190 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011191 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011192 },
11193 {
11194 .cmd = NL80211_CMD_DEL_MPATH,
11195 .doit = nl80211_del_mpath,
11196 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011197 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011198 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011199 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011200 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011201 {
11202 .cmd = NL80211_CMD_SET_BSS,
11203 .doit = nl80211_set_bss,
11204 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011205 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011206 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011207 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011208 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011209 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011210 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011211 .doit = nl80211_get_reg_do,
11212 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011213 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011214 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011215 /* can be retrieved by unprivileged users */
11216 },
Johannes Bergb6863032015-10-15 09:25:18 +020011217#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011218 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011219 .cmd = NL80211_CMD_SET_REG,
11220 .doit = nl80211_set_reg,
11221 .policy = nl80211_policy,
11222 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011223 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011224 },
Johannes Bergb6863032015-10-15 09:25:18 +020011225#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011226 {
11227 .cmd = NL80211_CMD_REQ_SET_REG,
11228 .doit = nl80211_req_set_reg,
11229 .policy = nl80211_policy,
11230 .flags = GENL_ADMIN_PERM,
11231 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011232 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011233 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11234 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011235 .policy = nl80211_policy,
11236 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011238 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011239 },
11240 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011241 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11242 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011243 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011244 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011246 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011247 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011248 {
Johannes Berg2a519312009-02-10 21:25:55 +010011249 .cmd = NL80211_CMD_TRIGGER_SCAN,
11250 .doit = nl80211_trigger_scan,
11251 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011252 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011253 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011254 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011255 },
11256 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011257 .cmd = NL80211_CMD_ABORT_SCAN,
11258 .doit = nl80211_abort_scan,
11259 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011260 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011261 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11262 NL80211_FLAG_NEED_RTNL,
11263 },
11264 {
Johannes Berg2a519312009-02-10 21:25:55 +010011265 .cmd = NL80211_CMD_GET_SCAN,
11266 .policy = nl80211_policy,
11267 .dumpit = nl80211_dump_scan,
11268 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011269 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011270 .cmd = NL80211_CMD_START_SCHED_SCAN,
11271 .doit = nl80211_start_sched_scan,
11272 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011273 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11275 NL80211_FLAG_NEED_RTNL,
11276 },
11277 {
11278 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11279 .doit = nl80211_stop_sched_scan,
11280 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011281 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11283 NL80211_FLAG_NEED_RTNL,
11284 },
11285 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011286 .cmd = NL80211_CMD_AUTHENTICATE,
11287 .doit = nl80211_authenticate,
11288 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011289 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011290 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011291 NL80211_FLAG_NEED_RTNL |
11292 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011293 },
11294 {
11295 .cmd = NL80211_CMD_ASSOCIATE,
11296 .doit = nl80211_associate,
11297 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011298 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011299 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011300 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011301 },
11302 {
11303 .cmd = NL80211_CMD_DEAUTHENTICATE,
11304 .doit = nl80211_deauthenticate,
11305 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011306 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011307 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011308 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011309 },
11310 {
11311 .cmd = NL80211_CMD_DISASSOCIATE,
11312 .doit = nl80211_disassociate,
11313 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011314 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011316 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011317 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011318 {
11319 .cmd = NL80211_CMD_JOIN_IBSS,
11320 .doit = nl80211_join_ibss,
11321 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011322 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011323 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011324 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011325 },
11326 {
11327 .cmd = NL80211_CMD_LEAVE_IBSS,
11328 .doit = nl80211_leave_ibss,
11329 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011330 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011332 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011333 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011334#ifdef CONFIG_NL80211_TESTMODE
11335 {
11336 .cmd = NL80211_CMD_TESTMODE,
11337 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011338 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011339 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011340 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011341 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11342 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011343 },
11344#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011345 {
11346 .cmd = NL80211_CMD_CONNECT,
11347 .doit = nl80211_connect,
11348 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011349 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011350 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011351 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011352 },
11353 {
11354 .cmd = NL80211_CMD_DISCONNECT,
11355 .doit = nl80211_disconnect,
11356 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011357 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011358 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011359 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011360 },
Johannes Berg463d0182009-07-14 00:33:35 +020011361 {
11362 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11363 .doit = nl80211_wiphy_netns,
11364 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011365 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011366 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11367 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011368 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011369 {
11370 .cmd = NL80211_CMD_GET_SURVEY,
11371 .policy = nl80211_policy,
11372 .dumpit = nl80211_dump_survey,
11373 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011374 {
11375 .cmd = NL80211_CMD_SET_PMKSA,
11376 .doit = nl80211_setdel_pmksa,
11377 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011378 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011379 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011380 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011381 },
11382 {
11383 .cmd = NL80211_CMD_DEL_PMKSA,
11384 .doit = nl80211_setdel_pmksa,
11385 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011386 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011388 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011389 },
11390 {
11391 .cmd = NL80211_CMD_FLUSH_PMKSA,
11392 .doit = nl80211_flush_pmksa,
11393 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011394 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011396 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011397 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011398 {
11399 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11400 .doit = nl80211_remain_on_channel,
11401 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011402 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011403 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011404 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011405 },
11406 {
11407 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11408 .doit = nl80211_cancel_remain_on_channel,
11409 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011410 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011411 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011412 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011413 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011414 {
11415 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11416 .doit = nl80211_set_tx_bitrate_mask,
11417 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011418 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011419 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11420 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011421 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011422 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011423 .cmd = NL80211_CMD_REGISTER_FRAME,
11424 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011425 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011426 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011427 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011428 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011429 },
11430 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011431 .cmd = NL80211_CMD_FRAME,
11432 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011433 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011434 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011435 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011436 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011437 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011438 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011439 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11440 .doit = nl80211_tx_mgmt_cancel_wait,
11441 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011442 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011443 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011444 NL80211_FLAG_NEED_RTNL,
11445 },
11446 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011447 .cmd = NL80211_CMD_SET_POWER_SAVE,
11448 .doit = nl80211_set_power_save,
11449 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011450 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011451 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11452 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011453 },
11454 {
11455 .cmd = NL80211_CMD_GET_POWER_SAVE,
11456 .doit = nl80211_get_power_save,
11457 .policy = nl80211_policy,
11458 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011459 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11460 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011461 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011462 {
11463 .cmd = NL80211_CMD_SET_CQM,
11464 .doit = nl80211_set_cqm,
11465 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011466 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011467 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11468 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011469 },
Johannes Bergf444de02010-05-05 15:25:02 +020011470 {
11471 .cmd = NL80211_CMD_SET_CHANNEL,
11472 .doit = nl80211_set_channel,
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,
Johannes Bergf444de02010-05-05 15:25:02 +020011477 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011478 {
11479 .cmd = NL80211_CMD_SET_WDS_PEER,
11480 .doit = nl80211_set_wds_peer,
11481 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011482 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011483 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11484 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011485 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011486 {
11487 .cmd = NL80211_CMD_JOIN_MESH,
11488 .doit = nl80211_join_mesh,
11489 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011490 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11492 NL80211_FLAG_NEED_RTNL,
11493 },
11494 {
11495 .cmd = NL80211_CMD_LEAVE_MESH,
11496 .doit = nl80211_leave_mesh,
11497 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011498 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11500 NL80211_FLAG_NEED_RTNL,
11501 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011502 {
11503 .cmd = NL80211_CMD_JOIN_OCB,
11504 .doit = nl80211_join_ocb,
11505 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011506 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11508 NL80211_FLAG_NEED_RTNL,
11509 },
11510 {
11511 .cmd = NL80211_CMD_LEAVE_OCB,
11512 .doit = nl80211_leave_ocb,
11513 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011514 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11516 NL80211_FLAG_NEED_RTNL,
11517 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011518#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011519 {
11520 .cmd = NL80211_CMD_GET_WOWLAN,
11521 .doit = nl80211_get_wowlan,
11522 .policy = nl80211_policy,
11523 /* can be retrieved by unprivileged users */
11524 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11525 NL80211_FLAG_NEED_RTNL,
11526 },
11527 {
11528 .cmd = NL80211_CMD_SET_WOWLAN,
11529 .doit = nl80211_set_wowlan,
11530 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011531 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011532 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11533 NL80211_FLAG_NEED_RTNL,
11534 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011535#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011536 {
11537 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11538 .doit = nl80211_set_rekey_data,
11539 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011540 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011542 NL80211_FLAG_NEED_RTNL |
11543 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011544 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011545 {
11546 .cmd = NL80211_CMD_TDLS_MGMT,
11547 .doit = nl80211_tdls_mgmt,
11548 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011549 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011550 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11551 NL80211_FLAG_NEED_RTNL,
11552 },
11553 {
11554 .cmd = NL80211_CMD_TDLS_OPER,
11555 .doit = nl80211_tdls_oper,
11556 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011557 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011558 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11559 NL80211_FLAG_NEED_RTNL,
11560 },
Johannes Berg28946da2011-11-04 11:18:12 +010011561 {
11562 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11563 .doit = nl80211_register_unexpected_frame,
11564 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011565 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011566 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11567 NL80211_FLAG_NEED_RTNL,
11568 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011569 {
11570 .cmd = NL80211_CMD_PROBE_CLIENT,
11571 .doit = nl80211_probe_client,
11572 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011573 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011574 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011575 NL80211_FLAG_NEED_RTNL,
11576 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011577 {
11578 .cmd = NL80211_CMD_REGISTER_BEACONS,
11579 .doit = nl80211_register_beacons,
11580 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011581 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010011582 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11583 NL80211_FLAG_NEED_RTNL,
11584 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011585 {
11586 .cmd = NL80211_CMD_SET_NOACK_MAP,
11587 .doit = nl80211_set_noack_map,
11588 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011589 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011590 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11591 NL80211_FLAG_NEED_RTNL,
11592 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011593 {
11594 .cmd = NL80211_CMD_START_P2P_DEVICE,
11595 .doit = nl80211_start_p2p_device,
11596 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011597 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011598 .internal_flags = NL80211_FLAG_NEED_WDEV |
11599 NL80211_FLAG_NEED_RTNL,
11600 },
11601 {
11602 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11603 .doit = nl80211_stop_p2p_device,
11604 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011605 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011606 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11607 NL80211_FLAG_NEED_RTNL,
11608 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011609 {
11610 .cmd = NL80211_CMD_SET_MCAST_RATE,
11611 .doit = nl80211_set_mcast_rate,
11612 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011613 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011614 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11615 NL80211_FLAG_NEED_RTNL,
11616 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011617 {
11618 .cmd = NL80211_CMD_SET_MAC_ACL,
11619 .doit = nl80211_set_mac_acl,
11620 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011621 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011622 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11623 NL80211_FLAG_NEED_RTNL,
11624 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011625 {
11626 .cmd = NL80211_CMD_RADAR_DETECT,
11627 .doit = nl80211_start_radar_detection,
11628 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011629 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11631 NL80211_FLAG_NEED_RTNL,
11632 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011633 {
11634 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11635 .doit = nl80211_get_protocol_features,
11636 .policy = nl80211_policy,
11637 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011638 {
11639 .cmd = NL80211_CMD_UPDATE_FT_IES,
11640 .doit = nl80211_update_ft_ies,
11641 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011642 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11644 NL80211_FLAG_NEED_RTNL,
11645 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011646 {
11647 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11648 .doit = nl80211_crit_protocol_start,
11649 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011650 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011651 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11652 NL80211_FLAG_NEED_RTNL,
11653 },
11654 {
11655 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11656 .doit = nl80211_crit_protocol_stop,
11657 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011658 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011659 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11660 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011661 },
11662 {
11663 .cmd = NL80211_CMD_GET_COALESCE,
11664 .doit = nl80211_get_coalesce,
11665 .policy = nl80211_policy,
11666 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11667 NL80211_FLAG_NEED_RTNL,
11668 },
11669 {
11670 .cmd = NL80211_CMD_SET_COALESCE,
11671 .doit = nl80211_set_coalesce,
11672 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011673 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011674 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11675 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011676 },
11677 {
11678 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11679 .doit = nl80211_channel_switch,
11680 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011681 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011682 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11683 NL80211_FLAG_NEED_RTNL,
11684 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011685 {
11686 .cmd = NL80211_CMD_VENDOR,
11687 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011688 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011689 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011690 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011691 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11692 NL80211_FLAG_NEED_RTNL,
11693 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011694 {
11695 .cmd = NL80211_CMD_SET_QOS_MAP,
11696 .doit = nl80211_set_qos_map,
11697 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011698 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011699 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11700 NL80211_FLAG_NEED_RTNL,
11701 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011702 {
11703 .cmd = NL80211_CMD_ADD_TX_TS,
11704 .doit = nl80211_add_tx_ts,
11705 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011706 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011707 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11708 NL80211_FLAG_NEED_RTNL,
11709 },
11710 {
11711 .cmd = NL80211_CMD_DEL_TX_TS,
11712 .doit = nl80211_del_tx_ts,
11713 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011714 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11716 NL80211_FLAG_NEED_RTNL,
11717 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011718 {
11719 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11720 .doit = nl80211_tdls_channel_switch,
11721 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011722 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011723 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11724 NL80211_FLAG_NEED_RTNL,
11725 },
11726 {
11727 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11728 .doit = nl80211_tdls_cancel_channel_switch,
11729 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011730 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011731 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11732 NL80211_FLAG_NEED_RTNL,
11733 },
Johannes Berg55682962007-09-20 13:09:35 -040011734};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011735
Johannes Berg55682962007-09-20 13:09:35 -040011736/* notification functions */
11737
Johannes Berg3bb20552014-05-26 13:52:25 +020011738void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11739 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011740{
11741 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011742 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011743
Johannes Berg3bb20552014-05-26 13:52:25 +020011744 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11745 cmd != NL80211_CMD_DEL_WIPHY);
11746
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011747 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011748 if (!msg)
11749 return;
11750
Johannes Berg3bb20552014-05-26 13:52:25 +020011751 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011752 nlmsg_free(msg);
11753 return;
11754 }
11755
Johannes Berg68eb5502013-11-19 15:19:38 +010011756 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011757 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011758}
11759
Johannes Berg362a4152009-05-24 16:43:15 +020011760static int nl80211_add_scan_req(struct sk_buff *msg,
11761 struct cfg80211_registered_device *rdev)
11762{
11763 struct cfg80211_scan_request *req = rdev->scan_req;
11764 struct nlattr *nest;
11765 int i;
11766
11767 if (WARN_ON(!req))
11768 return 0;
11769
11770 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11771 if (!nest)
11772 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011773 for (i = 0; i < req->n_ssids; i++) {
11774 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11775 goto nla_put_failure;
11776 }
Johannes Berg362a4152009-05-24 16:43:15 +020011777 nla_nest_end(msg, nest);
11778
11779 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11780 if (!nest)
11781 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011782 for (i = 0; i < req->n_channels; i++) {
11783 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11784 goto nla_put_failure;
11785 }
Johannes Berg362a4152009-05-24 16:43:15 +020011786 nla_nest_end(msg, nest);
11787
David S. Miller9360ffd2012-03-29 04:41:26 -040011788 if (req->ie &&
11789 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11790 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011791
Johannes Bergae917c92013-10-25 11:05:22 +020011792 if (req->flags &&
11793 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11794 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011795
Johannes Berg362a4152009-05-24 16:43:15 +020011796 return 0;
11797 nla_put_failure:
11798 return -ENOBUFS;
11799}
11800
Johannes Berga538e2d2009-06-16 19:56:42 +020011801static int nl80211_send_scan_msg(struct sk_buff *msg,
11802 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011803 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011804 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011805 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011806{
11807 void *hdr;
11808
Eric W. Biederman15e47302012-09-07 20:12:54 +000011809 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011810 if (!hdr)
11811 return -1;
11812
David S. Miller9360ffd2012-03-29 04:41:26 -040011813 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011814 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11815 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011816 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11817 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011818 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011819
Johannes Berg362a4152009-05-24 16:43:15 +020011820 /* ignore errors and send incomplete event anyway */
11821 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011822
Johannes Berg053c0952015-01-16 22:09:00 +010011823 genlmsg_end(msg, hdr);
11824 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011825
11826 nla_put_failure:
11827 genlmsg_cancel(msg, hdr);
11828 return -EMSGSIZE;
11829}
11830
Luciano Coelho807f8a82011-05-11 17:09:35 +030011831static int
11832nl80211_send_sched_scan_msg(struct sk_buff *msg,
11833 struct cfg80211_registered_device *rdev,
11834 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011835 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011836{
11837 void *hdr;
11838
Eric W. Biederman15e47302012-09-07 20:12:54 +000011839 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011840 if (!hdr)
11841 return -1;
11842
David S. Miller9360ffd2012-03-29 04:41:26 -040011843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11844 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11845 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011846
Johannes Berg053c0952015-01-16 22:09:00 +010011847 genlmsg_end(msg, hdr);
11848 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011849
11850 nla_put_failure:
11851 genlmsg_cancel(msg, hdr);
11852 return -EMSGSIZE;
11853}
11854
Johannes Berga538e2d2009-06-16 19:56:42 +020011855void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011856 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011857{
11858 struct sk_buff *msg;
11859
Thomas Graf58050fc2012-06-28 03:57:45 +000011860 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011861 if (!msg)
11862 return;
11863
Johannes Bergfd014282012-06-18 19:17:03 +020011864 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011865 NL80211_CMD_TRIGGER_SCAN) < 0) {
11866 nlmsg_free(msg);
11867 return;
11868 }
11869
Johannes Berg68eb5502013-11-19 15:19:38 +010011870 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011871 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011872}
11873
Johannes Bergf9d15d12014-01-22 11:14:19 +020011874struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11875 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011876{
11877 struct sk_buff *msg;
11878
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011880 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011881 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011882
Johannes Bergfd014282012-06-18 19:17:03 +020011883 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011884 aborted ? NL80211_CMD_SCAN_ABORTED :
11885 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011886 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011887 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011888 }
11889
Johannes Bergf9d15d12014-01-22 11:14:19 +020011890 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011891}
11892
Johannes Bergf9d15d12014-01-22 11:14:19 +020011893void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11894 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011895{
Johannes Berg2a519312009-02-10 21:25:55 +010011896 if (!msg)
11897 return;
11898
Johannes Berg68eb5502013-11-19 15:19:38 +010011899 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011900 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011901}
11902
Luciano Coelho807f8a82011-05-11 17:09:35 +030011903void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11904 struct net_device *netdev)
11905{
11906 struct sk_buff *msg;
11907
11908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11909 if (!msg)
11910 return;
11911
11912 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11913 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11914 nlmsg_free(msg);
11915 return;
11916 }
11917
Johannes Berg68eb5502013-11-19 15:19:38 +010011918 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011919 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011920}
11921
11922void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11923 struct net_device *netdev, u32 cmd)
11924{
11925 struct sk_buff *msg;
11926
Thomas Graf58050fc2012-06-28 03:57:45 +000011927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011928 if (!msg)
11929 return;
11930
11931 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11932 nlmsg_free(msg);
11933 return;
11934 }
11935
Johannes Berg68eb5502013-11-19 15:19:38 +010011936 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011937 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011938}
11939
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011940static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11941 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011942{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011943 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011944 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11945 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011946
David S. Miller9360ffd2012-03-29 04:41:26 -040011947 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11948 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11949 NL80211_REGDOM_TYPE_WORLD))
11950 goto nla_put_failure;
11951 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11952 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11953 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11954 goto nla_put_failure;
11955 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11956 request->intersect) {
11957 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11958 NL80211_REGDOM_TYPE_INTERSECTION))
11959 goto nla_put_failure;
11960 } else {
11961 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11962 NL80211_REGDOM_TYPE_COUNTRY) ||
11963 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11964 request->alpha2))
11965 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011966 }
11967
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011968 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11969 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11970
11971 if (wiphy &&
11972 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11973 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011974
11975 if (wiphy &&
11976 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11977 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11978 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011979 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011980
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011981 return true;
11982
11983nla_put_failure:
11984 return false;
11985}
11986
11987/*
11988 * This can happen on global regulatory changes or device specific settings
11989 * based on custom regulatory domains.
11990 */
11991void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11992 struct regulatory_request *request)
11993{
11994 struct sk_buff *msg;
11995 void *hdr;
11996
11997 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11998 if (!msg)
11999 return;
12000
12001 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12002 if (!hdr) {
12003 nlmsg_free(msg);
12004 return;
12005 }
12006
12007 if (nl80211_reg_change_event_fill(msg, request) == false)
12008 goto nla_put_failure;
12009
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012010 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012011
Johannes Bergbc43b282009-07-25 10:54:13 +020012012 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012013 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012014 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012015 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012016
12017 return;
12018
12019nla_put_failure:
12020 genlmsg_cancel(msg, hdr);
12021 nlmsg_free(msg);
12022}
12023
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012024static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12025 struct net_device *netdev,
12026 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012027 enum nl80211_commands cmd, gfp_t gfp,
12028 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012029{
12030 struct sk_buff *msg;
12031 void *hdr;
12032
Johannes Berge6d6e342009-07-01 21:26:47 +020012033 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012034 if (!msg)
12035 return;
12036
12037 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12038 if (!hdr) {
12039 nlmsg_free(msg);
12040 return;
12041 }
12042
David S. Miller9360ffd2012-03-29 04:41:26 -040012043 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12044 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12045 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12046 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012047
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012048 if (uapsd_queues >= 0) {
12049 struct nlattr *nla_wmm =
12050 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12051 if (!nla_wmm)
12052 goto nla_put_failure;
12053
12054 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12055 uapsd_queues))
12056 goto nla_put_failure;
12057
12058 nla_nest_end(msg, nla_wmm);
12059 }
12060
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012061 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012062
Johannes Berg68eb5502013-11-19 15:19:38 +010012063 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012064 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012065 return;
12066
12067 nla_put_failure:
12068 genlmsg_cancel(msg, hdr);
12069 nlmsg_free(msg);
12070}
12071
12072void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012073 struct net_device *netdev, const u8 *buf,
12074 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012075{
12076 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012077 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012078}
12079
12080void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12081 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012082 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012083{
Johannes Berge6d6e342009-07-01 21:26:47 +020012084 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012085 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012086}
12087
Jouni Malinen53b46b82009-03-27 20:53:56 +020012088void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012089 struct net_device *netdev, const u8 *buf,
12090 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012091{
12092 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012093 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012094}
12095
Jouni Malinen53b46b82009-03-27 20:53:56 +020012096void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12097 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012098 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012099{
12100 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012101 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012102}
12103
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012104void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12105 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012106{
Johannes Berg947add32013-02-22 22:05:20 +010012107 struct wireless_dev *wdev = dev->ieee80211_ptr;
12108 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012109 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012110 const struct ieee80211_mgmt *mgmt = (void *)buf;
12111 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012112
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012113 if (WARN_ON(len < 2))
12114 return;
12115
12116 if (ieee80211_is_deauth(mgmt->frame_control))
12117 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12118 else
12119 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12120
12121 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012122 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012123}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012124EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012125
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012126static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12127 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012128 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012129{
12130 struct sk_buff *msg;
12131 void *hdr;
12132
Johannes Berge6d6e342009-07-01 21:26:47 +020012133 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012134 if (!msg)
12135 return;
12136
12137 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12138 if (!hdr) {
12139 nlmsg_free(msg);
12140 return;
12141 }
12142
David S. Miller9360ffd2012-03-29 04:41:26 -040012143 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12144 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12145 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12146 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12147 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012148
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012149 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012150
Johannes Berg68eb5502013-11-19 15:19:38 +010012151 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012152 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012153 return;
12154
12155 nla_put_failure:
12156 genlmsg_cancel(msg, hdr);
12157 nlmsg_free(msg);
12158}
12159
12160void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012161 struct net_device *netdev, const u8 *addr,
12162 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012163{
12164 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012165 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012166}
12167
12168void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012169 struct net_device *netdev, const u8 *addr,
12170 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012171{
Johannes Berge6d6e342009-07-01 21:26:47 +020012172 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12173 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012174}
12175
Samuel Ortizb23aa672009-07-01 21:26:54 +020012176void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12177 struct net_device *netdev, const u8 *bssid,
12178 const u8 *req_ie, size_t req_ie_len,
12179 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012180 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012181{
12182 struct sk_buff *msg;
12183 void *hdr;
12184
Thomas Graf58050fc2012-06-28 03:57:45 +000012185 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012186 if (!msg)
12187 return;
12188
12189 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12190 if (!hdr) {
12191 nlmsg_free(msg);
12192 return;
12193 }
12194
David S. Miller9360ffd2012-03-29 04:41:26 -040012195 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12196 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12197 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012198 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12199 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12200 status) ||
12201 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012202 (req_ie &&
12203 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12204 (resp_ie &&
12205 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12206 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012207
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012208 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012209
Johannes Berg68eb5502013-11-19 15:19:38 +010012210 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012211 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012212 return;
12213
12214 nla_put_failure:
12215 genlmsg_cancel(msg, hdr);
12216 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012217}
12218
12219void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12220 struct net_device *netdev, const u8 *bssid,
12221 const u8 *req_ie, size_t req_ie_len,
12222 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12223{
12224 struct sk_buff *msg;
12225 void *hdr;
12226
Thomas Graf58050fc2012-06-28 03:57:45 +000012227 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012228 if (!msg)
12229 return;
12230
12231 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12232 if (!hdr) {
12233 nlmsg_free(msg);
12234 return;
12235 }
12236
David S. Miller9360ffd2012-03-29 04:41:26 -040012237 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12238 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12239 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12240 (req_ie &&
12241 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12242 (resp_ie &&
12243 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12244 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012245
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012246 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012247
Johannes Berg68eb5502013-11-19 15:19:38 +010012248 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012249 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012250 return;
12251
12252 nla_put_failure:
12253 genlmsg_cancel(msg, hdr);
12254 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012255}
12256
12257void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12258 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012259 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012260{
12261 struct sk_buff *msg;
12262 void *hdr;
12263
Thomas Graf58050fc2012-06-28 03:57:45 +000012264 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012265 if (!msg)
12266 return;
12267
12268 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12269 if (!hdr) {
12270 nlmsg_free(msg);
12271 return;
12272 }
12273
David S. Miller9360ffd2012-03-29 04:41:26 -040012274 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12275 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12276 (from_ap && reason &&
12277 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12278 (from_ap &&
12279 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12280 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12281 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012282
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012283 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012284
Johannes Berg68eb5502013-11-19 15:19:38 +010012285 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012286 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012287 return;
12288
12289 nla_put_failure:
12290 genlmsg_cancel(msg, hdr);
12291 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012292}
12293
Johannes Berg04a773a2009-04-19 21:24:32 +020012294void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12295 struct net_device *netdev, const u8 *bssid,
12296 gfp_t gfp)
12297{
12298 struct sk_buff *msg;
12299 void *hdr;
12300
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012301 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012302 if (!msg)
12303 return;
12304
12305 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12306 if (!hdr) {
12307 nlmsg_free(msg);
12308 return;
12309 }
12310
David S. Miller9360ffd2012-03-29 04:41:26 -040012311 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12312 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12313 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12314 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012315
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012316 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012317
Johannes Berg68eb5502013-11-19 15:19:38 +010012318 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012319 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012320 return;
12321
12322 nla_put_failure:
12323 genlmsg_cancel(msg, hdr);
12324 nlmsg_free(msg);
12325}
12326
Johannes Berg947add32013-02-22 22:05:20 +010012327void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12328 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012329{
Johannes Berg947add32013-02-22 22:05:20 +010012330 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012331 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012332 struct sk_buff *msg;
12333 void *hdr;
12334
Johannes Berg947add32013-02-22 22:05:20 +010012335 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12336 return;
12337
12338 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12339
Javier Cardonac93b5e72011-04-07 15:08:34 -070012340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12341 if (!msg)
12342 return;
12343
12344 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12345 if (!hdr) {
12346 nlmsg_free(msg);
12347 return;
12348 }
12349
David S. Miller9360ffd2012-03-29 04:41:26 -040012350 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012351 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12352 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012353 (ie_len && ie &&
12354 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12355 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012356
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012357 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012358
Johannes Berg68eb5502013-11-19 15:19:38 +010012359 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012360 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012361 return;
12362
12363 nla_put_failure:
12364 genlmsg_cancel(msg, hdr);
12365 nlmsg_free(msg);
12366}
Johannes Berg947add32013-02-22 22:05:20 +010012367EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012368
Jouni Malinena3b8b052009-03-27 21:59:49 +020012369void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12370 struct net_device *netdev, const u8 *addr,
12371 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012372 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012373{
12374 struct sk_buff *msg;
12375 void *hdr;
12376
Johannes Berge6d6e342009-07-01 21:26:47 +020012377 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012378 if (!msg)
12379 return;
12380
12381 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12382 if (!hdr) {
12383 nlmsg_free(msg);
12384 return;
12385 }
12386
David S. Miller9360ffd2012-03-29 04:41:26 -040012387 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12388 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12389 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12390 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12391 (key_id != -1 &&
12392 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12393 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12394 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012395
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012396 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012397
Johannes Berg68eb5502013-11-19 15:19:38 +010012398 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012399 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012400 return;
12401
12402 nla_put_failure:
12403 genlmsg_cancel(msg, hdr);
12404 nlmsg_free(msg);
12405}
12406
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012407void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12408 struct ieee80211_channel *channel_before,
12409 struct ieee80211_channel *channel_after)
12410{
12411 struct sk_buff *msg;
12412 void *hdr;
12413 struct nlattr *nl_freq;
12414
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012415 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012416 if (!msg)
12417 return;
12418
12419 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12420 if (!hdr) {
12421 nlmsg_free(msg);
12422 return;
12423 }
12424
12425 /*
12426 * Since we are applying the beacon hint to a wiphy we know its
12427 * wiphy_idx is valid
12428 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12430 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012431
12432 /* Before */
12433 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12434 if (!nl_freq)
12435 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012436 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012437 goto nla_put_failure;
12438 nla_nest_end(msg, nl_freq);
12439
12440 /* After */
12441 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12442 if (!nl_freq)
12443 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012444 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012445 goto nla_put_failure;
12446 nla_nest_end(msg, nl_freq);
12447
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012448 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012449
Johannes Berg463d0182009-07-14 00:33:35 +020012450 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012451 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012452 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012453 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012454
12455 return;
12456
12457nla_put_failure:
12458 genlmsg_cancel(msg, hdr);
12459 nlmsg_free(msg);
12460}
12461
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012462static void nl80211_send_remain_on_chan_event(
12463 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012464 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012465 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012466 unsigned int duration, gfp_t gfp)
12467{
12468 struct sk_buff *msg;
12469 void *hdr;
12470
12471 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12472 if (!msg)
12473 return;
12474
12475 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12476 if (!hdr) {
12477 nlmsg_free(msg);
12478 return;
12479 }
12480
David S. Miller9360ffd2012-03-29 04:41:26 -040012481 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012482 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12483 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012484 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12485 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012486 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012487 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12488 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012489 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12490 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012491 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012492
David S. Miller9360ffd2012-03-29 04:41:26 -040012493 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12494 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12495 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012496
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012497 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012498
Johannes Berg68eb5502013-11-19 15:19:38 +010012499 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012500 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012501 return;
12502
12503 nla_put_failure:
12504 genlmsg_cancel(msg, hdr);
12505 nlmsg_free(msg);
12506}
12507
Johannes Berg947add32013-02-22 22:05:20 +010012508void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12509 struct ieee80211_channel *chan,
12510 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012511{
Johannes Berg947add32013-02-22 22:05:20 +010012512 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012513 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012514
12515 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012516 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012517 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012518 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012519}
Johannes Berg947add32013-02-22 22:05:20 +010012520EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012521
Johannes Berg947add32013-02-22 22:05:20 +010012522void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12523 struct ieee80211_channel *chan,
12524 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012525{
Johannes Berg947add32013-02-22 22:05:20 +010012526 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012527 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012528
12529 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012530 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012531 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012532}
Johannes Berg947add32013-02-22 22:05:20 +010012533EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012534
Johannes Berg947add32013-02-22 22:05:20 +010012535void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12536 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012537{
Johannes Berg947add32013-02-22 22:05:20 +010012538 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012539 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012540 struct sk_buff *msg;
12541
Johannes Berg947add32013-02-22 22:05:20 +010012542 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12543
Thomas Graf58050fc2012-06-28 03:57:45 +000012544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012545 if (!msg)
12546 return;
12547
Johannes Bergcf5ead82014-11-14 17:14:00 +010012548 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012549 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012550 nlmsg_free(msg);
12551 return;
12552 }
12553
Johannes Berg68eb5502013-11-19 15:19:38 +010012554 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012555 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012556}
Johannes Berg947add32013-02-22 22:05:20 +010012557EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012558
Johannes Bergcf5ead82014-11-14 17:14:00 +010012559void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12560 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012561{
Johannes Berg947add32013-02-22 22:05:20 +010012562 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012563 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012564 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012565 struct station_info empty_sinfo = {};
12566
12567 if (!sinfo)
12568 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012569
Johannes Berg947add32013-02-22 22:05:20 +010012570 trace_cfg80211_del_sta(dev, mac_addr);
12571
Thomas Graf58050fc2012-06-28 03:57:45 +000012572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012573 if (!msg)
12574 return;
12575
Johannes Bergcf5ead82014-11-14 17:14:00 +010012576 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012577 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012578 nlmsg_free(msg);
12579 return;
12580 }
12581
Johannes Berg68eb5502013-11-19 15:19:38 +010012582 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012583 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012584}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012585EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012586
Johannes Berg947add32013-02-22 22:05:20 +010012587void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12588 enum nl80211_connect_failed_reason reason,
12589 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012590{
Johannes Berg947add32013-02-22 22:05:20 +010012591 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012592 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012593 struct sk_buff *msg;
12594 void *hdr;
12595
12596 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12597 if (!msg)
12598 return;
12599
12600 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12601 if (!hdr) {
12602 nlmsg_free(msg);
12603 return;
12604 }
12605
12606 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12607 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12608 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12609 goto nla_put_failure;
12610
12611 genlmsg_end(msg, hdr);
12612
Johannes Berg68eb5502013-11-19 15:19:38 +010012613 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012614 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012615 return;
12616
12617 nla_put_failure:
12618 genlmsg_cancel(msg, hdr);
12619 nlmsg_free(msg);
12620}
Johannes Berg947add32013-02-22 22:05:20 +010012621EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012622
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012623static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12624 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012625{
12626 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012627 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012628 struct sk_buff *msg;
12629 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012630 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012631
Eric W. Biederman15e47302012-09-07 20:12:54 +000012632 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012633 return false;
12634
12635 msg = nlmsg_new(100, gfp);
12636 if (!msg)
12637 return true;
12638
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012639 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012640 if (!hdr) {
12641 nlmsg_free(msg);
12642 return true;
12643 }
12644
David S. Miller9360ffd2012-03-29 04:41:26 -040012645 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12646 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12647 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12648 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012649
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012650 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012651 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012652 return true;
12653
12654 nla_put_failure:
12655 genlmsg_cancel(msg, hdr);
12656 nlmsg_free(msg);
12657 return true;
12658}
12659
Johannes Berg947add32013-02-22 22:05:20 +010012660bool cfg80211_rx_spurious_frame(struct net_device *dev,
12661 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012662{
Johannes Berg947add32013-02-22 22:05:20 +010012663 struct wireless_dev *wdev = dev->ieee80211_ptr;
12664 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012665
Johannes Berg947add32013-02-22 22:05:20 +010012666 trace_cfg80211_rx_spurious_frame(dev, addr);
12667
12668 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12669 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12670 trace_cfg80211_return_bool(false);
12671 return false;
12672 }
12673 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12674 addr, gfp);
12675 trace_cfg80211_return_bool(ret);
12676 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012677}
Johannes Berg947add32013-02-22 22:05:20 +010012678EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12679
12680bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12681 const u8 *addr, gfp_t gfp)
12682{
12683 struct wireless_dev *wdev = dev->ieee80211_ptr;
12684 bool ret;
12685
12686 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12687
12688 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12689 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12690 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12691 trace_cfg80211_return_bool(false);
12692 return false;
12693 }
12694 ret = __nl80211_unexpected_frame(dev,
12695 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12696 addr, gfp);
12697 trace_cfg80211_return_bool(ret);
12698 return ret;
12699}
12700EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012701
Johannes Berg2e161f72010-08-12 15:38:38 +020012702int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012703 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012704 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012705 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012706{
Johannes Berg71bbc992012-06-15 15:30:18 +020012707 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012708 struct sk_buff *msg;
12709 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012710
12711 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12712 if (!msg)
12713 return -ENOMEM;
12714
Johannes Berg2e161f72010-08-12 15:38:38 +020012715 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012716 if (!hdr) {
12717 nlmsg_free(msg);
12718 return -ENOMEM;
12719 }
12720
David S. Miller9360ffd2012-03-29 04:41:26 -040012721 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012722 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12723 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012724 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12725 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012726 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12727 (sig_dbm &&
12728 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012729 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12730 (flags &&
12731 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012732 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012733
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012734 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012735
Eric W. Biederman15e47302012-09-07 20:12:54 +000012736 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012737
12738 nla_put_failure:
12739 genlmsg_cancel(msg, hdr);
12740 nlmsg_free(msg);
12741 return -ENOBUFS;
12742}
12743
Johannes Berg947add32013-02-22 22:05:20 +010012744void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12745 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012746{
Johannes Berg947add32013-02-22 22:05:20 +010012747 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012748 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012749 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012750 struct sk_buff *msg;
12751 void *hdr;
12752
Johannes Berg947add32013-02-22 22:05:20 +010012753 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12754
Jouni Malinen026331c2010-02-15 12:53:10 +020012755 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12756 if (!msg)
12757 return;
12758
Johannes Berg2e161f72010-08-12 15:38:38 +020012759 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012760 if (!hdr) {
12761 nlmsg_free(msg);
12762 return;
12763 }
12764
David S. Miller9360ffd2012-03-29 04:41:26 -040012765 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012766 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12767 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012768 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12769 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012770 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012771 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12772 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012773 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12774 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012775
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012776 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012777
Johannes Berg68eb5502013-11-19 15:19:38 +010012778 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012779 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012780 return;
12781
12782 nla_put_failure:
12783 genlmsg_cancel(msg, hdr);
12784 nlmsg_free(msg);
12785}
Johannes Berg947add32013-02-22 22:05:20 +010012786EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012787
Johannes Berg5b97f492014-11-26 12:37:43 +010012788static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12789 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012790{
Johannes Berg947add32013-02-22 22:05:20 +010012791 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012792 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12793 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12794 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012795
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012796 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012797 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012798
Johannes Berg5b97f492014-11-26 12:37:43 +010012799 cb = (void **)msg->cb;
12800
12801 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12802 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012803 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012804 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012805 }
12806
David S. Miller9360ffd2012-03-29 04:41:26 -040012807 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012808 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012809 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012810
Johannes Berg5b97f492014-11-26 12:37:43 +010012811 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012812 goto nla_put_failure;
12813
Johannes Berg5b97f492014-11-26 12:37:43 +010012814 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12815 if (!cb[1])
12816 goto nla_put_failure;
12817
12818 cb[2] = rdev;
12819
12820 return msg;
12821 nla_put_failure:
12822 nlmsg_free(msg);
12823 return NULL;
12824}
12825
12826static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12827{
12828 void **cb = (void **)msg->cb;
12829 struct cfg80211_registered_device *rdev = cb[2];
12830
12831 nla_nest_end(msg, cb[1]);
12832 genlmsg_end(msg, cb[0]);
12833
12834 memset(msg->cb, 0, sizeof(msg->cb));
12835
12836 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12837 NL80211_MCGRP_MLME, gfp);
12838}
12839
12840void cfg80211_cqm_rssi_notify(struct net_device *dev,
12841 enum nl80211_cqm_rssi_threshold_event rssi_event,
12842 gfp_t gfp)
12843{
12844 struct sk_buff *msg;
12845
12846 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12847
Johannes Berg98f03342014-11-26 12:42:02 +010012848 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12849 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12850 return;
12851
Johannes Berg5b97f492014-11-26 12:37:43 +010012852 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12853 if (!msg)
12854 return;
12855
David S. Miller9360ffd2012-03-29 04:41:26 -040012856 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12857 rssi_event))
12858 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012859
Johannes Berg5b97f492014-11-26 12:37:43 +010012860 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012861
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012862 return;
12863
12864 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012865 nlmsg_free(msg);
12866}
Johannes Berg947add32013-02-22 22:05:20 +010012867EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012868
Johannes Berg5b97f492014-11-26 12:37:43 +010012869void cfg80211_cqm_txe_notify(struct net_device *dev,
12870 const u8 *peer, u32 num_packets,
12871 u32 rate, u32 intvl, gfp_t gfp)
12872{
12873 struct sk_buff *msg;
12874
12875 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12876 if (!msg)
12877 return;
12878
12879 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12880 goto nla_put_failure;
12881
12882 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12883 goto nla_put_failure;
12884
12885 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12886 goto nla_put_failure;
12887
12888 cfg80211_send_cqm(msg, gfp);
12889 return;
12890
12891 nla_put_failure:
12892 nlmsg_free(msg);
12893}
12894EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12895
12896void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12897 const u8 *peer, u32 num_packets, gfp_t gfp)
12898{
12899 struct sk_buff *msg;
12900
12901 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12902
12903 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12904 if (!msg)
12905 return;
12906
12907 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12908 goto nla_put_failure;
12909
12910 cfg80211_send_cqm(msg, gfp);
12911 return;
12912
12913 nla_put_failure:
12914 nlmsg_free(msg);
12915}
12916EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12917
Johannes Berg98f03342014-11-26 12:42:02 +010012918void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12919{
12920 struct sk_buff *msg;
12921
12922 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12923 if (!msg)
12924 return;
12925
12926 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12927 goto nla_put_failure;
12928
12929 cfg80211_send_cqm(msg, gfp);
12930 return;
12931
12932 nla_put_failure:
12933 nlmsg_free(msg);
12934}
12935EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12936
Johannes Berg947add32013-02-22 22:05:20 +010012937static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12938 struct net_device *netdev, const u8 *bssid,
12939 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012940{
12941 struct sk_buff *msg;
12942 struct nlattr *rekey_attr;
12943 void *hdr;
12944
Thomas Graf58050fc2012-06-28 03:57:45 +000012945 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012946 if (!msg)
12947 return;
12948
12949 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12950 if (!hdr) {
12951 nlmsg_free(msg);
12952 return;
12953 }
12954
David S. Miller9360ffd2012-03-29 04:41:26 -040012955 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12957 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12958 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012959
12960 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12961 if (!rekey_attr)
12962 goto nla_put_failure;
12963
David S. Miller9360ffd2012-03-29 04:41:26 -040012964 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12965 NL80211_REPLAY_CTR_LEN, replay_ctr))
12966 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012967
12968 nla_nest_end(msg, rekey_attr);
12969
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012970 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012971
Johannes Berg68eb5502013-11-19 15:19:38 +010012972 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012973 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012974 return;
12975
12976 nla_put_failure:
12977 genlmsg_cancel(msg, hdr);
12978 nlmsg_free(msg);
12979}
12980
Johannes Berg947add32013-02-22 22:05:20 +010012981void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12982 const u8 *replay_ctr, gfp_t gfp)
12983{
12984 struct wireless_dev *wdev = dev->ieee80211_ptr;
12985 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012986 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012987
12988 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12989 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12990}
12991EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12992
12993static void
12994nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12995 struct net_device *netdev, int index,
12996 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012997{
12998 struct sk_buff *msg;
12999 struct nlattr *attr;
13000 void *hdr;
13001
Thomas Graf58050fc2012-06-28 03:57:45 +000013002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013003 if (!msg)
13004 return;
13005
13006 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13007 if (!hdr) {
13008 nlmsg_free(msg);
13009 return;
13010 }
13011
David S. Miller9360ffd2012-03-29 04:41:26 -040013012 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13013 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13014 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013015
13016 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13017 if (!attr)
13018 goto nla_put_failure;
13019
David S. Miller9360ffd2012-03-29 04:41:26 -040013020 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13021 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13022 (preauth &&
13023 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13024 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013025
13026 nla_nest_end(msg, attr);
13027
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013028 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013029
Johannes Berg68eb5502013-11-19 15:19:38 +010013030 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013031 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013032 return;
13033
13034 nla_put_failure:
13035 genlmsg_cancel(msg, hdr);
13036 nlmsg_free(msg);
13037}
13038
Johannes Berg947add32013-02-22 22:05:20 +010013039void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13040 const u8 *bssid, bool preauth, gfp_t gfp)
13041{
13042 struct wireless_dev *wdev = dev->ieee80211_ptr;
13043 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013044 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013045
13046 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13047 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13048}
13049EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13050
13051static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13052 struct net_device *netdev,
13053 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013054 gfp_t gfp,
13055 enum nl80211_commands notif,
13056 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013057{
13058 struct sk_buff *msg;
13059 void *hdr;
13060
Thomas Graf58050fc2012-06-28 03:57:45 +000013061 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013062 if (!msg)
13063 return;
13064
Luciano Coelhof8d75522014-11-07 14:31:35 +020013065 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013066 if (!hdr) {
13067 nlmsg_free(msg);
13068 return;
13069 }
13070
Johannes Berg683b6d32012-11-08 21:25:48 +010013071 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13072 goto nla_put_failure;
13073
13074 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013075 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013076
Luciano Coelhof8d75522014-11-07 14:31:35 +020013077 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13078 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13079 goto nla_put_failure;
13080
Thomas Pedersen53145262012-04-06 13:35:47 -070013081 genlmsg_end(msg, hdr);
13082
Johannes Berg68eb5502013-11-19 15:19:38 +010013083 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013084 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013085 return;
13086
13087 nla_put_failure:
13088 genlmsg_cancel(msg, hdr);
13089 nlmsg_free(msg);
13090}
13091
Johannes Berg947add32013-02-22 22:05:20 +010013092void cfg80211_ch_switch_notify(struct net_device *dev,
13093 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013094{
Johannes Berg947add32013-02-22 22:05:20 +010013095 struct wireless_dev *wdev = dev->ieee80211_ptr;
13096 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013097 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013098
Simon Wunderliche487eae2013-11-21 18:19:51 +010013099 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013100
Simon Wunderliche487eae2013-11-21 18:19:51 +010013101 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013102
Michal Kazior9e0e2962014-01-29 14:22:27 +010013103 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013104 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013105 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13106 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013107}
13108EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13109
Luciano Coelhof8d75522014-11-07 14:31:35 +020013110void cfg80211_ch_switch_started_notify(struct net_device *dev,
13111 struct cfg80211_chan_def *chandef,
13112 u8 count)
13113{
13114 struct wireless_dev *wdev = dev->ieee80211_ptr;
13115 struct wiphy *wiphy = wdev->wiphy;
13116 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13117
13118 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13119
13120 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13121 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13122}
13123EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13124
Thomas Pedersen84f10702012-07-12 16:17:33 -070013125void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013126nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013127 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013128 enum nl80211_radar_event event,
13129 struct net_device *netdev, gfp_t gfp)
13130{
13131 struct sk_buff *msg;
13132 void *hdr;
13133
13134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13135 if (!msg)
13136 return;
13137
13138 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13139 if (!hdr) {
13140 nlmsg_free(msg);
13141 return;
13142 }
13143
13144 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13145 goto nla_put_failure;
13146
13147 /* NOP and radar events don't need a netdev parameter */
13148 if (netdev) {
13149 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13150
13151 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013152 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13153 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013154 goto nla_put_failure;
13155 }
13156
13157 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13158 goto nla_put_failure;
13159
13160 if (nl80211_send_chandef(msg, chandef))
13161 goto nla_put_failure;
13162
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013163 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013164
Johannes Berg68eb5502013-11-19 15:19:38 +010013165 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013166 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013167 return;
13168
13169 nla_put_failure:
13170 genlmsg_cancel(msg, hdr);
13171 nlmsg_free(msg);
13172}
13173
Johannes Berg7f6cf312011-11-04 11:18:15 +010013174void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13175 u64 cookie, bool acked, gfp_t gfp)
13176{
13177 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013178 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013179 struct sk_buff *msg;
13180 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013181
Beni Lev4ee3e062012-08-27 12:49:39 +030013182 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13183
Thomas Graf58050fc2012-06-28 03:57:45 +000013184 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013185
Johannes Berg7f6cf312011-11-04 11:18:15 +010013186 if (!msg)
13187 return;
13188
13189 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13190 if (!hdr) {
13191 nlmsg_free(msg);
13192 return;
13193 }
13194
David S. Miller9360ffd2012-03-29 04:41:26 -040013195 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13196 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13197 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013198 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13199 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013200 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13201 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013202
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013203 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013204
Johannes Berg68eb5502013-11-19 15:19:38 +010013205 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013206 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013207 return;
13208
13209 nla_put_failure:
13210 genlmsg_cancel(msg, hdr);
13211 nlmsg_free(msg);
13212}
13213EXPORT_SYMBOL(cfg80211_probe_status);
13214
Johannes Berg5e7602302011-11-04 11:18:17 +010013215void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13216 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013217 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013218{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013219 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013220 struct sk_buff *msg;
13221 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013222 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013223
Beni Lev4ee3e062012-08-27 12:49:39 +030013224 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13225
Ben Greear37c73b52012-10-26 14:49:25 -070013226 spin_lock_bh(&rdev->beacon_registrations_lock);
13227 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13228 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13229 if (!msg) {
13230 spin_unlock_bh(&rdev->beacon_registrations_lock);
13231 return;
13232 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013233
Ben Greear37c73b52012-10-26 14:49:25 -070013234 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13235 if (!hdr)
13236 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013237
Ben Greear37c73b52012-10-26 14:49:25 -070013238 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13239 (freq &&
13240 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13241 (sig_dbm &&
13242 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13243 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13244 goto nla_put_failure;
13245
13246 genlmsg_end(msg, hdr);
13247
13248 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013249 }
Ben Greear37c73b52012-10-26 14:49:25 -070013250 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013251 return;
13252
13253 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013254 spin_unlock_bh(&rdev->beacon_registrations_lock);
13255 if (hdr)
13256 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013257 nlmsg_free(msg);
13258}
13259EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13260
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013261#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013262static int cfg80211_net_detect_results(struct sk_buff *msg,
13263 struct cfg80211_wowlan_wakeup *wakeup)
13264{
13265 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13266 struct nlattr *nl_results, *nl_match, *nl_freqs;
13267 int i, j;
13268
13269 nl_results = nla_nest_start(
13270 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13271 if (!nl_results)
13272 return -EMSGSIZE;
13273
13274 for (i = 0; i < nd->n_matches; i++) {
13275 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13276
13277 nl_match = nla_nest_start(msg, i);
13278 if (!nl_match)
13279 break;
13280
13281 /* The SSID attribute is optional in nl80211, but for
13282 * simplicity reasons it's always present in the
13283 * cfg80211 structure. If a driver can't pass the
13284 * SSID, that needs to be changed. A zero length SSID
13285 * is still a valid SSID (wildcard), so it cannot be
13286 * used for this purpose.
13287 */
13288 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13289 match->ssid.ssid)) {
13290 nla_nest_cancel(msg, nl_match);
13291 goto out;
13292 }
13293
13294 if (match->n_channels) {
13295 nl_freqs = nla_nest_start(
13296 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13297 if (!nl_freqs) {
13298 nla_nest_cancel(msg, nl_match);
13299 goto out;
13300 }
13301
13302 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013303 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013304 nla_nest_cancel(msg, nl_freqs);
13305 nla_nest_cancel(msg, nl_match);
13306 goto out;
13307 }
13308 }
13309
13310 nla_nest_end(msg, nl_freqs);
13311 }
13312
13313 nla_nest_end(msg, nl_match);
13314 }
13315
13316out:
13317 nla_nest_end(msg, nl_results);
13318 return 0;
13319}
13320
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013321void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13322 struct cfg80211_wowlan_wakeup *wakeup,
13323 gfp_t gfp)
13324{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013325 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013326 struct sk_buff *msg;
13327 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013328 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013329
13330 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13331
13332 if (wakeup)
13333 size += wakeup->packet_present_len;
13334
13335 msg = nlmsg_new(size, gfp);
13336 if (!msg)
13337 return;
13338
13339 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13340 if (!hdr)
13341 goto free_msg;
13342
13343 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013344 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13345 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013346 goto free_msg;
13347
13348 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13349 wdev->netdev->ifindex))
13350 goto free_msg;
13351
13352 if (wakeup) {
13353 struct nlattr *reasons;
13354
13355 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013356 if (!reasons)
13357 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013358
13359 if (wakeup->disconnect &&
13360 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13361 goto free_msg;
13362 if (wakeup->magic_pkt &&
13363 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13364 goto free_msg;
13365 if (wakeup->gtk_rekey_failure &&
13366 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13367 goto free_msg;
13368 if (wakeup->eap_identity_req &&
13369 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13370 goto free_msg;
13371 if (wakeup->four_way_handshake &&
13372 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13373 goto free_msg;
13374 if (wakeup->rfkill_release &&
13375 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13376 goto free_msg;
13377
13378 if (wakeup->pattern_idx >= 0 &&
13379 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13380 wakeup->pattern_idx))
13381 goto free_msg;
13382
Johannes Bergae917c92013-10-25 11:05:22 +020013383 if (wakeup->tcp_match &&
13384 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13385 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013386
Johannes Bergae917c92013-10-25 11:05:22 +020013387 if (wakeup->tcp_connlost &&
13388 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13389 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013390
Johannes Bergae917c92013-10-25 11:05:22 +020013391 if (wakeup->tcp_nomoretokens &&
13392 nla_put_flag(msg,
13393 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13394 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013395
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013396 if (wakeup->packet) {
13397 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13398 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13399
13400 if (!wakeup->packet_80211) {
13401 pkt_attr =
13402 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13403 len_attr =
13404 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13405 }
13406
13407 if (wakeup->packet_len &&
13408 nla_put_u32(msg, len_attr, wakeup->packet_len))
13409 goto free_msg;
13410
13411 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13412 wakeup->packet))
13413 goto free_msg;
13414 }
13415
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013416 if (wakeup->net_detect &&
13417 cfg80211_net_detect_results(msg, wakeup))
13418 goto free_msg;
13419
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013420 nla_nest_end(msg, reasons);
13421 }
13422
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013423 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013424
Johannes Berg68eb5502013-11-19 15:19:38 +010013425 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013426 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013427 return;
13428
13429 free_msg:
13430 nlmsg_free(msg);
13431}
13432EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13433#endif
13434
Jouni Malinen3475b092012-11-16 22:49:57 +020013435void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13436 enum nl80211_tdls_operation oper,
13437 u16 reason_code, gfp_t gfp)
13438{
13439 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013440 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013441 struct sk_buff *msg;
13442 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013443
13444 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13445 reason_code);
13446
13447 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13448 if (!msg)
13449 return;
13450
13451 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13452 if (!hdr) {
13453 nlmsg_free(msg);
13454 return;
13455 }
13456
13457 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13458 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13459 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13460 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13461 (reason_code > 0 &&
13462 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13463 goto nla_put_failure;
13464
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013465 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013466
Johannes Berg68eb5502013-11-19 15:19:38 +010013467 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013468 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013469 return;
13470
13471 nla_put_failure:
13472 genlmsg_cancel(msg, hdr);
13473 nlmsg_free(msg);
13474}
13475EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13476
Jouni Malinen026331c2010-02-15 12:53:10 +020013477static int nl80211_netlink_notify(struct notifier_block * nb,
13478 unsigned long state,
13479 void *_notify)
13480{
13481 struct netlink_notify *notify = _notify;
13482 struct cfg80211_registered_device *rdev;
13483 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013484 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013485
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013486 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013487 return NOTIFY_DONE;
13488
13489 rcu_read_lock();
13490
Johannes Berg5e7602302011-11-04 11:18:17 +010013491 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013492 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013493 bool schedule_scan_stop = false;
13494 struct cfg80211_sched_scan_request *sched_scan_req =
13495 rcu_dereference(rdev->sched_scan_req);
13496
13497 if (sched_scan_req && notify->portid &&
13498 sched_scan_req->owner_nlportid == notify->portid)
13499 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013500
Johannes Berg53873f12016-05-03 16:52:04 +030013501 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013502 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013503
Johannes Berg78f22b62014-03-24 17:57:27 +010013504 if (wdev->owner_nlportid == notify->portid)
13505 schedule_destroy_work = true;
13506 }
13507
Ben Greear37c73b52012-10-26 14:49:25 -070013508 spin_lock_bh(&rdev->beacon_registrations_lock);
13509 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13510 list) {
13511 if (reg->nlportid == notify->portid) {
13512 list_del(&reg->list);
13513 kfree(reg);
13514 break;
13515 }
13516 }
13517 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013518
13519 if (schedule_destroy_work) {
13520 struct cfg80211_iface_destroy *destroy;
13521
13522 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13523 if (destroy) {
13524 destroy->nlportid = notify->portid;
13525 spin_lock(&rdev->destroy_list_lock);
13526 list_add(&destroy->list, &rdev->destroy_list);
13527 spin_unlock(&rdev->destroy_list_lock);
13528 schedule_work(&rdev->destroy_work);
13529 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013530 } else if (schedule_scan_stop) {
13531 sched_scan_req->owner_nlportid = 0;
13532
13533 if (rdev->ops->sched_scan_stop &&
13534 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13535 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013536 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013537 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013538
13539 rcu_read_unlock();
13540
Ilan peer05050752015-03-04 00:32:06 -050013541 /*
13542 * It is possible that the user space process that is controlling the
13543 * indoor setting disappeared, so notify the regulatory core.
13544 */
13545 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013546 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013547}
13548
13549static struct notifier_block nl80211_netlink_notifier = {
13550 .notifier_call = nl80211_netlink_notify,
13551};
13552
Jouni Malinen355199e2013-02-27 17:14:27 +020013553void cfg80211_ft_event(struct net_device *netdev,
13554 struct cfg80211_ft_event_params *ft_event)
13555{
13556 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013557 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013558 struct sk_buff *msg;
13559 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013560
13561 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13562
13563 if (!ft_event->target_ap)
13564 return;
13565
13566 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13567 if (!msg)
13568 return;
13569
13570 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013571 if (!hdr)
13572 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013573
Johannes Bergae917c92013-10-25 11:05:22 +020013574 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13575 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13576 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13577 goto out;
13578
13579 if (ft_event->ies &&
13580 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13581 goto out;
13582 if (ft_event->ric_ies &&
13583 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13584 ft_event->ric_ies))
13585 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013586
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013587 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013588
Johannes Berg68eb5502013-11-19 15:19:38 +010013589 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013590 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013591 return;
13592 out:
13593 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013594}
13595EXPORT_SYMBOL(cfg80211_ft_event);
13596
Arend van Spriel5de17982013-04-18 15:49:00 +020013597void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13598{
13599 struct cfg80211_registered_device *rdev;
13600 struct sk_buff *msg;
13601 void *hdr;
13602 u32 nlportid;
13603
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013604 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013605 if (!rdev->crit_proto_nlportid)
13606 return;
13607
13608 nlportid = rdev->crit_proto_nlportid;
13609 rdev->crit_proto_nlportid = 0;
13610
13611 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13612 if (!msg)
13613 return;
13614
13615 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13616 if (!hdr)
13617 goto nla_put_failure;
13618
13619 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013620 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13621 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013622 goto nla_put_failure;
13623
13624 genlmsg_end(msg, hdr);
13625
13626 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13627 return;
13628
13629 nla_put_failure:
13630 if (hdr)
13631 genlmsg_cancel(msg, hdr);
13632 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020013633}
13634EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13635
Johannes Berg348baf02014-01-24 14:06:29 +010013636void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13637{
13638 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013639 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013640 struct sk_buff *msg;
13641 void *hdr;
13642
13643 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13644 if (!msg)
13645 return;
13646
13647 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13648 if (!hdr)
13649 goto out;
13650
13651 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13652 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013653 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13654 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013655 goto out;
13656
13657 genlmsg_end(msg, hdr);
13658
13659 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13660 NL80211_MCGRP_MLME, GFP_KERNEL);
13661 return;
13662 out:
13663 nlmsg_free(msg);
13664}
13665
Johannes Berg55682962007-09-20 13:09:35 -040013666/* initialisation/exit functions */
13667
13668int nl80211_init(void)
13669{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013670 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013671
Johannes Berg2a94fe42013-11-19 15:19:39 +010013672 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13673 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013674 if (err)
13675 return err;
13676
Jouni Malinen026331c2010-02-15 12:53:10 +020013677 err = netlink_register_notifier(&nl80211_netlink_notifier);
13678 if (err)
13679 goto err_out;
13680
Johannes Berg55682962007-09-20 13:09:35 -040013681 return 0;
13682 err_out:
13683 genl_unregister_family(&nl80211_fam);
13684 return err;
13685}
13686
13687void nl80211_exit(void)
13688{
Jouni Malinen026331c2010-02-15 12:53:10 +020013689 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013690 genl_unregister_family(&nl80211_fam);
13691}