blob: f02653a08993334f98517d30c9c319f780ce9342 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Beni Lev0c9ca112016-02-17 20:30:00 +02006 * Copyright 2015-2016 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg53873f12016-05-03 16:52:04 +0300106 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee4772012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300152 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700170
Ying Xue7f2b8562014-01-15 10:23:45 +0800171 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200172 if (netdev) {
173 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800174 tmp = wiphy_to_rdev(
175 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200176 else
177 tmp = NULL;
178
Johannes Berg7fee4772012-06-15 14:09:58 +0200179 /* not wireless device -- return error */
180 if (!tmp)
181 return ERR_PTR(-EINVAL);
182
183 /* mismatch -- return error */
184 if (rdev && tmp != rdev)
185 return ERR_PTR(-EINVAL);
186
187 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
Johannes Berga9455402012-06-15 13:32:49 +0200189 }
190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (!rdev)
192 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200193
Johannes Berg4f7eff12012-06-15 14:14:22 +0200194 if (netns != wiphy_net(&rdev->wiphy))
195 return ERR_PTR(-ENODEV);
196
197 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200198}
199
200/*
201 * This function returns a pointer to the driver
202 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200203 *
204 * The result of this can be a PTR_ERR and hence must
205 * be checked with IS_ERR() for errors.
206 */
207static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200208cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200209{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200210 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200211}
212
Johannes Berg55682962007-09-20 13:09:35 -0400213/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300214static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400215 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
216 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700217 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200218 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200220 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530221 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100222 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
224 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
225
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200226 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
228 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
229 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100230 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200231 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400232
233 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
235 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100236
Eliad Pellere007b852011-11-24 18:13:56 +0200237 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
238 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100239
Johannes Bergb9454e82009-07-08 13:29:08 +0200240 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100241 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
242 .len = WLAN_MAX_KEY_LEN },
243 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
244 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
245 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200246 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200247 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100248
249 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
250 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
251 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
253 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100255 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
257 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
258 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
259 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100260 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100261 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200262 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800264 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100265 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700267 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
268 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
269
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300270 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
272 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200273 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
274 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100275 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300276
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800277 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700278 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700279
Johannes Berg6c739412011-11-03 09:27:01 +0100280 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200281
282 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
283 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
284 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100285 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
286 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200287
288 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_SSID_LEN },
290 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
291 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200292 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300293 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300294 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300295 [NL80211_ATTR_STA_FLAGS2] = {
296 .len = sizeof(struct nl80211_sta_flag_update),
297 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300298 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200301 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
302 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
303 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200304 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100305 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100306 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
307 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100308 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
309 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200310 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200311 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
313 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200314 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200315 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300316 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200317 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300318 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
319 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200320 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900321 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
322 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100323 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100324 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100325 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200326 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700327 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300328 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200329 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200330 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300331 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300332 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
334 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530336 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300337 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530338 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300339 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
343 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300344 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100345 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200346 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
347 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700348 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800349 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
351 .len = NL80211_HT_CAPABILITY_LEN
352 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100353 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530354 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530355 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200356 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700357 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300358 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000359 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700360 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100361 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
362 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530363 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
364 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200365 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
366 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100367 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100368 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
369 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
370 .len = NL80211_VHT_CAPABILITY_LEN,
371 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200372 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
373 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
374 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300375 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200376 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
377 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
378 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300379 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
380 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530381 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
382 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200383 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100384 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100385 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
387 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800388 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
389 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200390 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
391 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530392 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200393 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300394 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300395 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300396 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
397 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
398 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300399 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200400 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200401 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200402 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200403 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500404 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200405 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100406 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200407 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300408 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
409 .len = VHT_MUMIMO_GROUPS_DATA_LEN
410 },
411 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Johannes Berg55682962007-09-20 13:09:35 -0400412};
413
Johannes Berge31b8212010-10-05 19:39:30 +0200414/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000415static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200416 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200417 [NL80211_KEY_IDX] = { .type = NLA_U8 },
418 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200419 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200420 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200422 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100423 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
424};
425
426/* policy for the key default flags */
427static const struct nla_policy
428nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
429 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
430 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200431};
432
Johannes Bergff1b6e62011-05-04 15:37:28 +0200433/* policy for WoWLAN attributes */
434static const struct nla_policy
435nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
436 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
437 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
439 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200440 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
441 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
442 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
443 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100444 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300445 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100446};
447
448static const struct nla_policy
449nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
450 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
451 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
452 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
453 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
454 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
455 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
456 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
457 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
458 },
459 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
460 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
461 },
462 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
463 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
464 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200465};
466
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700467/* policy for coalesce rule attributes */
468static const struct nla_policy
469nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
470 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
471 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
472 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
473};
474
Johannes Berge5497d72011-07-05 16:35:40 +0200475/* policy for GTK rekey offload attributes */
476static const struct nla_policy
477nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
478 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
479 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
480 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
481};
482
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300483static const struct nla_policy
484nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200485 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300486 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700487 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300488};
489
Avraham Stern3b06d272015-10-12 09:51:34 +0300490static const struct nla_policy
491nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
492 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
493 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
494};
495
Arend van Spriel38de03d2016-03-02 20:37:18 +0100496static const struct nla_policy
497nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
498 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
499 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
500 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
501 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
502 },
503};
504
Johannes Berg97990a02013-04-19 01:02:55 +0200505static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
506 struct netlink_callback *cb,
507 struct cfg80211_registered_device **rdev,
508 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100509{
Johannes Berg67748892010-10-04 21:14:06 +0200510 int err;
511
Johannes Berg67748892010-10-04 21:14:06 +0200512 rtnl_lock();
513
Johannes Berg97990a02013-04-19 01:02:55 +0200514 if (!cb->args[0]) {
515 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
516 nl80211_fam.attrbuf, nl80211_fam.maxattr,
517 nl80211_policy);
518 if (err)
519 goto out_unlock;
520
521 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
522 nl80211_fam.attrbuf);
523 if (IS_ERR(*wdev)) {
524 err = PTR_ERR(*wdev);
525 goto out_unlock;
526 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800527 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200528 /* 0 is the first index - add 1 to parse only once */
529 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200530 cb->args[1] = (*wdev)->identifier;
531 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200532 /* subtract the 1 again here */
533 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200534 struct wireless_dev *tmp;
535
536 if (!wiphy) {
537 err = -ENODEV;
538 goto out_unlock;
539 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800540 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200541 *wdev = NULL;
542
Johannes Berg53873f12016-05-03 16:52:04 +0300543 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200544 if (tmp->identifier == cb->args[1]) {
545 *wdev = tmp;
546 break;
547 }
548 }
Johannes Berg97990a02013-04-19 01:02:55 +0200549
550 if (!*wdev) {
551 err = -ENODEV;
552 goto out_unlock;
553 }
Johannes Berg67748892010-10-04 21:14:06 +0200554 }
555
Johannes Berg67748892010-10-04 21:14:06 +0200556 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200557 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200558 rtnl_unlock();
559 return err;
560}
561
Johannes Berg97990a02013-04-19 01:02:55 +0200562static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200563{
Johannes Berg67748892010-10-04 21:14:06 +0200564 rtnl_unlock();
565}
566
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100567/* IE validation */
568static bool is_valid_ie_attr(const struct nlattr *attr)
569{
570 const u8 *pos;
571 int len;
572
573 if (!attr)
574 return true;
575
576 pos = nla_data(attr);
577 len = nla_len(attr);
578
579 while (len) {
580 u8 elemlen;
581
582 if (len < 2)
583 return false;
584 len -= 2;
585
586 elemlen = pos[1];
587 if (elemlen > len)
588 return false;
589
590 len -= elemlen;
591 pos += 2 + elemlen;
592 }
593
594 return true;
595}
596
Johannes Berg55682962007-09-20 13:09:35 -0400597/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000598static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400599 int flags, u8 cmd)
600{
601 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000602 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400603}
604
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400605static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100606 struct ieee80211_channel *chan,
607 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400608{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200609 /* Some channels must be completely excluded from the
610 * list to protect old user-space tools from breaking
611 */
612 if (!large && chan->flags &
613 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
614 return 0;
615
David S. Miller9360ffd2012-03-29 04:41:26 -0400616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
617 chan->center_freq))
618 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400619
David S. Miller9360ffd2012-03-29 04:41:26 -0400620 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
621 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
622 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200623 if (chan->flags & IEEE80211_CHAN_NO_IR) {
624 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
625 goto nla_put_failure;
626 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
627 goto nla_put_failure;
628 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100629 if (chan->flags & IEEE80211_CHAN_RADAR) {
630 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
631 goto nla_put_failure;
632 if (large) {
633 u32 time;
634
635 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
636
637 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
638 chan->dfs_state))
639 goto nla_put_failure;
640 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
641 time))
642 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100643 if (nla_put_u32(msg,
644 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
645 chan->dfs_cac_ms))
646 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100647 }
648 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400649
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100650 if (large) {
651 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
652 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
653 goto nla_put_failure;
654 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
655 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
656 goto nla_put_failure;
657 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
658 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
659 goto nla_put_failure;
660 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
661 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
662 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200663 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
664 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
665 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300666 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
667 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200668 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200669 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
670 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
671 goto nla_put_failure;
672 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
673 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
674 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100675 }
676
David S. Miller9360ffd2012-03-29 04:41:26 -0400677 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
678 DBM_TO_MBM(chan->max_power)))
679 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400680
681 return 0;
682
683 nla_put_failure:
684 return -ENOBUFS;
685}
686
Johannes Berg55682962007-09-20 13:09:35 -0400687/* netlink command implementations */
688
Johannes Bergb9454e82009-07-08 13:29:08 +0200689struct key_parse {
690 struct key_params p;
691 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200692 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200693 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100694 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200695};
696
697static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
698{
699 struct nlattr *tb[NL80211_KEY_MAX + 1];
700 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
701 nl80211_key_policy);
702 if (err)
703 return err;
704
705 k->def = !!tb[NL80211_KEY_DEFAULT];
706 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
707
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100708 if (k->def) {
709 k->def_uni = true;
710 k->def_multi = true;
711 }
712 if (k->defmgmt)
713 k->def_multi = true;
714
Johannes Bergb9454e82009-07-08 13:29:08 +0200715 if (tb[NL80211_KEY_IDX])
716 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
717
718 if (tb[NL80211_KEY_DATA]) {
719 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
720 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
721 }
722
723 if (tb[NL80211_KEY_SEQ]) {
724 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
725 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
726 }
727
728 if (tb[NL80211_KEY_CIPHER])
729 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
730
Johannes Berge31b8212010-10-05 19:39:30 +0200731 if (tb[NL80211_KEY_TYPE]) {
732 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
733 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
734 return -EINVAL;
735 }
736
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100737 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
738 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700739
Johannes Berg2da8f412012-01-20 13:52:37 +0100740 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
741 tb[NL80211_KEY_DEFAULT_TYPES],
742 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100743 if (err)
744 return err;
745
746 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
747 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
748 }
749
Johannes Bergb9454e82009-07-08 13:29:08 +0200750 return 0;
751}
752
753static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
754{
755 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
756 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
757 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
758 }
759
760 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
761 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
762 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
763 }
764
765 if (info->attrs[NL80211_ATTR_KEY_IDX])
766 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
767
768 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
769 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
770
771 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
772 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
773
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (k->def) {
775 k->def_uni = true;
776 k->def_multi = true;
777 }
778 if (k->defmgmt)
779 k->def_multi = true;
780
Johannes Berge31b8212010-10-05 19:39:30 +0200781 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
782 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
783 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
784 return -EINVAL;
785 }
786
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100787 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
788 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
789 int err = nla_parse_nested(
790 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
791 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
792 nl80211_key_default_policy);
793 if (err)
794 return err;
795
796 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
797 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
798 }
799
Johannes Bergb9454e82009-07-08 13:29:08 +0200800 return 0;
801}
802
803static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
804{
805 int err;
806
807 memset(k, 0, sizeof(*k));
808 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200809 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200810
811 if (info->attrs[NL80211_ATTR_KEY])
812 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
813 else
814 err = nl80211_parse_key_old(info, k);
815
816 if (err)
817 return err;
818
819 if (k->def && k->defmgmt)
820 return -EINVAL;
821
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100822 if (k->defmgmt) {
823 if (k->def_uni || !k->def_multi)
824 return -EINVAL;
825 }
826
Johannes Bergb9454e82009-07-08 13:29:08 +0200827 if (k->idx != -1) {
828 if (k->defmgmt) {
829 if (k->idx < 4 || k->idx > 5)
830 return -EINVAL;
831 } else if (k->def) {
832 if (k->idx < 0 || k->idx > 3)
833 return -EINVAL;
834 } else {
835 if (k->idx < 0 || k->idx > 5)
836 return -EINVAL;
837 }
838 }
839
840 return 0;
841}
842
Johannes Bergfffd0932009-07-08 14:22:54 +0200843static struct cfg80211_cached_keys *
844nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530845 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200846{
847 struct key_parse parse;
848 struct nlattr *key;
849 struct cfg80211_cached_keys *result;
850 int rem, err, def = 0;
851
852 result = kzalloc(sizeof(*result), GFP_KERNEL);
853 if (!result)
854 return ERR_PTR(-ENOMEM);
855
856 result->def = -1;
857 result->defmgmt = -1;
858
859 nla_for_each_nested(key, keys, rem) {
860 memset(&parse, 0, sizeof(parse));
861 parse.idx = -1;
862
863 err = nl80211_parse_key_new(key, &parse);
864 if (err)
865 goto error;
866 err = -EINVAL;
867 if (!parse.p.key)
868 goto error;
869 if (parse.idx < 0 || parse.idx > 4)
870 goto error;
871 if (parse.def) {
872 if (def)
873 goto error;
874 def = 1;
875 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100876 if (!parse.def_uni || !parse.def_multi)
877 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 } else if (parse.defmgmt)
879 goto error;
880 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200881 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 if (err)
883 goto error;
884 result->params[parse.idx].cipher = parse.p.cipher;
885 result->params[parse.idx].key_len = parse.p.key_len;
886 result->params[parse.idx].key = result->data[parse.idx];
887 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530888
889 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
890 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
891 if (no_ht)
892 *no_ht = true;
893 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200894 }
895
896 return result;
897 error:
898 kfree(result);
899 return ERR_PTR(err);
900}
901
902static int nl80211_key_allowed(struct wireless_dev *wdev)
903{
904 ASSERT_WDEV_LOCK(wdev);
905
Johannes Bergfffd0932009-07-08 14:22:54 +0200906 switch (wdev->iftype) {
907 case NL80211_IFTYPE_AP:
908 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200909 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700910 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200911 break;
912 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200913 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200914 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200915 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200916 return -ENOLINK;
917 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100918 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100919 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100920 case NL80211_IFTYPE_MONITOR:
921 case NL80211_IFTYPE_P2P_DEVICE:
922 case NL80211_IFTYPE_WDS:
923 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200924 return -EINVAL;
925 }
926
927 return 0;
928}
929
Jouni Malinen664834d2014-01-15 00:01:44 +0200930static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
931 struct nlattr *tb)
932{
933 struct ieee80211_channel *chan;
934
935 if (tb == NULL)
936 return NULL;
937 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
938 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
939 return NULL;
940 return chan;
941}
942
Johannes Berg7527a782011-05-13 10:58:57 +0200943static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
944{
945 struct nlattr *nl_modes = nla_nest_start(msg, attr);
946 int i;
947
948 if (!nl_modes)
949 goto nla_put_failure;
950
951 i = 0;
952 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400953 if ((ifmodes & 1) && nla_put_flag(msg, i))
954 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200955 ifmodes >>= 1;
956 i++;
957 }
958
959 nla_nest_end(msg, nl_modes);
960 return 0;
961
962nla_put_failure:
963 return -ENOBUFS;
964}
965
966static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100967 struct sk_buff *msg,
968 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200969{
970 struct nlattr *nl_combis;
971 int i, j;
972
973 nl_combis = nla_nest_start(msg,
974 NL80211_ATTR_INTERFACE_COMBINATIONS);
975 if (!nl_combis)
976 goto nla_put_failure;
977
978 for (i = 0; i < wiphy->n_iface_combinations; i++) {
979 const struct ieee80211_iface_combination *c;
980 struct nlattr *nl_combi, *nl_limits;
981
982 c = &wiphy->iface_combinations[i];
983
984 nl_combi = nla_nest_start(msg, i + 1);
985 if (!nl_combi)
986 goto nla_put_failure;
987
988 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
989 if (!nl_limits)
990 goto nla_put_failure;
991
992 for (j = 0; j < c->n_limits; j++) {
993 struct nlattr *nl_limit;
994
995 nl_limit = nla_nest_start(msg, j + 1);
996 if (!nl_limit)
997 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400998 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
999 c->limits[j].max))
1000 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001001 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1002 c->limits[j].types))
1003 goto nla_put_failure;
1004 nla_nest_end(msg, nl_limit);
1005 }
1006
1007 nla_nest_end(msg, nl_limits);
1008
David S. Miller9360ffd2012-03-29 04:41:26 -04001009 if (c->beacon_int_infra_match &&
1010 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1011 goto nla_put_failure;
1012 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1013 c->num_different_channels) ||
1014 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1015 c->max_interfaces))
1016 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001017 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001018 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1019 c->radar_detect_widths) ||
1020 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1021 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001022 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001023
1024 nla_nest_end(msg, nl_combi);
1025 }
1026
1027 nla_nest_end(msg, nl_combis);
1028
1029 return 0;
1030nla_put_failure:
1031 return -ENOBUFS;
1032}
1033
Johannes Berg3713b4e2013-02-14 16:19:38 +01001034#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001035static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1036 struct sk_buff *msg)
1037{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001038 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001039 struct nlattr *nl_tcp;
1040
1041 if (!tcp)
1042 return 0;
1043
1044 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1045 if (!nl_tcp)
1046 return -ENOBUFS;
1047
1048 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1049 tcp->data_payload_max))
1050 return -ENOBUFS;
1051
1052 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1053 tcp->data_payload_max))
1054 return -ENOBUFS;
1055
1056 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1057 return -ENOBUFS;
1058
1059 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1060 sizeof(*tcp->tok), tcp->tok))
1061 return -ENOBUFS;
1062
1063 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1064 tcp->data_interval_max))
1065 return -ENOBUFS;
1066
1067 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1068 tcp->wake_payload_max))
1069 return -ENOBUFS;
1070
1071 nla_nest_end(msg, nl_tcp);
1072 return 0;
1073}
1074
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001077 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078{
1079 struct nlattr *nl_wowlan;
1080
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001082 return 0;
1083
1084 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1085 if (!nl_wowlan)
1086 return -ENOBUFS;
1087
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001098 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001099 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001101 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001103 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1104 return -ENOBUFS;
1105
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001106 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001107 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001108 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1109 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1110 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1111 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001112 };
1113
1114 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1115 sizeof(pat), &pat))
1116 return -ENOBUFS;
1117 }
1118
Luciano Coelho75453cc2015-01-09 14:06:37 +02001119 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1120 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1121 rdev->wiphy.wowlan->max_nd_match_sets))
1122 return -ENOBUFS;
1123
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001124 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001125 return -ENOBUFS;
1126
Johannes Berg3713b4e2013-02-14 16:19:38 +01001127 nla_nest_end(msg, nl_wowlan);
1128
1129 return 0;
1130}
1131#endif
1132
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001133static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001135{
1136 struct nl80211_coalesce_rule_support rule;
1137
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001138 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001139 return 0;
1140
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001141 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1142 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1143 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1144 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1145 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1146 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001147
1148 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1149 return -ENOBUFS;
1150
1151 return 0;
1152}
1153
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1155 struct ieee80211_supported_band *sband)
1156{
1157 struct nlattr *nl_rates, *nl_rate;
1158 struct ieee80211_rate *rate;
1159 int i;
1160
1161 /* add HT info */
1162 if (sband->ht_cap.ht_supported &&
1163 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1164 sizeof(sband->ht_cap.mcs),
1165 &sband->ht_cap.mcs) ||
1166 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1167 sband->ht_cap.cap) ||
1168 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1169 sband->ht_cap.ampdu_factor) ||
1170 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1171 sband->ht_cap.ampdu_density)))
1172 return -ENOBUFS;
1173
1174 /* add VHT info */
1175 if (sband->vht_cap.vht_supported &&
1176 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1177 sizeof(sband->vht_cap.vht_mcs),
1178 &sband->vht_cap.vht_mcs) ||
1179 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1180 sband->vht_cap.cap)))
1181 return -ENOBUFS;
1182
1183 /* add bitrates */
1184 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1185 if (!nl_rates)
1186 return -ENOBUFS;
1187
1188 for (i = 0; i < sband->n_bitrates; i++) {
1189 nl_rate = nla_nest_start(msg, i);
1190 if (!nl_rate)
1191 return -ENOBUFS;
1192
1193 rate = &sband->bitrates[i];
1194 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1195 rate->bitrate))
1196 return -ENOBUFS;
1197 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1198 nla_put_flag(msg,
1199 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1200 return -ENOBUFS;
1201
1202 nla_nest_end(msg, nl_rate);
1203 }
1204
1205 nla_nest_end(msg, nl_rates);
1206
1207 return 0;
1208}
1209
1210static int
1211nl80211_send_mgmt_stypes(struct sk_buff *msg,
1212 const struct ieee80211_txrx_stypes *mgmt_stypes)
1213{
1214 u16 stypes;
1215 struct nlattr *nl_ftypes, *nl_ifs;
1216 enum nl80211_iftype ift;
1217 int i;
1218
1219 if (!mgmt_stypes)
1220 return 0;
1221
1222 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1223 if (!nl_ifs)
1224 return -ENOBUFS;
1225
1226 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1227 nl_ftypes = nla_nest_start(msg, ift);
1228 if (!nl_ftypes)
1229 return -ENOBUFS;
1230 i = 0;
1231 stypes = mgmt_stypes[ift].tx;
1232 while (stypes) {
1233 if ((stypes & 1) &&
1234 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1235 (i << 4) | IEEE80211_FTYPE_MGMT))
1236 return -ENOBUFS;
1237 stypes >>= 1;
1238 i++;
1239 }
1240 nla_nest_end(msg, nl_ftypes);
1241 }
1242
1243 nla_nest_end(msg, nl_ifs);
1244
1245 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1246 if (!nl_ifs)
1247 return -ENOBUFS;
1248
1249 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1250 nl_ftypes = nla_nest_start(msg, ift);
1251 if (!nl_ftypes)
1252 return -ENOBUFS;
1253 i = 0;
1254 stypes = mgmt_stypes[ift].rx;
1255 while (stypes) {
1256 if ((stypes & 1) &&
1257 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1258 (i << 4) | IEEE80211_FTYPE_MGMT))
1259 return -ENOBUFS;
1260 stypes >>= 1;
1261 i++;
1262 }
1263 nla_nest_end(msg, nl_ftypes);
1264 }
1265 nla_nest_end(msg, nl_ifs);
1266
1267 return 0;
1268}
1269
Johannes Berg86e8cf92013-06-19 10:57:22 +02001270struct nl80211_dump_wiphy_state {
1271 s64 filter_wiphy;
1272 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301273 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 bool split;
1275};
1276
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001278 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001280 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001281{
1282 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001283 struct nlattr *nl_bands, *nl_band;
1284 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001285 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001286 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001287 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001288 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001289 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001291 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001292
Johannes Berg3bb20552014-05-26 13:52:25 +02001293 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001294 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 return -ENOBUFS;
1296
Johannes Berg86e8cf92013-06-19 10:57:22 +02001297 if (WARN_ON(!state))
1298 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001299
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001303 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001305 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001306
Johannes Berg3bb20552014-05-26 13:52:25 +02001307 if (cmd != NL80211_CMD_NEW_WIPHY)
1308 goto finish;
1309
Johannes Berg86e8cf92013-06-19 10:57:22 +02001310 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 case 0:
1312 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001327 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001331 rdev->wiphy.max_match_sets) ||
1332 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1333 rdev->wiphy.max_sched_scan_plans) ||
1334 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1335 rdev->wiphy.max_sched_scan_plan_interval) ||
1336 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1337 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001338 goto nla_put_failure;
1339
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1342 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1345 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1348 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1351 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1354 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001356 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001357 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 state->split_start++;
1359 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 break;
1361 case 1:
1362 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001363 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1364 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001365 goto nla_put_failure;
1366
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001369 goto nla_put_failure;
1370
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1373 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001374
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001376 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001378 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001380
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001381 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001383 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001385
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001386 if ((rdev->wiphy.available_antennas_tx ||
1387 rdev->wiphy.available_antennas_rx) &&
1388 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 u32 tx_ant = 0, rx_ant = 0;
1390 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001391
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001392 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 if (!res) {
1394 if (nla_put_u32(msg,
1395 NL80211_ATTR_WIPHY_ANTENNA_TX,
1396 tx_ant) ||
1397 nla_put_u32(msg,
1398 NL80211_ATTR_WIPHY_ANTENNA_RX,
1399 rx_ant))
1400 goto nla_put_failure;
1401 }
Johannes Bergee688b002008-01-24 19:38:39 +01001402 }
1403
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->split_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 case 2:
1408 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001409 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001411 state->split_start++;
1412 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 break;
1414 case 3:
1415 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1416 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001417 goto nla_put_failure;
1418
Johannes Berg86e8cf92013-06-19 10:57:22 +02001419 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001420 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 struct ieee80211_supported_band *sband;
1422
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001423 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424
1425 if (!sband)
1426 continue;
1427
1428 nl_band = nla_nest_start(msg, band);
1429 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001430 goto nla_put_failure;
1431
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 case 0:
1434 if (nl80211_send_band_rateinfo(msg, sband))
1435 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 state->chan_start++;
1437 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 break;
1439 default:
1440 /* add frequencies */
1441 nl_freqs = nla_nest_start(
1442 msg, NL80211_BAND_ATTR_FREQS);
1443 if (!nl_freqs)
1444 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001445
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 i < sband->n_channels;
1448 i++) {
1449 nl_freq = nla_nest_start(msg, i);
1450 if (!nl_freq)
1451 goto nla_put_failure;
1452
1453 chan = &sband->channels[i];
1454
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 if (nl80211_msg_put_channel(
1456 msg, chan,
1457 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 goto nla_put_failure;
1459
1460 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001461 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 break;
1463 }
1464 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001465 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001467 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 nla_nest_end(msg, nl_freqs);
1469 }
1470
1471 nla_nest_end(msg, nl_band);
1472
Johannes Berg86e8cf92013-06-19 10:57:22 +02001473 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001475 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 band--;
1477 break;
1478 }
Johannes Bergee688b002008-01-24 19:38:39 +01001479 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001481
Johannes Berg57fbcce2016-04-12 15:56:15 +02001482 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001483 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001486
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001488 if (state->band_start == 0 && state->chan_start == 0)
1489 state->split_start++;
1490 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 break;
1492 case 4:
1493 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1494 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001495 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496
1497 i = 0;
1498#define CMD(op, n) \
1499 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001500 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 i++; \
1502 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1503 goto nla_put_failure; \
1504 } \
1505 } while (0)
1506
1507 CMD(add_virtual_intf, NEW_INTERFACE);
1508 CMD(change_virtual_intf, SET_INTERFACE);
1509 CMD(add_key, NEW_KEY);
1510 CMD(start_ap, START_AP);
1511 CMD(add_station, NEW_STATION);
1512 CMD(add_mpath, NEW_MPATH);
1513 CMD(update_mesh_config, SET_MESH_CONFIG);
1514 CMD(change_bss, SET_BSS);
1515 CMD(auth, AUTHENTICATE);
1516 CMD(assoc, ASSOCIATE);
1517 CMD(deauth, DEAUTHENTICATE);
1518 CMD(disassoc, DISASSOCIATE);
1519 CMD(join_ibss, JOIN_IBSS);
1520 CMD(join_mesh, JOIN_MESH);
1521 CMD(set_pmksa, SET_PMKSA);
1522 CMD(del_pmksa, DEL_PMKSA);
1523 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1526 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1527 CMD(mgmt_tx, FRAME);
1528 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 i++;
1531 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1532 goto nla_put_failure;
1533 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1535 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 i++;
1537 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1538 goto nla_put_failure;
1539 }
1540 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 CMD(tdls_mgmt, TDLS_MGMT);
1543 CMD(tdls_oper, TDLS_OPER);
1544 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 CMD(sched_scan_start, START_SCHED_SCAN);
1547 CMD(probe_client, PROBE_CLIENT);
1548 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550 i++;
1551 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1552 goto nla_put_failure;
1553 }
1554 CMD(start_p2p_device, START_P2P_DEVICE);
1555 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001556#ifdef CONFIG_NL80211_TESTMODE
1557 CMD(testmode_cmd, TESTMODE);
1558#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001560 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1561 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001563 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001564 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001565 if (rdev->wiphy.features &
1566 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001567 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001568 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001569 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001570#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001571
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 i++;
1574 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001575 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001576 }
1577
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 i++;
1580 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1581 goto nla_put_failure;
1582 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001583
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001585 state->split_start++;
1586 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 break;
1588 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if (rdev->ops->remain_on_channel &&
1590 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 nla_put_u32(msg,
1592 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001594 goto nla_put_failure;
1595
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1598 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001599
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1601 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split_start++;
1603 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 break;
1605 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001606#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 state->split_start++;
1610 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 break;
1612#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001613 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001614#endif
1615 case 7:
1616 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001617 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001618 goto nla_put_failure;
1619
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001621 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001623
Johannes Berg86e8cf92013-06-19 10:57:22 +02001624 state->split_start++;
1625 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 break;
1627 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001628 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001631 goto nla_put_failure;
1632
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001634 /*
1635 * We can only add the per-channel limit information if the
1636 * dump is split, otherwise it makes it too big. Therefore
1637 * only advertise it in that case.
1638 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001639 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001640 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1641 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 goto nla_put_failure;
1643
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001644 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1647 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 goto nla_put_failure;
1649
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1651 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001652 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001654 goto nla_put_failure;
1655
1656 /*
1657 * Any information below this point is only available to
1658 * applications that can deal with it being split. This
1659 * helps ensure that newly added capabilities don't break
1660 * older tools by overrunning their buffers.
1661 *
1662 * We still increment split_start so that in the split
1663 * case we'll continue with more data in the next round,
1664 * but break unconditionally so unsplit data stops here.
1665 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001666 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001667 break;
1668 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001669 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001670 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 rdev->wiphy.extended_capabilities_len,
1672 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001673 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 rdev->wiphy.extended_capabilities_len,
1675 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001676 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001677
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001678 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001679 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1681 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001682 goto nla_put_failure;
1683
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001684 state->split_start++;
1685 break;
1686 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001687 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001688 goto nla_put_failure;
1689
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001691 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1692 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1693 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001694
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001695 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001696 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001697 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001698 goto nla_put_failure;
1699
Johannes Bergad7e7182013-11-13 13:37:47 +01001700 state->split_start++;
1701 break;
1702 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001704 const struct nl80211_vendor_cmd_info *info;
1705 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001706
Johannes Berg567ffc32013-12-18 14:43:31 +01001707 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1708 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001709 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001710
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1712 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001713 if (nla_put(msg, i + 1, sizeof(*info), info))
1714 goto nla_put_failure;
1715 }
1716 nla_nest_end(msg, nested);
1717 }
1718
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001719 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001720 const struct nl80211_vendor_cmd_info *info;
1721 struct nlattr *nested;
1722
1723 nested = nla_nest_start(msg,
1724 NL80211_ATTR_VENDOR_EVENTS);
1725 if (!nested)
1726 goto nla_put_failure;
1727
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001728 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1729 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001730 if (nla_put(msg, i + 1, sizeof(*info), info))
1731 goto nla_put_failure;
1732 }
1733 nla_nest_end(msg, nested);
1734 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001735 state->split_start++;
1736 break;
1737 case 12:
1738 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1739 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1740 rdev->wiphy.max_num_csa_counters))
1741 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001742
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001743 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1744 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1745 goto nla_put_failure;
1746
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001747 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1748 sizeof(rdev->wiphy.ext_features),
1749 rdev->wiphy.ext_features))
1750 goto nla_put_failure;
1751
Arend van Spriel38de03d2016-03-02 20:37:18 +01001752 if (rdev->wiphy.bss_select_support) {
1753 struct nlattr *nested;
1754 u32 bss_select_support = rdev->wiphy.bss_select_support;
1755
1756 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1757 if (!nested)
1758 goto nla_put_failure;
1759
1760 i = 0;
1761 while (bss_select_support) {
1762 if ((bss_select_support & 1) &&
1763 nla_put_flag(msg, i))
1764 goto nla_put_failure;
1765 i++;
1766 bss_select_support >>= 1;
1767 }
1768 nla_nest_end(msg, nested);
1769 }
1770
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301771 state->split_start++;
1772 break;
1773 case 13:
1774 if (rdev->wiphy.num_iftype_ext_capab &&
1775 rdev->wiphy.iftype_ext_capab) {
1776 struct nlattr *nested_ext_capab, *nested;
1777
1778 nested = nla_nest_start(msg,
1779 NL80211_ATTR_IFTYPE_EXT_CAPA);
1780 if (!nested)
1781 goto nla_put_failure;
1782
1783 for (i = state->capa_start;
1784 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1785 const struct wiphy_iftype_ext_capab *capab;
1786
1787 capab = &rdev->wiphy.iftype_ext_capab[i];
1788
1789 nested_ext_capab = nla_nest_start(msg, i);
1790 if (!nested_ext_capab ||
1791 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1792 capab->iftype) ||
1793 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1794 capab->extended_capabilities_len,
1795 capab->extended_capabilities) ||
1796 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1797 capab->extended_capabilities_len,
1798 capab->extended_capabilities_mask))
1799 goto nla_put_failure;
1800
1801 nla_nest_end(msg, nested_ext_capab);
1802 if (state->split)
1803 break;
1804 }
1805 nla_nest_end(msg, nested);
1806 if (i < rdev->wiphy.num_iftype_ext_capab) {
1807 state->capa_start = i + 1;
1808 break;
1809 }
1810 }
1811
Johannes Berg3713b4e2013-02-14 16:19:38 +01001812 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001815 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001816 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001817 genlmsg_end(msg, hdr);
1818 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001819
1820 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001821 genlmsg_cancel(msg, hdr);
1822 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001823}
1824
Johannes Berg86e8cf92013-06-19 10:57:22 +02001825static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1826 struct netlink_callback *cb,
1827 struct nl80211_dump_wiphy_state *state)
1828{
1829 struct nlattr **tb = nl80211_fam.attrbuf;
1830 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1831 tb, nl80211_fam.maxattr, nl80211_policy);
1832 /* ignore parse errors for backward compatibility */
1833 if (ret)
1834 return 0;
1835
1836 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1837 if (tb[NL80211_ATTR_WIPHY])
1838 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1839 if (tb[NL80211_ATTR_WDEV])
1840 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1841 if (tb[NL80211_ATTR_IFINDEX]) {
1842 struct net_device *netdev;
1843 struct cfg80211_registered_device *rdev;
1844 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1845
Ying Xue7f2b8562014-01-15 10:23:45 +08001846 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001847 if (!netdev)
1848 return -ENODEV;
1849 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001850 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001851 netdev->ieee80211_ptr->wiphy);
1852 state->filter_wiphy = rdev->wiphy_idx;
1853 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001854 }
1855
1856 return 0;
1857}
1858
Johannes Berg55682962007-09-20 13:09:35 -04001859static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1860{
Johannes Berg645e77d2013-03-01 14:03:49 +01001861 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001862 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001863 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001864
Johannes Berg5fe231e2013-05-08 21:45:15 +02001865 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001866 if (!state) {
1867 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001868 if (!state) {
1869 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001870 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001871 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001872 state->filter_wiphy = -1;
1873 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1874 if (ret) {
1875 kfree(state);
1876 rtnl_unlock();
1877 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001878 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001879 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001880 }
1881
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001882 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1883 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001884 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001885 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001886 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001887 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001888 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001889 continue;
1890 /* attempt to fit multiple wiphy data chunks into the skb */
1891 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001892 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1893 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001894 NETLINK_CB(cb->skb).portid,
1895 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001896 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001897 if (ret < 0) {
1898 /*
1899 * If sending the wiphy data didn't fit (ENOBUFS
1900 * or EMSGSIZE returned), this SKB is still
1901 * empty (so it's not too big because another
1902 * wiphy dataset is already in the skb) and
1903 * we've not tried to adjust the dump allocation
1904 * yet ... then adjust the alloc size to be
1905 * bigger, and return 1 but with the empty skb.
1906 * This results in an empty message being RX'ed
1907 * in userspace, but that is ignored.
1908 *
1909 * We can then retry with the larger buffer.
1910 */
1911 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001912 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001913 cb->min_dump_alloc < 4096) {
1914 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001915 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001916 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001917 return 1;
1918 }
1919 idx--;
1920 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001921 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001922 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001923 break;
Johannes Berg55682962007-09-20 13:09:35 -04001924 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001925 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001926
Johannes Berg86e8cf92013-06-19 10:57:22 +02001927 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001928
1929 return skb->len;
1930}
1931
Johannes Berg86e8cf92013-06-19 10:57:22 +02001932static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1933{
1934 kfree((void *)cb->args[0]);
1935 return 0;
1936}
1937
Johannes Berg55682962007-09-20 13:09:35 -04001938static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1939{
1940 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001942 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001943
Johannes Berg645e77d2013-03-01 14:03:49 +01001944 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001945 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001946 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001947
Johannes Berg3bb20552014-05-26 13:52:25 +02001948 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1949 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001950 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001951 nlmsg_free(msg);
1952 return -ENOBUFS;
1953 }
Johannes Berg55682962007-09-20 13:09:35 -04001954
Johannes Berg134e6372009-07-10 09:51:34 +00001955 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001956}
1957
Jouni Malinen31888482008-10-30 16:59:24 +02001958static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1959 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1960 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1961 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1962 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1963 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1964};
1965
1966static int parse_txq_params(struct nlattr *tb[],
1967 struct ieee80211_txq_params *txq_params)
1968{
Johannes Berga3304b02012-03-28 11:04:24 +02001969 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001970 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1971 !tb[NL80211_TXQ_ATTR_AIFS])
1972 return -EINVAL;
1973
Johannes Berga3304b02012-03-28 11:04:24 +02001974 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001975 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1976 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1977 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1978 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1979
Johannes Berga3304b02012-03-28 11:04:24 +02001980 if (txq_params->ac >= NL80211_NUM_ACS)
1981 return -EINVAL;
1982
Jouni Malinen31888482008-10-30 16:59:24 +02001983 return 0;
1984}
1985
Johannes Bergf444de02010-05-05 15:25:02 +02001986static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1987{
1988 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001989 * You can only set the channel explicitly for WDS interfaces,
1990 * all others have their channel managed via their respective
1991 * "establish a connection" command (connect, join, ...)
1992 *
1993 * For AP/GO and mesh mode, the channel can be set with the
1994 * channel userspace API, but is only stored and passed to the
1995 * low-level driver when the AP starts or the mesh is joined.
1996 * This is for backward compatibility, userspace can also give
1997 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001998 *
1999 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002000 * whatever else is going on, so they have their own special
2001 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002002 */
2003 return !wdev ||
2004 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002005 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002006 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2007 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002008}
2009
Johannes Berg683b6d32012-11-08 21:25:48 +01002010static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2011 struct genl_info *info,
2012 struct cfg80211_chan_def *chandef)
2013{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302014 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002015
2016 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2017 return -EINVAL;
2018
2019 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2020
2021 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002022 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2023 chandef->center_freq1 = control_freq;
2024 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002025
2026 /* Primary channel not allowed */
2027 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2028 return -EINVAL;
2029
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002030 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2031 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002032
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002033 chantype = nla_get_u32(
2034 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2035
2036 switch (chantype) {
2037 case NL80211_CHAN_NO_HT:
2038 case NL80211_CHAN_HT20:
2039 case NL80211_CHAN_HT40PLUS:
2040 case NL80211_CHAN_HT40MINUS:
2041 cfg80211_chandef_create(chandef, chandef->chan,
2042 chantype);
2043 break;
2044 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002045 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002046 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002047 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2048 chandef->width =
2049 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2050 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2051 chandef->center_freq1 =
2052 nla_get_u32(
2053 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2054 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2055 chandef->center_freq2 =
2056 nla_get_u32(
2057 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2058 }
2059
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002060 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002061 return -EINVAL;
2062
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002063 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2064 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002065 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002066
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002067 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2068 chandef->width == NL80211_CHAN_WIDTH_10) &&
2069 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2070 return -EINVAL;
2071
Johannes Berg683b6d32012-11-08 21:25:48 +01002072 return 0;
2073}
2074
Johannes Bergf444de02010-05-05 15:25:02 +02002075static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002076 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002077 struct genl_info *info)
2078{
Johannes Berg683b6d32012-11-08 21:25:48 +01002079 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002080 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002081 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002082 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002083
Jouni Malinene16821b2014-04-28 11:22:08 +03002084 if (dev)
2085 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002086 if (!nl80211_can_set_dev_channel(wdev))
2087 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002088 if (wdev)
2089 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002090
Johannes Berg683b6d32012-11-08 21:25:48 +01002091 result = nl80211_parse_chandef(rdev, info, &chandef);
2092 if (result)
2093 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002094
Johannes Berge8c9bd52012-06-06 08:18:22 +02002095 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002096 case NL80211_IFTYPE_AP:
2097 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002098 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2099 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002100 result = -EINVAL;
2101 break;
2102 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002103 if (wdev->beacon_interval) {
2104 if (!dev || !rdev->ops->set_ap_chanwidth ||
2105 !(rdev->wiphy.features &
2106 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2107 result = -EBUSY;
2108 break;
2109 }
2110
2111 /* Only allow dynamic channel width changes */
2112 if (chandef.chan != wdev->preset_chandef.chan) {
2113 result = -EBUSY;
2114 break;
2115 }
2116 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2117 if (result)
2118 break;
2119 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002120 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002121 result = 0;
2122 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002123 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002124 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002125 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002126 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002127 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002128 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002129 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002130 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002131 }
Johannes Bergf444de02010-05-05 15:25:02 +02002132
2133 return result;
2134}
2135
2136static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2137{
Johannes Berg4c476992010-10-04 21:36:35 +02002138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2139 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002140
Jouni Malinene16821b2014-04-28 11:22:08 +03002141 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002142}
2143
Bill Jordane8347eb2010-10-01 13:54:28 -04002144static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2145{
Johannes Berg43b19952010-10-07 13:10:30 +02002146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2147 struct net_device *dev = info->user_ptr[1];
2148 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002149 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002150
2151 if (!info->attrs[NL80211_ATTR_MAC])
2152 return -EINVAL;
2153
Johannes Berg43b19952010-10-07 13:10:30 +02002154 if (netif_running(dev))
2155 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002156
Johannes Berg43b19952010-10-07 13:10:30 +02002157 if (!rdev->ops->set_wds_peer)
2158 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002159
Johannes Berg43b19952010-10-07 13:10:30 +02002160 if (wdev->iftype != NL80211_IFTYPE_WDS)
2161 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002162
2163 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002164 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002165}
2166
Johannes Berg55682962007-09-20 13:09:35 -04002167static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2168{
2169 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002170 struct net_device *netdev = NULL;
2171 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002172 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002173 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002174 u32 changed;
2175 u8 retry_short = 0, retry_long = 0;
2176 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002177 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002178
Johannes Berg5fe231e2013-05-08 21:45:15 +02002179 ASSERT_RTNL();
2180
Johannes Bergf444de02010-05-05 15:25:02 +02002181 /*
2182 * Try to find the wiphy and netdev. Normally this
2183 * function shouldn't need the netdev, but this is
2184 * done for backward compatibility -- previously
2185 * setting the channel was done per wiphy, but now
2186 * it is per netdev. Previous userland like hostapd
2187 * also passed a netdev to set_wiphy, so that it is
2188 * possible to let that go to the right netdev!
2189 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002190
Johannes Bergf444de02010-05-05 15:25:02 +02002191 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2192 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2193
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002195 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002196 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002197 else
Johannes Bergf444de02010-05-05 15:25:02 +02002198 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002199 }
2200
Johannes Bergf444de02010-05-05 15:25:02 +02002201 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002202 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2203 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002204 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002205 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002206 wdev = NULL;
2207 netdev = NULL;
2208 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002209 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002210 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002211
2212 /*
2213 * end workaround code, by now the rdev is available
2214 * and locked, and wdev may or may not be NULL.
2215 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002216
2217 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002218 result = cfg80211_dev_rename(
2219 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002220
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002221 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002222 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002223
Jouni Malinen31888482008-10-30 16:59:24 +02002224 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2225 struct ieee80211_txq_params txq_params;
2226 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2227
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 if (!rdev->ops->set_txq_params)
2229 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002230
Ying Xue7f2b8562014-01-15 10:23:45 +08002231 if (!netdev)
2232 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002233
Johannes Berg133a3ff2011-11-03 14:50:13 +01002234 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002235 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2236 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002237
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 if (!netif_running(netdev))
2239 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002240
Jouni Malinen31888482008-10-30 16:59:24 +02002241 nla_for_each_nested(nl_txq_params,
2242 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2243 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002244 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2245 nla_data(nl_txq_params),
2246 nla_len(nl_txq_params),
2247 txq_params_policy);
2248 if (result)
2249 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002250 result = parse_txq_params(tb, &txq_params);
2251 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002252 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002253
Hila Gonene35e4d22012-06-27 17:19:42 +03002254 result = rdev_set_txq_params(rdev, netdev,
2255 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002256 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002257 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002258 }
2259 }
2260
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002261 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002262 result = __nl80211_set_channel(
2263 rdev,
2264 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2265 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002266 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002267 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002268 }
2269
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002270 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002271 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002272 enum nl80211_tx_power_setting type;
2273 int idx, mbm = 0;
2274
Johannes Bergc8442112012-10-24 10:17:18 +02002275 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2276 txp_wdev = NULL;
2277
Ying Xue7f2b8562014-01-15 10:23:45 +08002278 if (!rdev->ops->set_tx_power)
2279 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002280
2281 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2282 type = nla_get_u32(info->attrs[idx]);
2283
2284 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002285 (type != NL80211_TX_POWER_AUTOMATIC))
2286 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002287
2288 if (type != NL80211_TX_POWER_AUTOMATIC) {
2289 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2290 mbm = nla_get_u32(info->attrs[idx]);
2291 }
2292
Johannes Bergc8442112012-10-24 10:17:18 +02002293 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002294 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002295 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002296 }
2297
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002298 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2299 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2300 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002301
Bruno Randolf7f531e02010-12-16 11:30:22 +09002302 if ((!rdev->wiphy.available_antennas_tx &&
2303 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002304 !rdev->ops->set_antenna)
2305 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002306
2307 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2308 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2309
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002310 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002311 * available antenna masks, except for the "all" mask */
2312 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002313 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2314 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002315
Bruno Randolf7f531e02010-12-16 11:30:22 +09002316 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2317 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002318
Hila Gonene35e4d22012-06-27 17:19:42 +03002319 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002320 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002321 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002322 }
2323
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002324 changed = 0;
2325
2326 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2327 retry_short = nla_get_u8(
2328 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 if (retry_short == 0)
2330 return -EINVAL;
2331
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002332 changed |= WIPHY_PARAM_RETRY_SHORT;
2333 }
2334
2335 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2336 retry_long = nla_get_u8(
2337 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002338 if (retry_long == 0)
2339 return -EINVAL;
2340
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002341 changed |= WIPHY_PARAM_RETRY_LONG;
2342 }
2343
2344 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2345 frag_threshold = nla_get_u32(
2346 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002347 if (frag_threshold < 256)
2348 return -EINVAL;
2349
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002350 if (frag_threshold != (u32) -1) {
2351 /*
2352 * Fragments (apart from the last one) are required to
2353 * have even length. Make the fragmentation code
2354 * simpler by stripping LSB should someone try to use
2355 * odd threshold value.
2356 */
2357 frag_threshold &= ~0x1;
2358 }
2359 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2360 }
2361
2362 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2363 rts_threshold = nla_get_u32(
2364 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2365 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2366 }
2367
Lukáš Turek81077e82009-12-21 22:50:47 +01002368 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002369 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2370 return -EINVAL;
2371
Lukáš Turek81077e82009-12-21 22:50:47 +01002372 coverage_class = nla_get_u8(
2373 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2374 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2375 }
2376
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002377 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2378 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2379 return -EOPNOTSUPP;
2380
2381 changed |= WIPHY_PARAM_DYN_ACK;
2382 }
2383
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002384 if (changed) {
2385 u8 old_retry_short, old_retry_long;
2386 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002387 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002388
Ying Xue7f2b8562014-01-15 10:23:45 +08002389 if (!rdev->ops->set_wiphy_params)
2390 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002391
2392 old_retry_short = rdev->wiphy.retry_short;
2393 old_retry_long = rdev->wiphy.retry_long;
2394 old_frag_threshold = rdev->wiphy.frag_threshold;
2395 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002396 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002397
2398 if (changed & WIPHY_PARAM_RETRY_SHORT)
2399 rdev->wiphy.retry_short = retry_short;
2400 if (changed & WIPHY_PARAM_RETRY_LONG)
2401 rdev->wiphy.retry_long = retry_long;
2402 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2403 rdev->wiphy.frag_threshold = frag_threshold;
2404 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2405 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002406 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2407 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002408
Hila Gonene35e4d22012-06-27 17:19:42 +03002409 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002410 if (result) {
2411 rdev->wiphy.retry_short = old_retry_short;
2412 rdev->wiphy.retry_long = old_retry_long;
2413 rdev->wiphy.frag_threshold = old_frag_threshold;
2414 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002415 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002416 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002417 }
2418 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002419 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002420}
2421
Johannes Berg71bbc992012-06-15 15:30:18 +02002422static inline u64 wdev_id(struct wireless_dev *wdev)
2423{
2424 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002425 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002426}
Johannes Berg55682962007-09-20 13:09:35 -04002427
Johannes Berg683b6d32012-11-08 21:25:48 +01002428static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002429 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002430{
Johannes Berg601555c2014-11-27 17:26:56 +01002431 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2432 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002433
Johannes Berg683b6d32012-11-08 21:25:48 +01002434 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2435 chandef->chan->center_freq))
2436 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002437 switch (chandef->width) {
2438 case NL80211_CHAN_WIDTH_20_NOHT:
2439 case NL80211_CHAN_WIDTH_20:
2440 case NL80211_CHAN_WIDTH_40:
2441 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2442 cfg80211_get_chandef_type(chandef)))
2443 return -ENOBUFS;
2444 break;
2445 default:
2446 break;
2447 }
2448 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2449 return -ENOBUFS;
2450 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2451 return -ENOBUFS;
2452 if (chandef->center_freq2 &&
2453 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002454 return -ENOBUFS;
2455 return 0;
2456}
2457
Eric W. Biederman15e47302012-09-07 20:12:54 +00002458static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002459 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002460 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002461{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002462 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002463 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002464 void *hdr;
2465
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002466 if (removal)
2467 cmd = NL80211_CMD_DEL_INTERFACE;
2468
2469 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002470 if (!hdr)
2471 return -1;
2472
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002473 if (dev &&
2474 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002475 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002476 goto nla_put_failure;
2477
2478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2479 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002480 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2481 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002482 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002483 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2484 rdev->devlist_generation ^
2485 (cfg80211_rdev_list_generation << 2)))
2486 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002487
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002488 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002489 int ret;
2490 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002491
Johannes Berg683b6d32012-11-08 21:25:48 +01002492 ret = rdev_get_channel(rdev, wdev, &chandef);
2493 if (ret == 0) {
2494 if (nl80211_send_chandef(msg, &chandef))
2495 goto nla_put_failure;
2496 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002497 }
2498
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002499 if (rdev->ops->get_tx_power) {
2500 int dbm, ret;
2501
2502 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2503 if (ret == 0 &&
2504 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2505 DBM_TO_MBM(dbm)))
2506 goto nla_put_failure;
2507 }
2508
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002509 if (wdev->ssid_len) {
2510 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2511 goto nla_put_failure;
2512 }
2513
Johannes Berg053c0952015-01-16 22:09:00 +01002514 genlmsg_end(msg, hdr);
2515 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002516
2517 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002518 genlmsg_cancel(msg, hdr);
2519 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002520}
2521
2522static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2523{
2524 int wp_idx = 0;
2525 int if_idx = 0;
2526 int wp_start = cb->args[0];
2527 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002528 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002529 struct wireless_dev *wdev;
2530
Johannes Berg5fe231e2013-05-08 21:45:15 +02002531 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002532 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2533 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002534 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002535 if (wp_idx < wp_start) {
2536 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002537 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002538 }
Johannes Berg55682962007-09-20 13:09:35 -04002539 if_idx = 0;
2540
Johannes Berg53873f12016-05-03 16:52:04 +03002541 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002542 if (if_idx < if_start) {
2543 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002544 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002545 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002546 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002547 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002548 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002549 goto out;
2550 }
2551 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002552 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002553
2554 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002555 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002556 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002557 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002558
2559 cb->args[0] = wp_idx;
2560 cb->args[1] = if_idx;
2561
2562 return skb->len;
2563}
2564
2565static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2566{
2567 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002569 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002570
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002571 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002572 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002573 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002574
Eric W. Biederman15e47302012-09-07 20:12:54 +00002575 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002576 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002577 nlmsg_free(msg);
2578 return -ENOBUFS;
2579 }
Johannes Berg55682962007-09-20 13:09:35 -04002580
Johannes Berg134e6372009-07-10 09:51:34 +00002581 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002582}
2583
Michael Wu66f7ac52008-01-31 19:48:22 +01002584static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2585 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2586 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2587 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2588 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2589 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002590 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002591};
2592
2593static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2594{
2595 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2596 int flag;
2597
2598 *mntrflags = 0;
2599
2600 if (!nla)
2601 return -EINVAL;
2602
2603 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2604 nla, mntr_flags_policy))
2605 return -EINVAL;
2606
2607 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2608 if (flags[flag])
2609 *mntrflags |= (1<<flag);
2610
2611 return 0;
2612}
2613
Johannes Berg9bc383d2009-11-19 11:55:19 +01002614static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002615 struct net_device *netdev, u8 use_4addr,
2616 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002617{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002618 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002619 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002620 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002621 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002622 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002623
2624 switch (iftype) {
2625 case NL80211_IFTYPE_AP_VLAN:
2626 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2627 return 0;
2628 break;
2629 case NL80211_IFTYPE_STATION:
2630 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2631 return 0;
2632 break;
2633 default:
2634 break;
2635 }
2636
2637 return -EOPNOTSUPP;
2638}
2639
Johannes Berg55682962007-09-20 13:09:35 -04002640static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2641{
Johannes Berg4c476992010-10-04 21:36:35 +02002642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002643 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002644 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002645 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002646 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002647 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002648 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002649
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002650 memset(&params, 0, sizeof(params));
2651
Johannes Berg04a773a2009-04-19 21:24:32 +02002652 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002653
Johannes Berg723b0382008-09-16 20:22:09 +02002654 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002655 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002656 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002657 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (ntype > NL80211_IFTYPE_MAX)
2659 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002660 }
2661
Johannes Berg92ffe052008-09-16 20:39:36 +02002662 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002663 struct wireless_dev *wdev = dev->ieee80211_ptr;
2664
Johannes Berg4c476992010-10-04 21:36:35 +02002665 if (ntype != NL80211_IFTYPE_MESH_POINT)
2666 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002667 if (netif_running(dev))
2668 return -EBUSY;
2669
2670 wdev_lock(wdev);
2671 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2672 IEEE80211_MAX_MESH_ID_LEN);
2673 wdev->mesh_id_up_len =
2674 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2675 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2676 wdev->mesh_id_up_len);
2677 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002678 }
2679
Felix Fietkau8b787642009-11-10 18:53:10 +01002680 if (info->attrs[NL80211_ATTR_4ADDR]) {
2681 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2682 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002683 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002684 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002685 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002686 } else {
2687 params.use_4addr = -1;
2688 }
2689
Johannes Berg92ffe052008-09-16 20:39:36 +02002690 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002691 if (ntype != NL80211_IFTYPE_MONITOR)
2692 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002693 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2694 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002695 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002696 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002697
2698 flags = &_flags;
2699 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002700 }
Johannes Berg3b858752009-03-12 09:55:09 +01002701
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002702 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2703 const u8 *mumimo_groups;
2704 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2705
2706 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2707 return -EOPNOTSUPP;
2708
2709 mumimo_groups =
2710 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2711
2712 /* bits 0 and 63 are reserved and must be zero */
2713 if ((mumimo_groups[0] & BIT(7)) ||
2714 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2715 return -EINVAL;
2716
2717 memcpy(params.vht_mumimo_groups, mumimo_groups,
2718 VHT_MUMIMO_GROUPS_DATA_LEN);
2719 change = true;
2720 }
2721
2722 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2723 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2724
2725 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2726 return -EOPNOTSUPP;
2727
2728 nla_memcpy(params.macaddr,
2729 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2730 ETH_ALEN);
2731 change = true;
2732 }
2733
Luciano Coelho18003292013-08-29 13:26:57 +03002734 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002735 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2736 return -EOPNOTSUPP;
2737
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002738 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002739 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002740 else
2741 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002742
Johannes Berg9bc383d2009-11-19 11:55:19 +01002743 if (!err && params.use_4addr != -1)
2744 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2745
Johannes Berg55682962007-09-20 13:09:35 -04002746 return err;
2747}
2748
2749static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2750{
Johannes Berg4c476992010-10-04 21:36:35 +02002751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002752 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002753 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002754 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002755 int err;
2756 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002757 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002758
Johannes Berg78f22b62014-03-24 17:57:27 +01002759 /* to avoid failing a new interface creation due to pending removal */
2760 cfg80211_destroy_ifaces(rdev);
2761
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002762 memset(&params, 0, sizeof(params));
2763
Johannes Berg55682962007-09-20 13:09:35 -04002764 if (!info->attrs[NL80211_ATTR_IFNAME])
2765 return -EINVAL;
2766
2767 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2768 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2769 if (type > NL80211_IFTYPE_MAX)
2770 return -EINVAL;
2771 }
2772
Johannes Berg79c97e92009-07-07 03:56:12 +02002773 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002774 !(rdev->wiphy.interface_modes & (1 << type)))
2775 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002776
Ben Greeare8f479b2014-10-22 12:23:05 -07002777 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2778 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2779 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002780 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2781 ETH_ALEN);
2782 if (!is_valid_ether_addr(params.macaddr))
2783 return -EADDRNOTAVAIL;
2784 }
2785
Johannes Berg9bc383d2009-11-19 11:55:19 +01002786 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002787 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002788 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002789 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002790 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002791 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002792
Michael Wu66f7ac52008-01-31 19:48:22 +01002793 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2794 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2795 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002796
Luciano Coelho18003292013-08-29 13:26:57 +03002797 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002798 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2799 return -EOPNOTSUPP;
2800
Johannes Berga18c7192015-02-24 10:56:42 +01002801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2802 if (!msg)
2803 return -ENOMEM;
2804
Hila Gonene35e4d22012-06-27 17:19:42 +03002805 wdev = rdev_add_virtual_intf(rdev,
2806 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002807 NET_NAME_USER, type, err ? NULL : &flags,
2808 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002809 if (WARN_ON(!wdev)) {
2810 nlmsg_free(msg);
2811 return -EPROTO;
2812 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002813 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002814 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002815 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002816
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002817 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002818 wdev->owner_nlportid = info->snd_portid;
2819
Johannes Berg98104fde2012-06-16 00:19:54 +02002820 switch (type) {
2821 case NL80211_IFTYPE_MESH_POINT:
2822 if (!info->attrs[NL80211_ATTR_MESH_ID])
2823 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002824 wdev_lock(wdev);
2825 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2826 IEEE80211_MAX_MESH_ID_LEN);
2827 wdev->mesh_id_up_len =
2828 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2829 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2830 wdev->mesh_id_up_len);
2831 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002832 break;
2833 case NL80211_IFTYPE_P2P_DEVICE:
2834 /*
2835 * P2P Device doesn't have a netdev, so doesn't go
2836 * through the netdev notifier and must be added here
2837 */
2838 mutex_init(&wdev->mtx);
2839 INIT_LIST_HEAD(&wdev->event_list);
2840 spin_lock_init(&wdev->event_lock);
2841 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2842 spin_lock_init(&wdev->mgmt_registrations_lock);
2843
Johannes Berg98104fde2012-06-16 00:19:54 +02002844 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002845 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002846 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002847 break;
2848 default:
2849 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002850 }
2851
Eric W. Biederman15e47302012-09-07 20:12:54 +00002852 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002853 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002854 nlmsg_free(msg);
2855 return -ENOBUFS;
2856 }
2857
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002858 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2859 if (event) {
2860 if (nl80211_send_iface(event, 0, 0, 0,
2861 rdev, wdev, false) < 0) {
2862 nlmsg_free(event);
2863 goto out;
2864 }
2865
2866 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2867 event, 0, NL80211_MCGRP_CONFIG,
2868 GFP_KERNEL);
2869 }
2870
2871out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002872 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002873}
2874
2875static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2876{
Johannes Berg4c476992010-10-04 21:36:35 +02002877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002878 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002879 struct sk_buff *msg;
2880 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002881
Johannes Berg4c476992010-10-04 21:36:35 +02002882 if (!rdev->ops->del_virtual_intf)
2883 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002884
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002885 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2886 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2887 nlmsg_free(msg);
2888 msg = NULL;
2889 }
2890
Johannes Berg84efbb82012-06-16 00:00:26 +02002891 /*
2892 * If we remove a wireless device without a netdev then clear
2893 * user_ptr[1] so that nl80211_post_doit won't dereference it
2894 * to check if it needs to do dev_put(). Otherwise it crashes
2895 * since the wdev has been freed, unlike with a netdev where
2896 * we need the dev_put() for the netdev to really be freed.
2897 */
2898 if (!wdev->netdev)
2899 info->user_ptr[1] = NULL;
2900
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002901 status = rdev_del_virtual_intf(rdev, wdev);
2902 if (status >= 0 && msg)
2903 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2904 msg, 0, NL80211_MCGRP_CONFIG,
2905 GFP_KERNEL);
2906 else
2907 nlmsg_free(msg);
2908
2909 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002910}
2911
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002912static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2913{
2914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2915 struct net_device *dev = info->user_ptr[1];
2916 u16 noack_map;
2917
2918 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2919 return -EINVAL;
2920
2921 if (!rdev->ops->set_noack_map)
2922 return -EOPNOTSUPP;
2923
2924 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2925
Hila Gonene35e4d22012-06-27 17:19:42 +03002926 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002927}
2928
Johannes Berg41ade002007-12-19 02:03:29 +01002929struct get_key_cookie {
2930 struct sk_buff *msg;
2931 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002932 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002933};
2934
2935static void get_key_callback(void *c, struct key_params *params)
2936{
Johannes Bergb9454e82009-07-08 13:29:08 +02002937 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002938 struct get_key_cookie *cookie = c;
2939
David S. Miller9360ffd2012-03-29 04:41:26 -04002940 if ((params->key &&
2941 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2942 params->key_len, params->key)) ||
2943 (params->seq &&
2944 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2945 params->seq_len, params->seq)) ||
2946 (params->cipher &&
2947 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2948 params->cipher)))
2949 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002950
Johannes Bergb9454e82009-07-08 13:29:08 +02002951 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2952 if (!key)
2953 goto nla_put_failure;
2954
David S. Miller9360ffd2012-03-29 04:41:26 -04002955 if ((params->key &&
2956 nla_put(cookie->msg, NL80211_KEY_DATA,
2957 params->key_len, params->key)) ||
2958 (params->seq &&
2959 nla_put(cookie->msg, NL80211_KEY_SEQ,
2960 params->seq_len, params->seq)) ||
2961 (params->cipher &&
2962 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2963 params->cipher)))
2964 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002965
David S. Miller9360ffd2012-03-29 04:41:26 -04002966 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2967 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002968
2969 nla_nest_end(cookie->msg, key);
2970
Johannes Berg41ade002007-12-19 02:03:29 +01002971 return;
2972 nla_put_failure:
2973 cookie->error = 1;
2974}
2975
2976static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2977{
Johannes Berg4c476992010-10-04 21:36:35 +02002978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002979 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002980 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002981 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002982 const u8 *mac_addr = NULL;
2983 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002984 struct get_key_cookie cookie = {
2985 .error = 0,
2986 };
2987 void *hdr;
2988 struct sk_buff *msg;
2989
2990 if (info->attrs[NL80211_ATTR_KEY_IDX])
2991 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2992
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002993 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002994 return -EINVAL;
2995
2996 if (info->attrs[NL80211_ATTR_MAC])
2997 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2998
Johannes Berge31b8212010-10-05 19:39:30 +02002999 pairwise = !!mac_addr;
3000 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3001 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003002
Johannes Berge31b8212010-10-05 19:39:30 +02003003 if (kt >= NUM_NL80211_KEYTYPES)
3004 return -EINVAL;
3005 if (kt != NL80211_KEYTYPE_GROUP &&
3006 kt != NL80211_KEYTYPE_PAIRWISE)
3007 return -EINVAL;
3008 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3009 }
3010
Johannes Berg4c476992010-10-04 21:36:35 +02003011 if (!rdev->ops->get_key)
3012 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003013
Johannes Berg0fa7b392015-01-23 11:10:12 +01003014 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3015 return -ENOENT;
3016
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003017 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003018 if (!msg)
3019 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003020
Eric W. Biederman15e47302012-09-07 20:12:54 +00003021 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003022 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003023 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003024 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003025
3026 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003027 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003028
David S. Miller9360ffd2012-03-29 04:41:26 -04003029 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3030 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3031 goto nla_put_failure;
3032 if (mac_addr &&
3033 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3034 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003035
Hila Gonene35e4d22012-06-27 17:19:42 +03003036 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3037 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003038
3039 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003040 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003041
3042 if (cookie.error)
3043 goto nla_put_failure;
3044
3045 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003046 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003047
3048 nla_put_failure:
3049 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003050 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003051 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003052 return err;
3053}
3054
3055static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3056{
Johannes Berg4c476992010-10-04 21:36:35 +02003057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003058 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003059 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003060 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003061
Johannes Bergb9454e82009-07-08 13:29:08 +02003062 err = nl80211_parse_key(info, &key);
3063 if (err)
3064 return err;
3065
3066 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003067 return -EINVAL;
3068
Johannes Bergb9454e82009-07-08 13:29:08 +02003069 /* only support setting default key */
3070 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003071 return -EINVAL;
3072
Johannes Bergfffd0932009-07-08 14:22:54 +02003073 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003074
3075 if (key.def) {
3076 if (!rdev->ops->set_default_key) {
3077 err = -EOPNOTSUPP;
3078 goto out;
3079 }
3080
3081 err = nl80211_key_allowed(dev->ieee80211_ptr);
3082 if (err)
3083 goto out;
3084
Hila Gonene35e4d22012-06-27 17:19:42 +03003085 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003086 key.def_uni, key.def_multi);
3087
3088 if (err)
3089 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003090
Johannes Berg3d23e342009-09-29 23:27:28 +02003091#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003092 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003093#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003094 } else {
3095 if (key.def_uni || !key.def_multi) {
3096 err = -EINVAL;
3097 goto out;
3098 }
3099
3100 if (!rdev->ops->set_default_mgmt_key) {
3101 err = -EOPNOTSUPP;
3102 goto out;
3103 }
3104
3105 err = nl80211_key_allowed(dev->ieee80211_ptr);
3106 if (err)
3107 goto out;
3108
Hila Gonene35e4d22012-06-27 17:19:42 +03003109 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003110 if (err)
3111 goto out;
3112
3113#ifdef CONFIG_CFG80211_WEXT
3114 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3115#endif
3116 }
3117
3118 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003119 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003120
Johannes Berg41ade002007-12-19 02:03:29 +01003121 return err;
3122}
3123
3124static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3125{
Johannes Berg4c476992010-10-04 21:36:35 +02003126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003127 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003128 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003129 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003130 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003131
Johannes Bergb9454e82009-07-08 13:29:08 +02003132 err = nl80211_parse_key(info, &key);
3133 if (err)
3134 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003135
Johannes Bergb9454e82009-07-08 13:29:08 +02003136 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003137 return -EINVAL;
3138
Johannes Berg41ade002007-12-19 02:03:29 +01003139 if (info->attrs[NL80211_ATTR_MAC])
3140 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3141
Johannes Berge31b8212010-10-05 19:39:30 +02003142 if (key.type == -1) {
3143 if (mac_addr)
3144 key.type = NL80211_KEYTYPE_PAIRWISE;
3145 else
3146 key.type = NL80211_KEYTYPE_GROUP;
3147 }
3148
3149 /* for now */
3150 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3151 key.type != NL80211_KEYTYPE_GROUP)
3152 return -EINVAL;
3153
Johannes Berg4c476992010-10-04 21:36:35 +02003154 if (!rdev->ops->add_key)
3155 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003156
Johannes Berge31b8212010-10-05 19:39:30 +02003157 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3158 key.type == NL80211_KEYTYPE_PAIRWISE,
3159 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003160 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003161
3162 wdev_lock(dev->ieee80211_ptr);
3163 err = nl80211_key_allowed(dev->ieee80211_ptr);
3164 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003165 err = rdev_add_key(rdev, dev, key.idx,
3166 key.type == NL80211_KEYTYPE_PAIRWISE,
3167 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003168 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003169
Johannes Berg41ade002007-12-19 02:03:29 +01003170 return err;
3171}
3172
3173static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3174{
Johannes Berg4c476992010-10-04 21:36:35 +02003175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003176 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003177 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003178 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003179 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003180
Johannes Bergb9454e82009-07-08 13:29:08 +02003181 err = nl80211_parse_key(info, &key);
3182 if (err)
3183 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003184
3185 if (info->attrs[NL80211_ATTR_MAC])
3186 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3187
Johannes Berge31b8212010-10-05 19:39:30 +02003188 if (key.type == -1) {
3189 if (mac_addr)
3190 key.type = NL80211_KEYTYPE_PAIRWISE;
3191 else
3192 key.type = NL80211_KEYTYPE_GROUP;
3193 }
3194
3195 /* for now */
3196 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3197 key.type != NL80211_KEYTYPE_GROUP)
3198 return -EINVAL;
3199
Johannes Berg4c476992010-10-04 21:36:35 +02003200 if (!rdev->ops->del_key)
3201 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003202
Johannes Bergfffd0932009-07-08 14:22:54 +02003203 wdev_lock(dev->ieee80211_ptr);
3204 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003205
Johannes Berg0fa7b392015-01-23 11:10:12 +01003206 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003207 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3208 err = -ENOENT;
3209
Johannes Bergfffd0932009-07-08 14:22:54 +02003210 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003211 err = rdev_del_key(rdev, dev, key.idx,
3212 key.type == NL80211_KEYTYPE_PAIRWISE,
3213 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003214
Johannes Berg3d23e342009-09-29 23:27:28 +02003215#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003216 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003217 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003218 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003219 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003220 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3221 }
3222#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003223 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003224
Johannes Berg41ade002007-12-19 02:03:29 +01003225 return err;
3226}
3227
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303228/* This function returns an error or the number of nested attributes */
3229static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3230{
3231 struct nlattr *attr;
3232 int n_entries = 0, tmp;
3233
3234 nla_for_each_nested(attr, nl_attr, tmp) {
3235 if (nla_len(attr) != ETH_ALEN)
3236 return -EINVAL;
3237
3238 n_entries++;
3239 }
3240
3241 return n_entries;
3242}
3243
3244/*
3245 * This function parses ACL information and allocates memory for ACL data.
3246 * On successful return, the calling function is responsible to free the
3247 * ACL buffer returned by this function.
3248 */
3249static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3250 struct genl_info *info)
3251{
3252 enum nl80211_acl_policy acl_policy;
3253 struct nlattr *attr;
3254 struct cfg80211_acl_data *acl;
3255 int i = 0, n_entries, tmp;
3256
3257 if (!wiphy->max_acl_mac_addrs)
3258 return ERR_PTR(-EOPNOTSUPP);
3259
3260 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3261 return ERR_PTR(-EINVAL);
3262
3263 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3264 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3265 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3266 return ERR_PTR(-EINVAL);
3267
3268 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3269 return ERR_PTR(-EINVAL);
3270
3271 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3272 if (n_entries < 0)
3273 return ERR_PTR(n_entries);
3274
3275 if (n_entries > wiphy->max_acl_mac_addrs)
3276 return ERR_PTR(-ENOTSUPP);
3277
3278 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3279 GFP_KERNEL);
3280 if (!acl)
3281 return ERR_PTR(-ENOMEM);
3282
3283 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3284 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3285 i++;
3286 }
3287
3288 acl->n_acl_entries = n_entries;
3289 acl->acl_policy = acl_policy;
3290
3291 return acl;
3292}
3293
3294static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3295{
3296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3297 struct net_device *dev = info->user_ptr[1];
3298 struct cfg80211_acl_data *acl;
3299 int err;
3300
3301 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3302 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3303 return -EOPNOTSUPP;
3304
3305 if (!dev->ieee80211_ptr->beacon_interval)
3306 return -EINVAL;
3307
3308 acl = parse_acl_data(&rdev->wiphy, info);
3309 if (IS_ERR(acl))
3310 return PTR_ERR(acl);
3311
3312 err = rdev_set_mac_acl(rdev, dev, acl);
3313
3314 kfree(acl);
3315
3316 return err;
3317}
3318
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003319static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003320 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003321{
Johannes Berg88600202012-02-13 15:17:18 +01003322 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003323
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003324 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3325 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3326 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3327 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003328 return -EINVAL;
3329
Johannes Berg88600202012-02-13 15:17:18 +01003330 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003331
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003332 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3333 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3334 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003335 if (!bcn->head_len)
3336 return -EINVAL;
3337 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003338 }
3339
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003340 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3341 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3342 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003343 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003344 }
3345
Johannes Berg4c476992010-10-04 21:36:35 +02003346 if (!haveinfo)
3347 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003348
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003349 if (attrs[NL80211_ATTR_IE]) {
3350 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3351 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003352 }
3353
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003354 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003355 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003356 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003357 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003358 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003359 }
3360
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003361 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003362 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003363 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003364 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003365 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003366 }
3367
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003368 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3369 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3370 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003371 }
3372
Johannes Berg88600202012-02-13 15:17:18 +01003373 return 0;
3374}
3375
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003376static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3377 struct cfg80211_ap_settings *params)
3378{
3379 struct wireless_dev *wdev;
3380 bool ret = false;
3381
Johannes Berg53873f12016-05-03 16:52:04 +03003382 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003383 if (wdev->iftype != NL80211_IFTYPE_AP &&
3384 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3385 continue;
3386
Johannes Berg683b6d32012-11-08 21:25:48 +01003387 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003388 continue;
3389
Johannes Berg683b6d32012-11-08 21:25:48 +01003390 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003391 ret = true;
3392 break;
3393 }
3394
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003395 return ret;
3396}
3397
Jouni Malinene39e5b52012-09-30 19:29:39 +03003398static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3399 enum nl80211_auth_type auth_type,
3400 enum nl80211_commands cmd)
3401{
3402 if (auth_type > NL80211_AUTHTYPE_MAX)
3403 return false;
3404
3405 switch (cmd) {
3406 case NL80211_CMD_AUTHENTICATE:
3407 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3408 auth_type == NL80211_AUTHTYPE_SAE)
3409 return false;
3410 return true;
3411 case NL80211_CMD_CONNECT:
3412 case NL80211_CMD_START_AP:
3413 /* SAE not supported yet */
3414 if (auth_type == NL80211_AUTHTYPE_SAE)
3415 return false;
3416 return true;
3417 default:
3418 return false;
3419 }
3420}
3421
Johannes Berg88600202012-02-13 15:17:18 +01003422static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3423{
3424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3425 struct net_device *dev = info->user_ptr[1];
3426 struct wireless_dev *wdev = dev->ieee80211_ptr;
3427 struct cfg80211_ap_settings params;
3428 int err;
3429
3430 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3431 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3432 return -EOPNOTSUPP;
3433
3434 if (!rdev->ops->start_ap)
3435 return -EOPNOTSUPP;
3436
3437 if (wdev->beacon_interval)
3438 return -EALREADY;
3439
3440 memset(&params, 0, sizeof(params));
3441
3442 /* these are required for START_AP */
3443 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3444 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3445 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3446 return -EINVAL;
3447
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003448 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003449 if (err)
3450 return err;
3451
3452 params.beacon_interval =
3453 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3454 params.dtim_period =
3455 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3456
3457 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3458 if (err)
3459 return err;
3460
3461 /*
3462 * In theory, some of these attributes should be required here
3463 * but since they were not used when the command was originally
3464 * added, keep them optional for old user space programs to let
3465 * them continue to work with drivers that do not need the
3466 * additional information -- drivers must check!
3467 */
3468 if (info->attrs[NL80211_ATTR_SSID]) {
3469 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3470 params.ssid_len =
3471 nla_len(info->attrs[NL80211_ATTR_SSID]);
3472 if (params.ssid_len == 0 ||
3473 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3474 return -EINVAL;
3475 }
3476
3477 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3478 params.hidden_ssid = nla_get_u32(
3479 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3480 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3481 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3482 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3483 return -EINVAL;
3484 }
3485
3486 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3487
3488 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3489 params.auth_type = nla_get_u32(
3490 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003491 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3492 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003493 return -EINVAL;
3494 } else
3495 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3496
3497 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3498 NL80211_MAX_NR_CIPHER_SUITES);
3499 if (err)
3500 return err;
3501
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303502 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3503 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3504 return -EOPNOTSUPP;
3505 params.inactivity_timeout = nla_get_u16(
3506 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3507 }
3508
Johannes Berg53cabad2012-11-14 15:17:28 +01003509 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3510 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3511 return -EINVAL;
3512 params.p2p_ctwindow =
3513 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3514 if (params.p2p_ctwindow > 127)
3515 return -EINVAL;
3516 if (params.p2p_ctwindow != 0 &&
3517 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3518 return -EINVAL;
3519 }
3520
3521 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3522 u8 tmp;
3523
3524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3525 return -EINVAL;
3526 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3527 if (tmp > 1)
3528 return -EINVAL;
3529 params.p2p_opp_ps = tmp;
3530 if (params.p2p_opp_ps != 0 &&
3531 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3532 return -EINVAL;
3533 }
3534
Johannes Bergaa430da2012-05-16 23:50:18 +02003535 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003536 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3537 if (err)
3538 return err;
3539 } else if (wdev->preset_chandef.chan) {
3540 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003541 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003542 return -EINVAL;
3543
Arik Nemtsov923b3522015-07-08 15:41:44 +03003544 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3545 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003546 return -EINVAL;
3547
Eliad Peller18998c32014-09-10 14:07:34 +03003548 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3549 params.smps_mode =
3550 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3551 switch (params.smps_mode) {
3552 case NL80211_SMPS_OFF:
3553 break;
3554 case NL80211_SMPS_STATIC:
3555 if (!(rdev->wiphy.features &
3556 NL80211_FEATURE_STATIC_SMPS))
3557 return -EINVAL;
3558 break;
3559 case NL80211_SMPS_DYNAMIC:
3560 if (!(rdev->wiphy.features &
3561 NL80211_FEATURE_DYNAMIC_SMPS))
3562 return -EINVAL;
3563 break;
3564 default:
3565 return -EINVAL;
3566 }
3567 } else {
3568 params.smps_mode = NL80211_SMPS_OFF;
3569 }
3570
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303571 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3572 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3573 return -EOPNOTSUPP;
3574
Ola Olsson4baf6be2015-10-29 07:04:58 +01003575 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3576 params.acl = parse_acl_data(&rdev->wiphy, info);
3577 if (IS_ERR(params.acl))
3578 return PTR_ERR(params.acl);
3579 }
3580
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003581 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003582 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003583 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003584 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003585 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003586 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003587 wdev->ssid_len = params.ssid_len;
3588 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003589 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003590 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303591
3592 kfree(params.acl);
3593
Johannes Berg56d18932011-05-09 18:41:15 +02003594 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003595}
3596
Johannes Berg88600202012-02-13 15:17:18 +01003597static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3598{
3599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3600 struct net_device *dev = info->user_ptr[1];
3601 struct wireless_dev *wdev = dev->ieee80211_ptr;
3602 struct cfg80211_beacon_data params;
3603 int err;
3604
3605 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3606 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3607 return -EOPNOTSUPP;
3608
3609 if (!rdev->ops->change_beacon)
3610 return -EOPNOTSUPP;
3611
3612 if (!wdev->beacon_interval)
3613 return -EINVAL;
3614
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003615 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003616 if (err)
3617 return err;
3618
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003619 wdev_lock(wdev);
3620 err = rdev_change_beacon(rdev, dev, &params);
3621 wdev_unlock(wdev);
3622
3623 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003624}
3625
3626static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003627{
Johannes Berg4c476992010-10-04 21:36:35 +02003628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3629 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003630
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003631 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003632}
3633
Johannes Berg5727ef12007-12-19 02:03:34 +01003634static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3635 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3636 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3637 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003638 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003639 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003640 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003641};
3642
Johannes Bergeccb8e82009-05-11 21:57:56 +03003643static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003644 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003645 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003646{
3647 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003648 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003649 int flag;
3650
Johannes Bergeccb8e82009-05-11 21:57:56 +03003651 /*
3652 * Try parsing the new attribute first so userspace
3653 * can specify both for older kernels.
3654 */
3655 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3656 if (nla) {
3657 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003658
Johannes Bergeccb8e82009-05-11 21:57:56 +03003659 sta_flags = nla_data(nla);
3660 params->sta_flags_mask = sta_flags->mask;
3661 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003662 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003663 if ((params->sta_flags_mask |
3664 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3665 return -EINVAL;
3666 return 0;
3667 }
3668
3669 /* if present, parse the old attribute */
3670
3671 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003672 if (!nla)
3673 return 0;
3674
3675 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3676 nla, sta_flags_policy))
3677 return -EINVAL;
3678
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003679 /*
3680 * Only allow certain flags for interface types so that
3681 * other attributes are silently ignored. Remember that
3682 * this is backward compatibility code with old userspace
3683 * and shouldn't be hit in other cases anyway.
3684 */
3685 switch (iftype) {
3686 case NL80211_IFTYPE_AP:
3687 case NL80211_IFTYPE_AP_VLAN:
3688 case NL80211_IFTYPE_P2P_GO:
3689 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3691 BIT(NL80211_STA_FLAG_WME) |
3692 BIT(NL80211_STA_FLAG_MFP);
3693 break;
3694 case NL80211_IFTYPE_P2P_CLIENT:
3695 case NL80211_IFTYPE_STATION:
3696 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3697 BIT(NL80211_STA_FLAG_TDLS_PEER);
3698 break;
3699 case NL80211_IFTYPE_MESH_POINT:
3700 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_MFP) |
3702 BIT(NL80211_STA_FLAG_AUTHORIZED);
3703 default:
3704 return -EINVAL;
3705 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003706
Johannes Berg3383b5a2012-05-10 20:14:43 +02003707 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3708 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003709 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003710
Johannes Berg3383b5a2012-05-10 20:14:43 +02003711 /* no longer support new API additions in old API */
3712 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3713 return -EINVAL;
3714 }
3715 }
3716
Johannes Berg5727ef12007-12-19 02:03:34 +01003717 return 0;
3718}
3719
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003720static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3721 int attr)
3722{
3723 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003724 u32 bitrate;
3725 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003726 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003727
3728 rate = nla_nest_start(msg, attr);
3729 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003730 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003731
3732 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3733 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003734 /* report 16-bit bitrate only if we can */
3735 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003736 if (bitrate > 0 &&
3737 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3738 return false;
3739 if (bitrate_compat > 0 &&
3740 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3741 return false;
3742
Johannes Bergb51f3be2015-01-15 16:14:02 +01003743 switch (info->bw) {
3744 case RATE_INFO_BW_5:
3745 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3746 break;
3747 case RATE_INFO_BW_10:
3748 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3749 break;
3750 default:
3751 WARN_ON(1);
3752 /* fall through */
3753 case RATE_INFO_BW_20:
3754 rate_flg = 0;
3755 break;
3756 case RATE_INFO_BW_40:
3757 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3758 break;
3759 case RATE_INFO_BW_80:
3760 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3761 break;
3762 case RATE_INFO_BW_160:
3763 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3764 break;
3765 }
3766
3767 if (rate_flg && nla_put_flag(msg, rate_flg))
3768 return false;
3769
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003770 if (info->flags & RATE_INFO_FLAGS_MCS) {
3771 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3772 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003773 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3774 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3775 return false;
3776 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3777 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3778 return false;
3779 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3780 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003781 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3782 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3783 return false;
3784 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003785
3786 nla_nest_end(msg, rate);
3787 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003788}
3789
Felix Fietkau119363c2013-04-22 16:29:30 +02003790static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3791 int id)
3792{
3793 void *attr;
3794 int i = 0;
3795
3796 if (!mask)
3797 return true;
3798
3799 attr = nla_nest_start(msg, id);
3800 if (!attr)
3801 return false;
3802
3803 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3804 if (!(mask & BIT(i)))
3805 continue;
3806
3807 if (nla_put_u8(msg, i, signal[i]))
3808 return false;
3809 }
3810
3811 nla_nest_end(msg, attr);
3812
3813 return true;
3814}
3815
Johannes Bergcf5ead82014-11-14 17:14:00 +01003816static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3817 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003818 struct cfg80211_registered_device *rdev,
3819 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003820 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003821{
3822 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003823 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003824
Johannes Bergcf5ead82014-11-14 17:14:00 +01003825 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003826 if (!hdr)
3827 return -1;
3828
David S. Miller9360ffd2012-03-29 04:41:26 -04003829 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3830 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3831 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3832 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003833
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003834 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3835 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003836 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003837
3838#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003839 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303840 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003841 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3842 sinfo->memb)) \
3843 goto nla_put_failure; \
3844 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003845#define PUT_SINFO_U64(attr, memb) do { \
3846 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3847 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3848 sinfo->memb, NL80211_STA_INFO_PAD)) \
3849 goto nla_put_failure; \
3850 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003851
3852 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3853 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3854
3855 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3856 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003857 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003858 (u32)sinfo->rx_bytes))
3859 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003860
3861 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3862 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003863 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3864 (u32)sinfo->tx_bytes))
3865 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003866
Johannes Bergd686b922016-04-26 09:54:11 +02003867 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3868 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003869 PUT_SINFO(LLID, llid, u16);
3870 PUT_SINFO(PLID, plid, u16);
3871 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003872 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003873
John W. Linville66266b32012-03-15 13:25:41 -04003874 switch (rdev->wiphy.signal_type) {
3875 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003876 PUT_SINFO(SIGNAL, signal, u8);
3877 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003878 break;
3879 default:
3880 break;
3881 }
Johannes Berg319090b2014-11-17 14:08:11 +01003882 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003883 if (!nl80211_put_signal(msg, sinfo->chains,
3884 sinfo->chain_signal,
3885 NL80211_STA_INFO_CHAIN_SIGNAL))
3886 goto nla_put_failure;
3887 }
Johannes Berg319090b2014-11-17 14:08:11 +01003888 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003889 if (!nl80211_put_signal(msg, sinfo->chains,
3890 sinfo->chain_signal_avg,
3891 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3892 goto nla_put_failure;
3893 }
Johannes Berg319090b2014-11-17 14:08:11 +01003894 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003895 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3896 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003897 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003898 }
Johannes Berg319090b2014-11-17 14:08:11 +01003899 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003900 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3901 NL80211_STA_INFO_RX_BITRATE))
3902 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003903 }
Johannes Berg319090b2014-11-17 14:08:11 +01003904
3905 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3906 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3907 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3908 PUT_SINFO(TX_FAILED, tx_failed, u32);
3909 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3910 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3911 PUT_SINFO(LOCAL_PM, local_pm, u32);
3912 PUT_SINFO(PEER_PM, peer_pm, u32);
3913 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3914
3915 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003916 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3917 if (!bss_param)
3918 goto nla_put_failure;
3919
David S. Miller9360ffd2012-03-29 04:41:26 -04003920 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3921 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3922 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3923 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3924 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3925 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3926 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3927 sinfo->bss_param.dtim_period) ||
3928 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3929 sinfo->bss_param.beacon_interval))
3930 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003931
3932 nla_nest_end(msg, bss_param);
3933 }
Johannes Berg319090b2014-11-17 14:08:11 +01003934 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003935 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3936 sizeof(struct nl80211_sta_flag_update),
3937 &sinfo->sta_flags))
3938 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003939
Johannes Bergd686b922016-04-26 09:54:11 +02003940 PUT_SINFO_U64(T_OFFSET, t_offset);
3941 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3942 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003943 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003944
3945#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003946#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003947
3948 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3949 struct nlattr *tidsattr;
3950 int tid;
3951
3952 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3953 if (!tidsattr)
3954 goto nla_put_failure;
3955
3956 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3957 struct cfg80211_tid_stats *tidstats;
3958 struct nlattr *tidattr;
3959
3960 tidstats = &sinfo->pertid[tid];
3961
3962 if (!tidstats->filled)
3963 continue;
3964
3965 tidattr = nla_nest_start(msg, tid + 1);
3966 if (!tidattr)
3967 goto nla_put_failure;
3968
Johannes Bergd686b922016-04-26 09:54:11 +02003969#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003970 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003971 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3972 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003973 goto nla_put_failure; \
3974 } while (0)
3975
Johannes Bergd686b922016-04-26 09:54:11 +02003976 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
3977 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
3978 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
3979 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01003980
Johannes Bergd686b922016-04-26 09:54:11 +02003981#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003982 nla_nest_end(msg, tidattr);
3983 }
3984
3985 nla_nest_end(msg, tidsattr);
3986 }
3987
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003988 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003989
Johannes Berg319090b2014-11-17 14:08:11 +01003990 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003991 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3992 sinfo->assoc_req_ies))
3993 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003994
Johannes Berg053c0952015-01-16 22:09:00 +01003995 genlmsg_end(msg, hdr);
3996 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003997
3998 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003999 genlmsg_cancel(msg, hdr);
4000 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004001}
4002
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004003static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004004 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004005{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004006 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004007 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004008 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004009 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004010 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004011 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004012
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004013 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004014 if (err)
4015 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004016
Johannes Berg97990a02013-04-19 01:02:55 +02004017 if (!wdev->netdev) {
4018 err = -EINVAL;
4019 goto out_err;
4020 }
4021
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004022 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004023 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004024 goto out_err;
4025 }
4026
Johannes Bergbba95fe2008-07-29 13:22:51 +02004027 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004028 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004029 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004030 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004031 if (err == -ENOENT)
4032 break;
4033 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004034 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004035
Johannes Bergcf5ead82014-11-14 17:14:00 +01004036 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004037 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004038 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004039 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004040 &sinfo) < 0)
4041 goto out;
4042
4043 sta_idx++;
4044 }
4045
Johannes Bergbba95fe2008-07-29 13:22:51 +02004046 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004047 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004048 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004049 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004050 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004051
4052 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004053}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004054
Johannes Berg5727ef12007-12-19 02:03:34 +01004055static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4056{
Johannes Berg4c476992010-10-04 21:36:35 +02004057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4058 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004059 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004060 struct sk_buff *msg;
4061 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004062 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004063
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004064 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004065
4066 if (!info->attrs[NL80211_ATTR_MAC])
4067 return -EINVAL;
4068
4069 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4070
Johannes Berg4c476992010-10-04 21:36:35 +02004071 if (!rdev->ops->get_station)
4072 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004073
Hila Gonene35e4d22012-06-27 17:19:42 +03004074 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004075 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004076 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004077
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004078 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004079 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004080 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004081
Johannes Bergcf5ead82014-11-14 17:14:00 +01004082 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4083 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004084 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004085 nlmsg_free(msg);
4086 return -ENOBUFS;
4087 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004088
Johannes Berg4c476992010-10-04 21:36:35 +02004089 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004090}
4091
Johannes Berg77ee7c82013-02-15 00:48:33 +01004092int cfg80211_check_station_change(struct wiphy *wiphy,
4093 struct station_parameters *params,
4094 enum cfg80211_station_type statype)
4095{
Ayala Bekere4208422015-10-23 11:20:06 +03004096 if (params->listen_interval != -1 &&
4097 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004098 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004099
Ayala Beker17b94242016-03-17 15:41:38 +02004100 if (params->support_p2p_ps != -1 &&
4101 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4102 return -EINVAL;
4103
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004104 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004105 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4106 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004107 return -EINVAL;
4108
4109 /* When you run into this, adjust the code below for the new flag */
4110 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4111
4112 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004113 case CFG80211_STA_MESH_PEER_KERNEL:
4114 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004115 /*
4116 * No ignoring the TDLS flag here -- the userspace mesh
4117 * code doesn't have the bug of including TDLS in the
4118 * mask everywhere.
4119 */
4120 if (params->sta_flags_mask &
4121 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4122 BIT(NL80211_STA_FLAG_MFP) |
4123 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4124 return -EINVAL;
4125 break;
4126 case CFG80211_STA_TDLS_PEER_SETUP:
4127 case CFG80211_STA_TDLS_PEER_ACTIVE:
4128 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4129 return -EINVAL;
4130 /* ignore since it can't change */
4131 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4132 break;
4133 default:
4134 /* disallow mesh-specific things */
4135 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4136 return -EINVAL;
4137 if (params->local_pm)
4138 return -EINVAL;
4139 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4140 return -EINVAL;
4141 }
4142
4143 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4144 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4145 /* TDLS can't be set, ... */
4146 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4147 return -EINVAL;
4148 /*
4149 * ... but don't bother the driver with it. This works around
4150 * a hostapd/wpa_supplicant issue -- it always includes the
4151 * TLDS_PEER flag in the mask even for AP mode.
4152 */
4153 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4154 }
4155
Ayala Beker47edb112015-09-21 15:49:53 +03004156 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4157 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004158 /* reject other things that can't change */
4159 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4160 return -EINVAL;
4161 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4162 return -EINVAL;
4163 if (params->supported_rates)
4164 return -EINVAL;
4165 if (params->ext_capab || params->ht_capa || params->vht_capa)
4166 return -EINVAL;
4167 }
4168
Ayala Beker47edb112015-09-21 15:49:53 +03004169 if (statype != CFG80211_STA_AP_CLIENT &&
4170 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004171 if (params->vlan)
4172 return -EINVAL;
4173 }
4174
4175 switch (statype) {
4176 case CFG80211_STA_AP_MLME_CLIENT:
4177 /* Use this only for authorizing/unauthorizing a station */
4178 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4179 return -EOPNOTSUPP;
4180 break;
4181 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004182 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004183 /* accept only the listed bits */
4184 if (params->sta_flags_mask &
4185 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4186 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4187 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4188 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4189 BIT(NL80211_STA_FLAG_WME) |
4190 BIT(NL80211_STA_FLAG_MFP)))
4191 return -EINVAL;
4192
4193 /* but authenticated/associated only if driver handles it */
4194 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4195 params->sta_flags_mask &
4196 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4197 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4198 return -EINVAL;
4199 break;
4200 case CFG80211_STA_IBSS:
4201 case CFG80211_STA_AP_STA:
4202 /* reject any changes other than AUTHORIZED */
4203 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4204 return -EINVAL;
4205 break;
4206 case CFG80211_STA_TDLS_PEER_SETUP:
4207 /* reject any changes other than AUTHORIZED or WME */
4208 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4209 BIT(NL80211_STA_FLAG_WME)))
4210 return -EINVAL;
4211 /* force (at least) rates when authorizing */
4212 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4213 !params->supported_rates)
4214 return -EINVAL;
4215 break;
4216 case CFG80211_STA_TDLS_PEER_ACTIVE:
4217 /* reject any changes */
4218 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004219 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004220 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4221 return -EINVAL;
4222 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004223 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004224 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4225 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004226 return -EINVAL;
4227 break;
4228 }
4229
4230 return 0;
4231}
4232EXPORT_SYMBOL(cfg80211_check_station_change);
4233
Johannes Berg5727ef12007-12-19 02:03:34 +01004234/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004235 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004236 */
Johannes Berg80b99892011-11-18 16:23:01 +01004237static struct net_device *get_vlan(struct genl_info *info,
4238 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004239{
Johannes Berg463d0182009-07-14 00:33:35 +02004240 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004241 struct net_device *v;
4242 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004243
Johannes Berg80b99892011-11-18 16:23:01 +01004244 if (!vlanattr)
4245 return NULL;
4246
4247 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4248 if (!v)
4249 return ERR_PTR(-ENODEV);
4250
4251 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4252 ret = -EINVAL;
4253 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004254 }
Johannes Berg80b99892011-11-18 16:23:01 +01004255
Johannes Berg77ee7c82013-02-15 00:48:33 +01004256 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4257 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4258 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4259 ret = -EINVAL;
4260 goto error;
4261 }
4262
Johannes Berg80b99892011-11-18 16:23:01 +01004263 if (!netif_running(v)) {
4264 ret = -ENETDOWN;
4265 goto error;
4266 }
4267
4268 return v;
4269 error:
4270 dev_put(v);
4271 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004272}
4273
Johannes Berg94e860f2014-01-20 23:58:15 +01004274static const struct nla_policy
4275nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004276 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4277 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4278};
4279
Johannes Bergff276692013-02-15 00:09:01 +01004280static int nl80211_parse_sta_wme(struct genl_info *info,
4281 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004282{
Jouni Malinendf881292013-02-14 21:10:54 +02004283 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4284 struct nlattr *nla;
4285 int err;
4286
Jouni Malinendf881292013-02-14 21:10:54 +02004287 /* parse WME attributes if present */
4288 if (!info->attrs[NL80211_ATTR_STA_WME])
4289 return 0;
4290
4291 nla = info->attrs[NL80211_ATTR_STA_WME];
4292 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4293 nl80211_sta_wme_policy);
4294 if (err)
4295 return err;
4296
4297 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4298 params->uapsd_queues = nla_get_u8(
4299 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4300 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4301 return -EINVAL;
4302
4303 if (tb[NL80211_STA_WME_MAX_SP])
4304 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4305
4306 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4307 return -EINVAL;
4308
4309 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4310
4311 return 0;
4312}
4313
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304314static int nl80211_parse_sta_channel_info(struct genl_info *info,
4315 struct station_parameters *params)
4316{
4317 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4318 params->supported_channels =
4319 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4320 params->supported_channels_len =
4321 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4322 /*
4323 * Need to include at least one (first channel, number of
4324 * channels) tuple for each subband, and must have proper
4325 * tuples for the rest of the data as well.
4326 */
4327 if (params->supported_channels_len < 2)
4328 return -EINVAL;
4329 if (params->supported_channels_len % 2)
4330 return -EINVAL;
4331 }
4332
4333 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4334 params->supported_oper_classes =
4335 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4336 params->supported_oper_classes_len =
4337 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4338 /*
4339 * The value of the Length field of the Supported Operating
4340 * Classes element is between 2 and 253.
4341 */
4342 if (params->supported_oper_classes_len < 2 ||
4343 params->supported_oper_classes_len > 253)
4344 return -EINVAL;
4345 }
4346 return 0;
4347}
4348
Johannes Bergff276692013-02-15 00:09:01 +01004349static int nl80211_set_station_tdls(struct genl_info *info,
4350 struct station_parameters *params)
4351{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304352 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004353 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004354 if (info->attrs[NL80211_ATTR_PEER_AID])
4355 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004356 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4357 params->ht_capa =
4358 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4359 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4360 params->vht_capa =
4361 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4362
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304363 err = nl80211_parse_sta_channel_info(info, params);
4364 if (err)
4365 return err;
4366
Johannes Bergff276692013-02-15 00:09:01 +01004367 return nl80211_parse_sta_wme(info, params);
4368}
4369
Johannes Berg5727ef12007-12-19 02:03:34 +01004370static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4371{
Johannes Berg4c476992010-10-04 21:36:35 +02004372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004373 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004374 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004375 u8 *mac_addr;
4376 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004377
4378 memset(&params, 0, sizeof(params));
4379
Johannes Berg77ee7c82013-02-15 00:48:33 +01004380 if (!rdev->ops->change_station)
4381 return -EOPNOTSUPP;
4382
Ayala Bekere4208422015-10-23 11:20:06 +03004383 /*
4384 * AID and listen_interval properties can be set only for unassociated
4385 * station. Include these parameters here and will check them in
4386 * cfg80211_check_station_change().
4387 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004388 if (info->attrs[NL80211_ATTR_STA_AID])
4389 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004390
4391 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4392 params.listen_interval =
4393 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4394 else
4395 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004396
Ayala Beker17b94242016-03-17 15:41:38 +02004397 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4398 u8 tmp;
4399
4400 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4401 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4402 return -EINVAL;
4403
4404 params.support_p2p_ps = tmp;
4405 } else {
4406 params.support_p2p_ps = -1;
4407 }
4408
Johannes Berg5727ef12007-12-19 02:03:34 +01004409 if (!info->attrs[NL80211_ATTR_MAC])
4410 return -EINVAL;
4411
4412 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4413
4414 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4415 params.supported_rates =
4416 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4417 params.supported_rates_len =
4418 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4419 }
4420
Jouni Malinen9d62a982013-02-14 21:10:13 +02004421 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4422 params.capability =
4423 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4424 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4425 }
4426
4427 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4428 params.ext_capab =
4429 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4430 params.ext_capab_len =
4431 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4432 }
4433
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004434 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004435 return -EINVAL;
4436
Johannes Bergf8bacc22013-02-14 23:27:01 +01004437 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004438 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004439 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4440 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4441 return -EINVAL;
4442 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004443
Johannes Bergf8bacc22013-02-14 23:27:01 +01004444 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004445 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004446 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4447 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4448 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004449 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4450 params.peer_aid = nla_get_u16(
4451 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4452 if (params.peer_aid > IEEE80211_MAX_AID)
4453 return -EINVAL;
4454 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004455 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4456 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004457
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004458 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4459 enum nl80211_mesh_power_mode pm = nla_get_u32(
4460 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4461
4462 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4463 pm > NL80211_MESH_POWER_MAX)
4464 return -EINVAL;
4465
4466 params.local_pm = pm;
4467 }
4468
Johannes Berg77ee7c82013-02-15 00:48:33 +01004469 /* Include parameters for TDLS peer (will check later) */
4470 err = nl80211_set_station_tdls(info, &params);
4471 if (err)
4472 return err;
4473
4474 params.vlan = get_vlan(info, rdev);
4475 if (IS_ERR(params.vlan))
4476 return PTR_ERR(params.vlan);
4477
Johannes Berga97f4422009-06-18 17:23:43 +02004478 switch (dev->ieee80211_ptr->iftype) {
4479 case NL80211_IFTYPE_AP:
4480 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004481 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004482 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004483 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004484 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004485 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004486 break;
4487 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004488 err = -EOPNOTSUPP;
4489 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004490 }
4491
Johannes Berg77ee7c82013-02-15 00:48:33 +01004492 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004493 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004494
Johannes Berg77ee7c82013-02-15 00:48:33 +01004495 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004496 if (params.vlan)
4497 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004498
Johannes Berg5727ef12007-12-19 02:03:34 +01004499 return err;
4500}
4501
4502static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4503{
Johannes Berg4c476992010-10-04 21:36:35 +02004504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004505 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004506 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004507 struct station_parameters params;
4508 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004509 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4510 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004511
4512 memset(&params, 0, sizeof(params));
4513
Johannes Berg984c3112013-02-14 23:43:25 +01004514 if (!rdev->ops->add_station)
4515 return -EOPNOTSUPP;
4516
Johannes Berg5727ef12007-12-19 02:03:34 +01004517 if (!info->attrs[NL80211_ATTR_MAC])
4518 return -EINVAL;
4519
Johannes Berg5727ef12007-12-19 02:03:34 +01004520 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4521 return -EINVAL;
4522
4523 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4524 return -EINVAL;
4525
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004526 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4527 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004528 return -EINVAL;
4529
Johannes Berg5727ef12007-12-19 02:03:34 +01004530 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4531 params.supported_rates =
4532 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4533 params.supported_rates_len =
4534 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4535 params.listen_interval =
4536 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004537
Ayala Beker17b94242016-03-17 15:41:38 +02004538 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4539 u8 tmp;
4540
4541 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4542 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4543 return -EINVAL;
4544
4545 params.support_p2p_ps = tmp;
4546 } else {
4547 /*
4548 * if not specified, assume it's supported for P2P GO interface,
4549 * and is NOT supported for AP interface
4550 */
4551 params.support_p2p_ps =
4552 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4553 }
4554
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004555 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004556 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004557 else
4558 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004559 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4560 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004561
Jouni Malinen9d62a982013-02-14 21:10:13 +02004562 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4563 params.capability =
4564 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4565 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4566 }
4567
4568 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4569 params.ext_capab =
4570 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4571 params.ext_capab_len =
4572 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4573 }
4574
Jouni Malinen36aedc902008-08-25 11:58:58 +03004575 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4576 params.ht_capa =
4577 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004578
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004579 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4580 params.vht_capa =
4581 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4582
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004583 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4584 params.opmode_notif_used = true;
4585 params.opmode_notif =
4586 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4587 }
4588
Johannes Bergf8bacc22013-02-14 23:27:01 +01004589 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004590 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004591 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4592 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4593 return -EINVAL;
4594 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004595
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304596 err = nl80211_parse_sta_channel_info(info, &params);
4597 if (err)
4598 return err;
4599
Johannes Bergff276692013-02-15 00:09:01 +01004600 err = nl80211_parse_sta_wme(info, &params);
4601 if (err)
4602 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004603
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004604 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004605 return -EINVAL;
4606
Johannes Berg496fcc22015-03-12 08:53:27 +02004607 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4608 * as userspace might just pass through the capabilities from the IEs
4609 * directly, rather than enforcing this restriction and returning an
4610 * error in this case.
4611 */
4612 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4613 params.ht_capa = NULL;
4614 params.vht_capa = NULL;
4615 }
4616
Johannes Berg77ee7c82013-02-15 00:48:33 +01004617 /* When you run into this, adjust the code below for the new flag */
4618 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4619
Johannes Bergbdd90d52011-12-14 12:20:27 +01004620 switch (dev->ieee80211_ptr->iftype) {
4621 case NL80211_IFTYPE_AP:
4622 case NL80211_IFTYPE_AP_VLAN:
4623 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004624 /* ignore WME attributes if iface/sta is not capable */
4625 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4626 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4627 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004628
Johannes Bergbdd90d52011-12-14 12:20:27 +01004629 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004630 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4631 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004632 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004633 /* but don't bother the driver with it */
4634 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004635
Johannes Bergd582cff2012-10-26 17:53:44 +02004636 /* allow authenticated/associated only if driver handles it */
4637 if (!(rdev->wiphy.features &
4638 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004639 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004640 return -EINVAL;
4641
Johannes Bergbda95eb2015-11-26 16:26:13 +01004642 /* Older userspace, or userspace wanting to be compatible with
4643 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4644 * and assoc flags in the mask, but assumes the station will be
4645 * added as associated anyway since this was the required driver
4646 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4647 * introduced.
4648 * In order to not bother drivers with this quirk in the API
4649 * set the flags in both the mask and set for new stations in
4650 * this case.
4651 */
4652 if (!(params.sta_flags_mask & auth_assoc)) {
4653 params.sta_flags_mask |= auth_assoc;
4654 params.sta_flags_set |= auth_assoc;
4655 }
4656
Johannes Bergbdd90d52011-12-14 12:20:27 +01004657 /* must be last in here for error handling */
4658 params.vlan = get_vlan(info, rdev);
4659 if (IS_ERR(params.vlan))
4660 return PTR_ERR(params.vlan);
4661 break;
4662 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004663 /* ignore uAPSD data */
4664 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4665
Johannes Bergd582cff2012-10-26 17:53:44 +02004666 /* associated is disallowed */
4667 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4668 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004669 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004670 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4671 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004672 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004673 break;
4674 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004675 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004676 /* ignore uAPSD data */
4677 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4678
Johannes Berg77ee7c82013-02-15 00:48:33 +01004679 /* these are disallowed */
4680 if (params.sta_flags_mask &
4681 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4682 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004683 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004684 /* Only TDLS peers can be added */
4685 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4686 return -EINVAL;
4687 /* Can only add if TDLS ... */
4688 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4689 return -EOPNOTSUPP;
4690 /* ... with external setup is supported */
4691 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4692 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004693 /*
4694 * Older wpa_supplicant versions always mark the TDLS peer
4695 * as authorized, but it shouldn't yet be.
4696 */
4697 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004698 break;
4699 default:
4700 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004701 }
4702
Johannes Bergbdd90d52011-12-14 12:20:27 +01004703 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004704
Hila Gonene35e4d22012-06-27 17:19:42 +03004705 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004706
Johannes Berg5727ef12007-12-19 02:03:34 +01004707 if (params.vlan)
4708 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004709 return err;
4710}
4711
4712static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4713{
Johannes Berg4c476992010-10-04 21:36:35 +02004714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4715 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004716 struct station_del_parameters params;
4717
4718 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004719
4720 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004721 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004722
Johannes Berge80cf852009-05-11 14:43:13 +02004723 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004724 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004725 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004726 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4727 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004728
Johannes Berg4c476992010-10-04 21:36:35 +02004729 if (!rdev->ops->del_station)
4730 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004731
Jouni Malinen98856862014-10-20 13:20:45 +03004732 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4733 params.subtype =
4734 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4735 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4736 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4737 return -EINVAL;
4738 } else {
4739 /* Default to Deauthentication frame */
4740 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4741 }
4742
4743 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4744 params.reason_code =
4745 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4746 if (params.reason_code == 0)
4747 return -EINVAL; /* 0 is reserved */
4748 } else {
4749 /* Default to reason code 2 */
4750 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4751 }
4752
Jouni Malinen89c771e2014-10-10 20:52:40 +03004753 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004754}
4755
Eric W. Biederman15e47302012-09-07 20:12:54 +00004756static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004757 int flags, struct net_device *dev,
4758 u8 *dst, u8 *next_hop,
4759 struct mpath_info *pinfo)
4760{
4761 void *hdr;
4762 struct nlattr *pinfoattr;
4763
Henning Rogge1ef4c852014-11-04 16:14:58 +01004764 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004765 if (!hdr)
4766 return -1;
4767
David S. Miller9360ffd2012-03-29 04:41:26 -04004768 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4769 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4770 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4771 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4772 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004773
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004774 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4775 if (!pinfoattr)
4776 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004777 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4778 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4779 pinfo->frame_qlen))
4780 goto nla_put_failure;
4781 if (((pinfo->filled & MPATH_INFO_SN) &&
4782 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4783 ((pinfo->filled & MPATH_INFO_METRIC) &&
4784 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4785 pinfo->metric)) ||
4786 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4787 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4788 pinfo->exptime)) ||
4789 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4790 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4791 pinfo->flags)) ||
4792 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4793 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4794 pinfo->discovery_timeout)) ||
4795 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4796 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4797 pinfo->discovery_retries)))
4798 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004799
4800 nla_nest_end(msg, pinfoattr);
4801
Johannes Berg053c0952015-01-16 22:09:00 +01004802 genlmsg_end(msg, hdr);
4803 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004804
4805 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004806 genlmsg_cancel(msg, hdr);
4807 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004808}
4809
4810static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004811 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004812{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004813 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004814 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004815 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004816 u8 dst[ETH_ALEN];
4817 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004818 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004819 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004820
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004821 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004822 if (err)
4823 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004824
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004825 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004826 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004827 goto out_err;
4828 }
4829
Johannes Berg97990a02013-04-19 01:02:55 +02004830 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004831 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004832 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004833 }
4834
Johannes Bergbba95fe2008-07-29 13:22:51 +02004835 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004836 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004837 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004838 if (err == -ENOENT)
4839 break;
4840 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004841 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004842
Eric W. Biederman15e47302012-09-07 20:12:54 +00004843 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004844 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004845 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004846 &pinfo) < 0)
4847 goto out;
4848
4849 path_idx++;
4850 }
4851
Johannes Bergbba95fe2008-07-29 13:22:51 +02004852 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004853 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004854 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004855 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004856 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004857 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004858}
4859
4860static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4861{
Johannes Berg4c476992010-10-04 21:36:35 +02004862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004863 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004864 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004865 struct mpath_info pinfo;
4866 struct sk_buff *msg;
4867 u8 *dst = NULL;
4868 u8 next_hop[ETH_ALEN];
4869
4870 memset(&pinfo, 0, sizeof(pinfo));
4871
4872 if (!info->attrs[NL80211_ATTR_MAC])
4873 return -EINVAL;
4874
4875 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4876
Johannes Berg4c476992010-10-04 21:36:35 +02004877 if (!rdev->ops->get_mpath)
4878 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004879
Johannes Berg4c476992010-10-04 21:36:35 +02004880 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4881 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004882
Hila Gonene35e4d22012-06-27 17:19:42 +03004883 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004884 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004885 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004886
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004887 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004888 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004889 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004890
Eric W. Biederman15e47302012-09-07 20:12:54 +00004891 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004892 dev, dst, next_hop, &pinfo) < 0) {
4893 nlmsg_free(msg);
4894 return -ENOBUFS;
4895 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004896
Johannes Berg4c476992010-10-04 21:36:35 +02004897 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004898}
4899
4900static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4901{
Johannes Berg4c476992010-10-04 21:36:35 +02004902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4903 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004904 u8 *dst = NULL;
4905 u8 *next_hop = NULL;
4906
4907 if (!info->attrs[NL80211_ATTR_MAC])
4908 return -EINVAL;
4909
4910 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4911 return -EINVAL;
4912
4913 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4914 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4915
Johannes Berg4c476992010-10-04 21:36:35 +02004916 if (!rdev->ops->change_mpath)
4917 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004918
Johannes Berg4c476992010-10-04 21:36:35 +02004919 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4920 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004921
Hila Gonene35e4d22012-06-27 17:19:42 +03004922 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004923}
Johannes Berg4c476992010-10-04 21:36:35 +02004924
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004925static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4926{
Johannes Berg4c476992010-10-04 21:36:35 +02004927 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4928 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004929 u8 *dst = NULL;
4930 u8 *next_hop = NULL;
4931
4932 if (!info->attrs[NL80211_ATTR_MAC])
4933 return -EINVAL;
4934
4935 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4936 return -EINVAL;
4937
4938 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4939 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4940
Johannes Berg4c476992010-10-04 21:36:35 +02004941 if (!rdev->ops->add_mpath)
4942 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004943
Johannes Berg4c476992010-10-04 21:36:35 +02004944 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4945 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004946
Hila Gonene35e4d22012-06-27 17:19:42 +03004947 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004948}
4949
4950static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4951{
Johannes Berg4c476992010-10-04 21:36:35 +02004952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4953 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004954 u8 *dst = NULL;
4955
4956 if (info->attrs[NL80211_ATTR_MAC])
4957 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4958
Johannes Berg4c476992010-10-04 21:36:35 +02004959 if (!rdev->ops->del_mpath)
4960 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004961
Hila Gonene35e4d22012-06-27 17:19:42 +03004962 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004963}
4964
Henning Rogge66be7d22014-09-12 08:58:49 +02004965static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4966{
4967 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4968 int err;
4969 struct net_device *dev = info->user_ptr[1];
4970 struct mpath_info pinfo;
4971 struct sk_buff *msg;
4972 u8 *dst = NULL;
4973 u8 mpp[ETH_ALEN];
4974
4975 memset(&pinfo, 0, sizeof(pinfo));
4976
4977 if (!info->attrs[NL80211_ATTR_MAC])
4978 return -EINVAL;
4979
4980 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4981
4982 if (!rdev->ops->get_mpp)
4983 return -EOPNOTSUPP;
4984
4985 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4986 return -EOPNOTSUPP;
4987
4988 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4989 if (err)
4990 return err;
4991
4992 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4993 if (!msg)
4994 return -ENOMEM;
4995
4996 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4997 dev, dst, mpp, &pinfo) < 0) {
4998 nlmsg_free(msg);
4999 return -ENOBUFS;
5000 }
5001
5002 return genlmsg_reply(msg, info);
5003}
5004
5005static int nl80211_dump_mpp(struct sk_buff *skb,
5006 struct netlink_callback *cb)
5007{
5008 struct mpath_info pinfo;
5009 struct cfg80211_registered_device *rdev;
5010 struct wireless_dev *wdev;
5011 u8 dst[ETH_ALEN];
5012 u8 mpp[ETH_ALEN];
5013 int path_idx = cb->args[2];
5014 int err;
5015
5016 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5017 if (err)
5018 return err;
5019
5020 if (!rdev->ops->dump_mpp) {
5021 err = -EOPNOTSUPP;
5022 goto out_err;
5023 }
5024
5025 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5026 err = -EOPNOTSUPP;
5027 goto out_err;
5028 }
5029
5030 while (1) {
5031 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5032 mpp, &pinfo);
5033 if (err == -ENOENT)
5034 break;
5035 if (err)
5036 goto out_err;
5037
5038 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5039 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5040 wdev->netdev, dst, mpp,
5041 &pinfo) < 0)
5042 goto out;
5043
5044 path_idx++;
5045 }
5046
5047 out:
5048 cb->args[2] = path_idx;
5049 err = skb->len;
5050 out_err:
5051 nl80211_finish_wdev_dump(rdev);
5052 return err;
5053}
5054
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005055static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5056{
Johannes Berg4c476992010-10-04 21:36:35 +02005057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5058 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005059 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005060 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005061 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005062
5063 memset(&params, 0, sizeof(params));
5064 /* default to not changing parameters */
5065 params.use_cts_prot = -1;
5066 params.use_short_preamble = -1;
5067 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005068 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005069 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005070 params.p2p_ctwindow = -1;
5071 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005072
5073 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5074 params.use_cts_prot =
5075 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5076 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5077 params.use_short_preamble =
5078 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5079 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5080 params.use_short_slot_time =
5081 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005082 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5083 params.basic_rates =
5084 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5085 params.basic_rates_len =
5086 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5087 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005088 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5089 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005090 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5091 params.ht_opmode =
5092 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005093
Johannes Berg53cabad2012-11-14 15:17:28 +01005094 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5095 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5096 return -EINVAL;
5097 params.p2p_ctwindow =
5098 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5099 if (params.p2p_ctwindow < 0)
5100 return -EINVAL;
5101 if (params.p2p_ctwindow != 0 &&
5102 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5103 return -EINVAL;
5104 }
5105
5106 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5107 u8 tmp;
5108
5109 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5110 return -EINVAL;
5111 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5112 if (tmp > 1)
5113 return -EINVAL;
5114 params.p2p_opp_ps = tmp;
5115 if (params.p2p_opp_ps &&
5116 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5117 return -EINVAL;
5118 }
5119
Johannes Berg4c476992010-10-04 21:36:35 +02005120 if (!rdev->ops->change_bss)
5121 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005122
Johannes Berg074ac8d2010-09-16 14:58:22 +02005123 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005124 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5125 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005126
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005127 wdev_lock(wdev);
5128 err = rdev_change_bss(rdev, dev, &params);
5129 wdev_unlock(wdev);
5130
5131 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005132}
5133
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005134static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5135{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005136 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005137 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005138 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005139 u32 owner_nlportid;
5140
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005141 /*
5142 * You should only get this when cfg80211 hasn't yet initialized
5143 * completely when built-in to the kernel right between the time
5144 * window between nl80211_init() and regulatory_init(), if that is
5145 * even possible.
5146 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005147 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005148 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005149
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005150 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5151 user_reg_hint_type =
5152 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5153 else
5154 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5155
5156 switch (user_reg_hint_type) {
5157 case NL80211_USER_REG_HINT_USER:
5158 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005159 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5160 return -EINVAL;
5161
5162 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5163 return regulatory_hint_user(data, user_reg_hint_type);
5164 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005165 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5166 owner_nlportid = info->snd_portid;
5167 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5168 } else {
5169 owner_nlportid = 0;
5170 is_indoor = true;
5171 }
5172
5173 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005174 default:
5175 return -EINVAL;
5176 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005177}
5178
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005179static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005180 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005181{
Johannes Berg4c476992010-10-04 21:36:35 +02005182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005183 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005184 struct wireless_dev *wdev = dev->ieee80211_ptr;
5185 struct mesh_config cur_params;
5186 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005187 void *hdr;
5188 struct nlattr *pinfoattr;
5189 struct sk_buff *msg;
5190
Johannes Berg29cbe682010-12-03 09:20:44 +01005191 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5192 return -EOPNOTSUPP;
5193
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005194 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005195 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005196
Johannes Berg29cbe682010-12-03 09:20:44 +01005197 wdev_lock(wdev);
5198 /* If not connected, get default parameters */
5199 if (!wdev->mesh_id_len)
5200 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5201 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005202 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005203 wdev_unlock(wdev);
5204
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005205 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005206 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005207
5208 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005210 if (!msg)
5211 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005212 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005213 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005214 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005215 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005216 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005217 if (!pinfoattr)
5218 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005219 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5220 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5221 cur_params.dot11MeshRetryTimeout) ||
5222 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5223 cur_params.dot11MeshConfirmTimeout) ||
5224 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5225 cur_params.dot11MeshHoldingTimeout) ||
5226 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5227 cur_params.dot11MeshMaxPeerLinks) ||
5228 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5229 cur_params.dot11MeshMaxRetries) ||
5230 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5231 cur_params.dot11MeshTTL) ||
5232 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5233 cur_params.element_ttl) ||
5234 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5235 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005236 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5237 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005238 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5239 cur_params.dot11MeshHWMPmaxPREQretries) ||
5240 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5241 cur_params.path_refresh_time) ||
5242 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5243 cur_params.min_discovery_timeout) ||
5244 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5245 cur_params.dot11MeshHWMPactivePathTimeout) ||
5246 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5247 cur_params.dot11MeshHWMPpreqMinInterval) ||
5248 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5249 cur_params.dot11MeshHWMPperrMinInterval) ||
5250 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5251 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5252 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5253 cur_params.dot11MeshHWMPRootMode) ||
5254 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5255 cur_params.dot11MeshHWMPRannInterval) ||
5256 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5257 cur_params.dot11MeshGateAnnouncementProtocol) ||
5258 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5259 cur_params.dot11MeshForwarding) ||
5260 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005261 cur_params.rssi_threshold) ||
5262 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005263 cur_params.ht_opmode) ||
5264 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5265 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5266 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005267 cur_params.dot11MeshHWMProotInterval) ||
5268 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005269 cur_params.dot11MeshHWMPconfirmationInterval) ||
5270 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5271 cur_params.power_mode) ||
5272 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005273 cur_params.dot11MeshAwakeWindowDuration) ||
5274 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5275 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005276 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005277 nla_nest_end(msg, pinfoattr);
5278 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005279 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005280
Johannes Berg3b858752009-03-12 09:55:09 +01005281 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005282 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005283 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005284 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005285 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005286}
5287
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005288static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005289 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5290 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5291 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5292 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5293 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5294 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005295 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005296 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005297 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005298 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5299 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5300 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5301 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5302 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005303 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005304 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005305 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005306 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005307 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005308 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005309 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5310 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005311 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5312 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005313 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005314 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5315 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005316 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005317};
5318
Javier Cardonac80d5452010-12-16 17:37:49 -08005319static const struct nla_policy
5320 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005321 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005322 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5323 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005324 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005325 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005326 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005327 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005328 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005329 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005330};
5331
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005332static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5333{
5334 u8 val = nla_get_u8(nla);
5335 if (val < min || val > max)
5336 return -EINVAL;
5337 *out = val;
5338 return 0;
5339}
5340
5341static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5342{
5343 u8 val = nla_get_u8(nla);
5344 if (val < min || val > max)
5345 return -EINVAL;
5346 *out = val;
5347 return 0;
5348}
5349
5350static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5351{
5352 u16 val = nla_get_u16(nla);
5353 if (val < min || val > max)
5354 return -EINVAL;
5355 *out = val;
5356 return 0;
5357}
5358
5359static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5360{
5361 u32 val = nla_get_u32(nla);
5362 if (val < min || val > max)
5363 return -EINVAL;
5364 *out = val;
5365 return 0;
5366}
5367
5368static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5369{
5370 s32 val = nla_get_s32(nla);
5371 if (val < min || val > max)
5372 return -EINVAL;
5373 *out = val;
5374 return 0;
5375}
5376
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005377static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005378 struct mesh_config *cfg,
5379 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005380{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005381 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005382 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005383 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005384
Marco Porschea54fba2013-01-07 16:04:48 +01005385#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5386do { \
5387 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005388 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005389 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005390 mask |= (1 << (attr - 1)); \
5391 } \
5392} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005393
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005394 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005395 return -EINVAL;
5396 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005397 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005398 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005399 return -EINVAL;
5400
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005401 /* This makes sure that there aren't more than 32 mesh config
5402 * parameters (otherwise our bitfield scheme would not work.) */
5403 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5404
5405 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005406 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005407 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005408 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005410 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005411 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005412 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005413 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005414 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005415 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005416 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005417 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005418 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005419 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005420 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005421 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005422 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005423 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005424 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005425 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005426 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005427 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005428 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005429 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5430 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005431 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005432 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005433 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005434 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005435 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005436 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005437 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
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, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005440 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005441 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005442 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5443 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005444 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005445 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005446 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005447 1, 65535, mask,
5448 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005449 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005450 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005451 1, 65535, mask,
5452 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005453 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005454 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005455 dot11MeshHWMPnetDiameterTraversalTime,
5456 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005457 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005458 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005459 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5460 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005461 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005462 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5463 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005464 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005465 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005466 dot11MeshGateAnnouncementProtocol, 0, 1,
5467 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005468 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005469 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005470 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005471 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005472 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005473 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005474 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005475 /*
5476 * Check HT operation mode based on
5477 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5478 */
5479 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5480 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5481
5482 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5483 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5484 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5485 return -EINVAL;
5486
5487 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5488 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5489 return -EINVAL;
5490
5491 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5492 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5493 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5494 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5495 return -EINVAL;
5496 break;
5497 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5498 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5499 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5500 return -EINVAL;
5501 break;
5502 }
5503 cfg->ht_opmode = ht_opmode;
5504 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005505 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005506 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005507 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005508 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005509 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005510 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005511 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005512 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005513 dot11MeshHWMPconfirmationInterval,
5514 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005515 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005516 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005517 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5518 NL80211_MESH_POWER_ACTIVE,
5519 NL80211_MESH_POWER_MAX,
5520 mask, NL80211_MESHCONF_POWER_MODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005521 nl80211_check_u32);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005522 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5523 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005524 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005525 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005526 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005527 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005528 if (mask_out)
5529 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005530
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005531 return 0;
5532
5533#undef FILL_IN_MESH_PARAM_IF_SET
5534}
5535
Javier Cardonac80d5452010-12-16 17:37:49 -08005536static int nl80211_parse_mesh_setup(struct genl_info *info,
5537 struct mesh_setup *setup)
5538{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005540 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5541
5542 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5543 return -EINVAL;
5544 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5545 info->attrs[NL80211_ATTR_MESH_SETUP],
5546 nl80211_mesh_setup_params_policy))
5547 return -EINVAL;
5548
Javier Cardonad299a1f2012-03-31 11:31:33 -07005549 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5550 setup->sync_method =
5551 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5552 IEEE80211_SYNC_METHOD_VENDOR :
5553 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5554
Javier Cardonac80d5452010-12-16 17:37:49 -08005555 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5556 setup->path_sel_proto =
5557 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5558 IEEE80211_PATH_PROTOCOL_VENDOR :
5559 IEEE80211_PATH_PROTOCOL_HWMP;
5560
5561 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5562 setup->path_metric =
5563 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5564 IEEE80211_PATH_METRIC_VENDOR :
5565 IEEE80211_PATH_METRIC_AIRTIME;
5566
Javier Cardona581a8b02011-04-07 15:08:27 -07005567 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005568 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005569 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005570 if (!is_valid_ie_attr(ieattr))
5571 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005572 setup->ie = nla_data(ieattr);
5573 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005574 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005575 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5576 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5577 return -EINVAL;
5578 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005579 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5580 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005581 if (setup->is_secure)
5582 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005583
Colleen Twitty6e16d902013-05-08 11:45:59 -07005584 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5585 if (!setup->user_mpm)
5586 return -EINVAL;
5587 setup->auth_id =
5588 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5589 }
5590
Javier Cardonac80d5452010-12-16 17:37:49 -08005591 return 0;
5592}
5593
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005594static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005595 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005596{
5597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5598 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005599 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005600 struct mesh_config cfg;
5601 u32 mask;
5602 int err;
5603
Johannes Berg29cbe682010-12-03 09:20:44 +01005604 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5605 return -EOPNOTSUPP;
5606
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005607 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005608 return -EOPNOTSUPP;
5609
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005610 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005611 if (err)
5612 return err;
5613
Johannes Berg29cbe682010-12-03 09:20:44 +01005614 wdev_lock(wdev);
5615 if (!wdev->mesh_id_len)
5616 err = -ENOLINK;
5617
5618 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005619 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005620
5621 wdev_unlock(wdev);
5622
5623 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005624}
5625
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005626static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5627 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005628{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005629 struct nlattr *nl_reg_rules;
5630 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005631
Johannes Berg458f4f92012-12-06 15:47:38 +01005632 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5633 (regdom->dfs_region &&
5634 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005635 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005636
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005637 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5638 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005639 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005640
Johannes Berg458f4f92012-12-06 15:47:38 +01005641 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005642 struct nlattr *nl_reg_rule;
5643 const struct ieee80211_reg_rule *reg_rule;
5644 const struct ieee80211_freq_range *freq_range;
5645 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005646 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005647
Johannes Berg458f4f92012-12-06 15:47:38 +01005648 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005649 freq_range = &reg_rule->freq_range;
5650 power_rule = &reg_rule->power_rule;
5651
5652 nl_reg_rule = nla_nest_start(msg, i);
5653 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005654 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005655
Janusz Dziedzic97524822014-01-30 09:52:20 +01005656 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5657 if (!max_bandwidth_khz)
5658 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5659 reg_rule);
5660
David S. Miller9360ffd2012-03-29 04:41:26 -04005661 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5662 reg_rule->flags) ||
5663 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5664 freq_range->start_freq_khz) ||
5665 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5666 freq_range->end_freq_khz) ||
5667 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005668 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005669 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5670 power_rule->max_antenna_gain) ||
5671 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005672 power_rule->max_eirp) ||
5673 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5674 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005675 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005676
5677 nla_nest_end(msg, nl_reg_rule);
5678 }
5679
5680 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005681 return 0;
5682
5683nla_put_failure:
5684 return -EMSGSIZE;
5685}
5686
5687static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5688{
5689 const struct ieee80211_regdomain *regdom = NULL;
5690 struct cfg80211_registered_device *rdev;
5691 struct wiphy *wiphy = NULL;
5692 struct sk_buff *msg;
5693 void *hdr;
5694
5695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5696 if (!msg)
5697 return -ENOBUFS;
5698
5699 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5700 NL80211_CMD_GET_REG);
5701 if (!hdr)
5702 goto put_failure;
5703
5704 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005705 bool self_managed;
5706
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005707 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5708 if (IS_ERR(rdev)) {
5709 nlmsg_free(msg);
5710 return PTR_ERR(rdev);
5711 }
5712
5713 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005714 self_managed = wiphy->regulatory_flags &
5715 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005716 regdom = get_wiphy_regdom(wiphy);
5717
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005718 /* a self-managed-reg device must have a private regdom */
5719 if (WARN_ON(!regdom && self_managed)) {
5720 nlmsg_free(msg);
5721 return -EINVAL;
5722 }
5723
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005724 if (regdom &&
5725 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5726 goto nla_put_failure;
5727 }
5728
5729 if (!wiphy && reg_last_request_cell_base() &&
5730 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5731 NL80211_USER_REG_HINT_CELL_BASE))
5732 goto nla_put_failure;
5733
5734 rcu_read_lock();
5735
5736 if (!regdom)
5737 regdom = rcu_dereference(cfg80211_regdomain);
5738
5739 if (nl80211_put_regdom(regdom, msg))
5740 goto nla_put_failure_rcu;
5741
5742 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005743
5744 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005745 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005746
Johannes Berg458f4f92012-12-06 15:47:38 +01005747nla_put_failure_rcu:
5748 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005749nla_put_failure:
5750 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005751put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005752 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005753 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005754}
5755
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005756static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5757 u32 seq, int flags, struct wiphy *wiphy,
5758 const struct ieee80211_regdomain *regdom)
5759{
5760 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5761 NL80211_CMD_GET_REG);
5762
5763 if (!hdr)
5764 return -1;
5765
5766 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5767
5768 if (nl80211_put_regdom(regdom, msg))
5769 goto nla_put_failure;
5770
5771 if (!wiphy && reg_last_request_cell_base() &&
5772 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5773 NL80211_USER_REG_HINT_CELL_BASE))
5774 goto nla_put_failure;
5775
5776 if (wiphy &&
5777 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5778 goto nla_put_failure;
5779
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005780 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5781 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5782 goto nla_put_failure;
5783
Johannes Berg053c0952015-01-16 22:09:00 +01005784 genlmsg_end(msg, hdr);
5785 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005786
5787nla_put_failure:
5788 genlmsg_cancel(msg, hdr);
5789 return -EMSGSIZE;
5790}
5791
5792static int nl80211_get_reg_dump(struct sk_buff *skb,
5793 struct netlink_callback *cb)
5794{
5795 const struct ieee80211_regdomain *regdom = NULL;
5796 struct cfg80211_registered_device *rdev;
5797 int err, reg_idx, start = cb->args[2];
5798
5799 rtnl_lock();
5800
5801 if (cfg80211_regdomain && start == 0) {
5802 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5803 NLM_F_MULTI, NULL,
5804 rtnl_dereference(cfg80211_regdomain));
5805 if (err < 0)
5806 goto out_err;
5807 }
5808
5809 /* the global regdom is idx 0 */
5810 reg_idx = 1;
5811 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5812 regdom = get_wiphy_regdom(&rdev->wiphy);
5813 if (!regdom)
5814 continue;
5815
5816 if (++reg_idx <= start)
5817 continue;
5818
5819 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5820 NLM_F_MULTI, &rdev->wiphy, regdom);
5821 if (err < 0) {
5822 reg_idx--;
5823 break;
5824 }
5825 }
5826
5827 cb->args[2] = reg_idx;
5828 err = skb->len;
5829out_err:
5830 rtnl_unlock();
5831 return err;
5832}
5833
Johannes Bergb6863032015-10-15 09:25:18 +02005834#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5835static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5836 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5837 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5838 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5839 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5840 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5841 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5842 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5843};
5844
5845static int parse_reg_rule(struct nlattr *tb[],
5846 struct ieee80211_reg_rule *reg_rule)
5847{
5848 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5849 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5850
5851 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5852 return -EINVAL;
5853 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5854 return -EINVAL;
5855 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5856 return -EINVAL;
5857 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5858 return -EINVAL;
5859 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5860 return -EINVAL;
5861
5862 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5863
5864 freq_range->start_freq_khz =
5865 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5866 freq_range->end_freq_khz =
5867 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5868 freq_range->max_bandwidth_khz =
5869 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5870
5871 power_rule->max_eirp =
5872 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5873
5874 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5875 power_rule->max_antenna_gain =
5876 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5877
5878 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5879 reg_rule->dfs_cac_ms =
5880 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5881
5882 return 0;
5883}
5884
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005885static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5886{
5887 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5888 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005889 char *alpha2;
5890 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005891 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005892 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005893 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005894
5895 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5896 return -EINVAL;
5897
5898 if (!info->attrs[NL80211_ATTR_REG_RULES])
5899 return -EINVAL;
5900
5901 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5902
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005903 if (info->attrs[NL80211_ATTR_DFS_REGION])
5904 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5905
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005906 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005907 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005908 num_rules++;
5909 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005910 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005911 }
5912
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005913 if (!reg_is_valid_request(alpha2))
5914 return -EINVAL;
5915
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005916 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005917 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005918
5919 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005920 if (!rd)
5921 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005922
5923 rd->n_reg_rules = num_rules;
5924 rd->alpha2[0] = alpha2[0];
5925 rd->alpha2[1] = alpha2[1];
5926
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005927 /*
5928 * Disable DFS master mode if the DFS region was
5929 * not supported or known on this kernel.
5930 */
5931 if (reg_supported_dfs_region(dfs_region))
5932 rd->dfs_region = dfs_region;
5933
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005934 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005935 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005936 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5937 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5938 reg_rule_policy);
5939 if (r)
5940 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005941 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5942 if (r)
5943 goto bad_reg;
5944
5945 rule_idx++;
5946
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005947 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5948 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005949 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005950 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005951 }
5952
Johannes Berg06627992016-06-09 10:40:09 +02005953 /* set_regdom takes ownership of rd */
5954 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02005955 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005956 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005957 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005958}
Johannes Bergb6863032015-10-15 09:25:18 +02005959#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005960
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005961static int validate_scan_freqs(struct nlattr *freqs)
5962{
5963 struct nlattr *attr1, *attr2;
5964 int n_channels = 0, tmp1, tmp2;
5965
5966 nla_for_each_nested(attr1, freqs, tmp1) {
5967 n_channels++;
5968 /*
5969 * Some hardware has a limited channel list for
5970 * scanning, and it is pretty much nonsensical
5971 * to scan for a channel twice, so disallow that
5972 * and don't require drivers to check that the
5973 * channel list they get isn't longer than what
5974 * they can scan, as long as they can scan all
5975 * the channels they registered at once.
5976 */
5977 nla_for_each_nested(attr2, freqs, tmp2)
5978 if (attr1 != attr2 &&
5979 nla_get_u32(attr1) == nla_get_u32(attr2))
5980 return 0;
5981 }
5982
5983 return n_channels;
5984}
5985
Johannes Berg57fbcce2016-04-12 15:56:15 +02005986static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005987{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005988 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005989}
5990
5991static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5992 struct cfg80211_bss_selection *bss_select)
5993{
5994 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5995 struct nlattr *nest;
5996 int err;
5997 bool found = false;
5998 int i;
5999
6000 /* only process one nested attribute */
6001 nest = nla_data(nla);
6002 if (!nla_ok(nest, nla_len(nest)))
6003 return -EINVAL;
6004
6005 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
6006 nla_len(nest), nl80211_bss_select_policy);
6007 if (err)
6008 return err;
6009
6010 /* only one attribute may be given */
6011 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6012 if (attr[i]) {
6013 if (found)
6014 return -EINVAL;
6015 found = true;
6016 }
6017 }
6018
6019 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6020
6021 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6022 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6023
6024 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6025 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6026 bss_select->param.band_pref =
6027 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6028 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6029 return -EINVAL;
6030 }
6031
6032 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6033 struct nl80211_bss_select_rssi_adjust *adj_param;
6034
6035 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6036 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6037 bss_select->param.adjust.band = adj_param->band;
6038 bss_select->param.adjust.delta = adj_param->delta;
6039 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6040 return -EINVAL;
6041 }
6042
6043 /* user-space did not provide behaviour attribute */
6044 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6045 return -EINVAL;
6046
6047 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6048 return -EINVAL;
6049
6050 return 0;
6051}
6052
Johannes Bergad2b26a2014-06-12 21:39:05 +02006053static int nl80211_parse_random_mac(struct nlattr **attrs,
6054 u8 *mac_addr, u8 *mac_addr_mask)
6055{
6056 int i;
6057
6058 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006059 eth_zero_addr(mac_addr);
6060 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006061 mac_addr[0] = 0x2;
6062 mac_addr_mask[0] = 0x3;
6063
6064 return 0;
6065 }
6066
6067 /* need both or none */
6068 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6069 return -EINVAL;
6070
6071 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6072 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6073
6074 /* don't allow or configure an mcast address */
6075 if (!is_multicast_ether_addr(mac_addr_mask) ||
6076 is_multicast_ether_addr(mac_addr))
6077 return -EINVAL;
6078
6079 /*
6080 * allow users to pass a MAC address that has bits set outside
6081 * of the mask, but don't bother drivers with having to deal
6082 * with such bits
6083 */
6084 for (i = 0; i < ETH_ALEN; i++)
6085 mac_addr[i] &= mac_addr_mask[i];
6086
6087 return 0;
6088}
6089
Johannes Berg2a519312009-02-10 21:25:55 +01006090static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6091{
Johannes Berg4c476992010-10-04 21:36:35 +02006092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006093 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006094 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006095 struct nlattr *attr;
6096 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006097 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006098 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006099
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006100 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6101 return -EINVAL;
6102
Johannes Berg79c97e92009-07-07 03:56:12 +02006103 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006104
Johannes Berg4c476992010-10-04 21:36:35 +02006105 if (!rdev->ops->scan)
6106 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006107
Johannes Bergf9d15d12014-01-22 11:14:19 +02006108 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006109 err = -EBUSY;
6110 goto unlock;
6111 }
Johannes Berg2a519312009-02-10 21:25:55 +01006112
6113 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006114 n_channels = validate_scan_freqs(
6115 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006116 if (!n_channels) {
6117 err = -EINVAL;
6118 goto unlock;
6119 }
Johannes Berg2a519312009-02-10 21:25:55 +01006120 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006121 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006122 }
6123
6124 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6125 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6126 n_ssids++;
6127
Johannes Bergf9f47522013-03-19 15:04:07 +01006128 if (n_ssids > wiphy->max_scan_ssids) {
6129 err = -EINVAL;
6130 goto unlock;
6131 }
Johannes Berg2a519312009-02-10 21:25:55 +01006132
Jouni Malinen70692ad2009-02-16 19:39:13 +02006133 if (info->attrs[NL80211_ATTR_IE])
6134 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6135 else
6136 ie_len = 0;
6137
Johannes Bergf9f47522013-03-19 15:04:07 +01006138 if (ie_len > wiphy->max_scan_ie_len) {
6139 err = -EINVAL;
6140 goto unlock;
6141 }
Johannes Berg18a83652009-03-31 12:12:05 +02006142
Johannes Berg2a519312009-02-10 21:25:55 +01006143 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006144 + sizeof(*request->ssids) * n_ssids
6145 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006146 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006147 if (!request) {
6148 err = -ENOMEM;
6149 goto unlock;
6150 }
Johannes Berg2a519312009-02-10 21:25:55 +01006151
Johannes Berg2a519312009-02-10 21:25:55 +01006152 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006153 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006154 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006155 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006156 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006157 request->ie = (void *)(request->ssids + n_ssids);
6158 else
6159 request->ie = (void *)(request->channels + n_channels);
6160 }
Johannes Berg2a519312009-02-10 21:25:55 +01006161
Johannes Berg584991d2009-11-02 13:32:03 +01006162 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006163 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6164 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006165 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006166 struct ieee80211_channel *chan;
6167
6168 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6169
6170 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006171 err = -EINVAL;
6172 goto out_free;
6173 }
Johannes Berg584991d2009-11-02 13:32:03 +01006174
6175 /* ignore disabled channels */
6176 if (chan->flags & IEEE80211_CHAN_DISABLED)
6177 continue;
6178
6179 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006180 i++;
6181 }
6182 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006183 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006184
Johannes Berg2a519312009-02-10 21:25:55 +01006185 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006186 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006187 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006188
Johannes Berg2a519312009-02-10 21:25:55 +01006189 if (!wiphy->bands[band])
6190 continue;
6191 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006192 struct ieee80211_channel *chan;
6193
6194 chan = &wiphy->bands[band]->channels[j];
6195
6196 if (chan->flags & IEEE80211_CHAN_DISABLED)
6197 continue;
6198
6199 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006200 i++;
6201 }
6202 }
6203 }
6204
Johannes Berg584991d2009-11-02 13:32:03 +01006205 if (!i) {
6206 err = -EINVAL;
6207 goto out_free;
6208 }
6209
6210 request->n_channels = i;
6211
Johannes Berg2a519312009-02-10 21:25:55 +01006212 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006213 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006214 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006215 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006216 err = -EINVAL;
6217 goto out_free;
6218 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006219 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006220 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006221 i++;
6222 }
6223 }
6224
Jouni Malinen70692ad2009-02-16 19:39:13 +02006225 if (info->attrs[NL80211_ATTR_IE]) {
6226 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006227 memcpy((void *)request->ie,
6228 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006229 request->ie_len);
6230 }
6231
Johannes Berg57fbcce2016-04-12 15:56:15 +02006232 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006233 if (wiphy->bands[i])
6234 request->rates[i] =
6235 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006236
6237 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6238 nla_for_each_nested(attr,
6239 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6240 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006241 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006242
Johannes Berg57fbcce2016-04-12 15:56:15 +02006243 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006244 err = -EINVAL;
6245 goto out_free;
6246 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006247
6248 if (!wiphy->bands[band])
6249 continue;
6250
Johannes Berg34850ab2011-07-18 18:08:35 +02006251 err = ieee80211_get_ratemask(wiphy->bands[band],
6252 nla_data(attr),
6253 nla_len(attr),
6254 &request->rates[band]);
6255 if (err)
6256 goto out_free;
6257 }
6258 }
6259
Avraham Stern1d762502016-07-05 17:10:13 +03006260 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6261 if (!wiphy_ext_feature_isset(wiphy,
6262 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6263 err = -EOPNOTSUPP;
6264 goto out_free;
6265 }
6266
6267 request->duration =
6268 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6269 request->duration_mandatory =
6270 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6271 }
6272
Sam Leffler46856bb2012-10-11 21:03:32 -07006273 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006274 request->flags = nla_get_u32(
6275 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006276 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6277 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006278 err = -EOPNOTSUPP;
6279 goto out_free;
6280 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006281
6282 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6283 if (!(wiphy->features &
6284 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6285 err = -EOPNOTSUPP;
6286 goto out_free;
6287 }
6288
6289 if (wdev->current_bss) {
6290 err = -EOPNOTSUPP;
6291 goto out_free;
6292 }
6293
6294 err = nl80211_parse_random_mac(info->attrs,
6295 request->mac_addr,
6296 request->mac_addr_mask);
6297 if (err)
6298 goto out_free;
6299 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006300 }
Sam Lefflered4737712012-10-11 21:03:31 -07006301
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306302 request->no_cck =
6303 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6304
Jouni Malinen818965d2016-02-26 22:12:47 +02006305 if (info->attrs[NL80211_ATTR_MAC])
6306 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6307 ETH_ALEN);
6308 else
6309 eth_broadcast_addr(request->bssid);
6310
Johannes Bergfd014282012-06-18 19:17:03 +02006311 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006312 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006313 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006314
Johannes Berg79c97e92009-07-07 03:56:12 +02006315 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006316 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006317
Johannes Berg463d0182009-07-14 00:33:35 +02006318 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006319 nl80211_send_scan_start(rdev, wdev);
6320 if (wdev->netdev)
6321 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006322 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006323 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006324 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006325 kfree(request);
6326 }
Johannes Berg3b858752009-03-12 09:55:09 +01006327
Johannes Bergf9f47522013-03-19 15:04:07 +01006328 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006329 return err;
6330}
6331
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306332static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6333{
6334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6335 struct wireless_dev *wdev = info->user_ptr[1];
6336
6337 if (!rdev->ops->abort_scan)
6338 return -EOPNOTSUPP;
6339
6340 if (rdev->scan_msg)
6341 return 0;
6342
6343 if (!rdev->scan_req)
6344 return -ENOENT;
6345
6346 rdev_abort_scan(rdev, wdev);
6347 return 0;
6348}
6349
Avraham Stern3b06d272015-10-12 09:51:34 +03006350static int
6351nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6352 struct cfg80211_sched_scan_request *request,
6353 struct nlattr **attrs)
6354{
6355 int tmp, err, i = 0;
6356 struct nlattr *attr;
6357
6358 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6359 u32 interval;
6360
6361 /*
6362 * If scan plans are not specified,
6363 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6364 * case one scan plan will be set with the specified scan
6365 * interval and infinite number of iterations.
6366 */
6367 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6368 return -EINVAL;
6369
6370 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6371 if (!interval)
6372 return -EINVAL;
6373
6374 request->scan_plans[0].interval =
6375 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6376 if (!request->scan_plans[0].interval)
6377 return -EINVAL;
6378
6379 if (request->scan_plans[0].interval >
6380 wiphy->max_sched_scan_plan_interval)
6381 request->scan_plans[0].interval =
6382 wiphy->max_sched_scan_plan_interval;
6383
6384 return 0;
6385 }
6386
6387 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6388 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6389
6390 if (WARN_ON(i >= n_plans))
6391 return -EINVAL;
6392
6393 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6394 nla_data(attr), nla_len(attr),
6395 nl80211_plan_policy);
6396 if (err)
6397 return err;
6398
6399 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6400 return -EINVAL;
6401
6402 request->scan_plans[i].interval =
6403 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6404 if (!request->scan_plans[i].interval ||
6405 request->scan_plans[i].interval >
6406 wiphy->max_sched_scan_plan_interval)
6407 return -EINVAL;
6408
6409 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6410 request->scan_plans[i].iterations =
6411 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6412 if (!request->scan_plans[i].iterations ||
6413 (request->scan_plans[i].iterations >
6414 wiphy->max_sched_scan_plan_iterations))
6415 return -EINVAL;
6416 } else if (i < n_plans - 1) {
6417 /*
6418 * All scan plans but the last one must specify
6419 * a finite number of iterations
6420 */
6421 return -EINVAL;
6422 }
6423
6424 i++;
6425 }
6426
6427 /*
6428 * The last scan plan must not specify the number of
6429 * iterations, it is supposed to run infinitely
6430 */
6431 if (request->scan_plans[n_plans - 1].iterations)
6432 return -EINVAL;
6433
6434 return 0;
6435}
6436
Luciano Coelho256da022014-11-10 16:13:46 +02006437static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006438nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006439 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006440{
6441 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006442 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006443 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006444 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006445 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006446 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006447 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006448
Luciano Coelho256da022014-11-10 16:13:46 +02006449 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6450 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006451
Luciano Coelho256da022014-11-10 16:13:46 +02006452 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006453 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006454 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006455 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006456 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006457 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006458 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006459 }
6460
Luciano Coelho256da022014-11-10 16:13:46 +02006461 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6462 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006463 tmp)
6464 n_ssids++;
6465
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006466 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006467 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006468
Johannes Bergea73cbc2014-01-24 10:53:53 +01006469 /*
6470 * First, count the number of 'real' matchsets. Due to an issue with
6471 * the old implementation, matchsets containing only the RSSI attribute
6472 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6473 * RSSI for all matchsets, rather than their own matchset for reporting
6474 * all APs with a strong RSSI. This is needed to be compatible with
6475 * older userspace that treated a matchset with only the RSSI as the
6476 * global RSSI for all other matchsets - if there are other matchsets.
6477 */
Luciano Coelho256da022014-11-10 16:13:46 +02006478 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006479 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006480 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006481 tmp) {
6482 struct nlattr *rssi;
6483
6484 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6485 nla_data(attr), nla_len(attr),
6486 nl80211_match_policy);
6487 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006488 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006489 /* add other standalone attributes here */
6490 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6491 n_match_sets++;
6492 continue;
6493 }
6494 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6495 if (rssi)
6496 default_match_rssi = nla_get_s32(rssi);
6497 }
6498 }
6499
6500 /* However, if there's no other matchset, add the RSSI one */
6501 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6502 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006503
6504 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006505 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006506
Luciano Coelho256da022014-11-10 16:13:46 +02006507 if (attrs[NL80211_ATTR_IE])
6508 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006509 else
6510 ie_len = 0;
6511
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006512 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006513 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006514
Avraham Stern3b06d272015-10-12 09:51:34 +03006515 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6516 /*
6517 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6518 * each scan plan already specifies its own interval
6519 */
6520 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6521 return ERR_PTR(-EINVAL);
6522
6523 nla_for_each_nested(attr,
6524 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6525 n_plans++;
6526 } else {
6527 /*
6528 * The scan interval attribute is kept for backward
6529 * compatibility. If no scan plans are specified and sched scan
6530 * interval is specified, one scan plan will be set with this
6531 * scan interval and infinite number of iterations.
6532 */
6533 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6534 return ERR_PTR(-EINVAL);
6535
6536 n_plans = 1;
6537 }
6538
6539 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6540 return ERR_PTR(-EINVAL);
6541
Luciano Coelho807f8a82011-05-11 17:09:35 +03006542 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006543 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006544 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006545 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006546 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006547 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006548 if (!request)
6549 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006550
6551 if (n_ssids)
6552 request->ssids = (void *)&request->channels[n_channels];
6553 request->n_ssids = n_ssids;
6554 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006555 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006556 request->ie = (void *)(request->ssids + n_ssids);
6557 else
6558 request->ie = (void *)(request->channels + n_channels);
6559 }
6560
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006561 if (n_match_sets) {
6562 if (request->ie)
6563 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006564 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006565 request->match_sets =
6566 (void *)(request->ssids + n_ssids);
6567 else
6568 request->match_sets =
6569 (void *)(request->channels + n_channels);
6570 }
6571 request->n_match_sets = n_match_sets;
6572
Avraham Stern3b06d272015-10-12 09:51:34 +03006573 if (n_match_sets)
6574 request->scan_plans = (void *)(request->match_sets +
6575 n_match_sets);
6576 else if (request->ie)
6577 request->scan_plans = (void *)(request->ie + ie_len);
6578 else if (n_ssids)
6579 request->scan_plans = (void *)(request->ssids + n_ssids);
6580 else
6581 request->scan_plans = (void *)(request->channels + n_channels);
6582
6583 request->n_scan_plans = n_plans;
6584
Luciano Coelho807f8a82011-05-11 17:09:35 +03006585 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006586 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006587 /* user specified, bail out if channel not found */
6588 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006589 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006590 tmp) {
6591 struct ieee80211_channel *chan;
6592
6593 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6594
6595 if (!chan) {
6596 err = -EINVAL;
6597 goto out_free;
6598 }
6599
6600 /* ignore disabled channels */
6601 if (chan->flags & IEEE80211_CHAN_DISABLED)
6602 continue;
6603
6604 request->channels[i] = chan;
6605 i++;
6606 }
6607 } else {
6608 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006609 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006610 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006611
Luciano Coelho807f8a82011-05-11 17:09:35 +03006612 if (!wiphy->bands[band])
6613 continue;
6614 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6615 struct ieee80211_channel *chan;
6616
6617 chan = &wiphy->bands[band]->channels[j];
6618
6619 if (chan->flags & IEEE80211_CHAN_DISABLED)
6620 continue;
6621
6622 request->channels[i] = chan;
6623 i++;
6624 }
6625 }
6626 }
6627
6628 if (!i) {
6629 err = -EINVAL;
6630 goto out_free;
6631 }
6632
6633 request->n_channels = i;
6634
6635 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006636 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006637 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006638 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006639 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006640 err = -EINVAL;
6641 goto out_free;
6642 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006643 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006644 memcpy(request->ssids[i].ssid, nla_data(attr),
6645 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006646 i++;
6647 }
6648 }
6649
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006650 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006651 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006652 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006653 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006654 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006655 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006656
Johannes Bergae811e22014-01-24 10:17:47 +01006657 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6658 nla_data(attr), nla_len(attr),
6659 nl80211_match_policy);
6660 if (err)
6661 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006662 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006663 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006664 if (WARN_ON(i >= n_match_sets)) {
6665 /* this indicates a programming error,
6666 * the loop above should have verified
6667 * things properly
6668 */
6669 err = -EINVAL;
6670 goto out_free;
6671 }
6672
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006673 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6674 err = -EINVAL;
6675 goto out_free;
6676 }
6677 memcpy(request->match_sets[i].ssid.ssid,
6678 nla_data(ssid), nla_len(ssid));
6679 request->match_sets[i].ssid.ssid_len =
6680 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07006681 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01006682 request->match_sets[i].rssi_thold =
6683 default_match_rssi;
6684 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6685 if (rssi)
6686 request->match_sets[i].rssi_thold =
6687 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006688 }
6689 i++;
6690 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006691
6692 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006693 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006694 request->match_sets[0].rssi_thold = default_match_rssi;
6695
6696 request->min_rssi_thold = INT_MAX;
6697 for (i = 0; i < n_match_sets; i++)
6698 request->min_rssi_thold =
6699 min(request->match_sets[i].rssi_thold,
6700 request->min_rssi_thold);
6701 } else {
6702 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006703 }
6704
Johannes Berg9900e482014-02-04 21:01:25 +01006705 if (ie_len) {
6706 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006707 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006708 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006709 request->ie_len);
6710 }
6711
Luciano Coelho256da022014-11-10 16:13:46 +02006712 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006713 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006714 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006715 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6716 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006717 err = -EOPNOTSUPP;
6718 goto out_free;
6719 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006720
6721 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6722 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6723
6724 if (!wdev) /* must be net-detect */
6725 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6726
6727 if (!(wiphy->features & flg)) {
6728 err = -EOPNOTSUPP;
6729 goto out_free;
6730 }
6731
6732 if (wdev && wdev->current_bss) {
6733 err = -EOPNOTSUPP;
6734 goto out_free;
6735 }
6736
6737 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6738 request->mac_addr_mask);
6739 if (err)
6740 goto out_free;
6741 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006742 }
Sam Lefflered4737712012-10-11 21:03:31 -07006743
Luciano Coelho9c748932015-01-16 16:04:09 +02006744 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6745 request->delay =
6746 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6747
Avraham Stern3b06d272015-10-12 09:51:34 +03006748 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6749 if (err)
6750 goto out_free;
6751
Sam Leffler15d60302012-10-11 21:03:34 -07006752 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006753
Luciano Coelho256da022014-11-10 16:13:46 +02006754 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006755
6756out_free:
6757 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006758 return ERR_PTR(err);
6759}
6760
6761static int nl80211_start_sched_scan(struct sk_buff *skb,
6762 struct genl_info *info)
6763{
6764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6765 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006766 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006767 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006768 int err;
6769
6770 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6771 !rdev->ops->sched_scan_start)
6772 return -EOPNOTSUPP;
6773
6774 if (rdev->sched_scan_req)
6775 return -EINPROGRESS;
6776
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006777 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6778 info->attrs);
6779
6780 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006781 if (err)
6782 goto out_err;
6783
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006784 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006785 if (err)
6786 goto out_free;
6787
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006788 sched_scan_req->dev = dev;
6789 sched_scan_req->wiphy = &rdev->wiphy;
6790
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006791 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6792 sched_scan_req->owner_nlportid = info->snd_portid;
6793
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006794 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006795
6796 nl80211_send_sched_scan(rdev, dev,
6797 NL80211_CMD_START_SCHED_SCAN);
6798 return 0;
6799
6800out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006801 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006802out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006803 return err;
6804}
6805
6806static int nl80211_stop_sched_scan(struct sk_buff *skb,
6807 struct genl_info *info)
6808{
6809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6810
6811 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6812 !rdev->ops->sched_scan_stop)
6813 return -EOPNOTSUPP;
6814
Johannes Berg5fe231e2013-05-08 21:45:15 +02006815 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006816}
6817
Simon Wunderlich04f39042013-02-08 18:16:19 +01006818static int nl80211_start_radar_detection(struct sk_buff *skb,
6819 struct genl_info *info)
6820{
6821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6822 struct net_device *dev = info->user_ptr[1];
6823 struct wireless_dev *wdev = dev->ieee80211_ptr;
6824 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006825 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006826 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006827 int err;
6828
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006829 dfs_region = reg_get_dfs_region(wdev->wiphy);
6830 if (dfs_region == NL80211_DFS_UNSET)
6831 return -EINVAL;
6832
Simon Wunderlich04f39042013-02-08 18:16:19 +01006833 err = nl80211_parse_chandef(rdev, info, &chandef);
6834 if (err)
6835 return err;
6836
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006837 if (netif_carrier_ok(dev))
6838 return -EBUSY;
6839
Simon Wunderlich04f39042013-02-08 18:16:19 +01006840 if (wdev->cac_started)
6841 return -EBUSY;
6842
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006843 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006844 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006845 if (err < 0)
6846 return err;
6847
6848 if (err == 0)
6849 return -EINVAL;
6850
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006851 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006852 return -EINVAL;
6853
6854 if (!rdev->ops->start_radar_detection)
6855 return -EOPNOTSUPP;
6856
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006857 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6858 if (WARN_ON(!cac_time_ms))
6859 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6860
Ilan Peera1056b12015-10-22 22:27:46 +03006861 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006862 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006863 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006864 wdev->cac_started = true;
6865 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006866 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006867 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006868 return err;
6869}
6870
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006871static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6872{
6873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6874 struct net_device *dev = info->user_ptr[1];
6875 struct wireless_dev *wdev = dev->ieee80211_ptr;
6876 struct cfg80211_csa_settings params;
6877 /* csa_attrs is defined static to avoid waste of stack size - this
6878 * function is called under RTNL lock, so this should not be a problem.
6879 */
6880 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006881 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006882 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006883 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006884 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006885
6886 if (!rdev->ops->channel_switch ||
6887 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6888 return -EOPNOTSUPP;
6889
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006890 switch (dev->ieee80211_ptr->iftype) {
6891 case NL80211_IFTYPE_AP:
6892 case NL80211_IFTYPE_P2P_GO:
6893 need_new_beacon = true;
6894
6895 /* useless if AP is not running */
6896 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006897 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006898 break;
6899 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006900 if (!wdev->ssid_len)
6901 return -ENOTCONN;
6902 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006903 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006904 if (!wdev->mesh_id_len)
6905 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006906 break;
6907 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006908 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006909 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006910
6911 memset(&params, 0, sizeof(params));
6912
6913 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6914 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6915 return -EINVAL;
6916
6917 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006918 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006919 return -EINVAL;
6920
Luciano Coelho252e07c2014-10-08 09:48:34 +03006921 /* Even though the attribute is u32, the specification says
6922 * u8, so let's make sure we don't overflow.
6923 */
6924 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6925 if (cs_count > 255)
6926 return -EINVAL;
6927
6928 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006929
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006930 if (!need_new_beacon)
6931 goto skip_beacons;
6932
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006933 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6934 if (err)
6935 return err;
6936
6937 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6938 info->attrs[NL80211_ATTR_CSA_IES],
6939 nl80211_policy);
6940 if (err)
6941 return err;
6942
6943 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6944 if (err)
6945 return err;
6946
6947 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6948 return -EINVAL;
6949
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006950 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6951 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006952 return -EINVAL;
6953
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006954 params.n_counter_offsets_beacon = len / sizeof(u16);
6955 if (rdev->wiphy.max_num_csa_counters &&
6956 (params.n_counter_offsets_beacon >
6957 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006958 return -EINVAL;
6959
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006960 params.counter_offsets_beacon =
6961 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6962
6963 /* sanity checks - counters should fit and be the same */
6964 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6965 u16 offset = params.counter_offsets_beacon[i];
6966
6967 if (offset >= params.beacon_csa.tail_len)
6968 return -EINVAL;
6969
6970 if (params.beacon_csa.tail[offset] != params.count)
6971 return -EINVAL;
6972 }
6973
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006974 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006975 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6976 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006977 return -EINVAL;
6978
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006979 params.n_counter_offsets_presp = len / sizeof(u16);
6980 if (rdev->wiphy.max_num_csa_counters &&
6981 (params.n_counter_offsets_beacon >
6982 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006983 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006984
6985 params.counter_offsets_presp =
6986 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6987
6988 /* sanity checks - counters should fit and be the same */
6989 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6990 u16 offset = params.counter_offsets_presp[i];
6991
6992 if (offset >= params.beacon_csa.probe_resp_len)
6993 return -EINVAL;
6994
6995 if (params.beacon_csa.probe_resp[offset] !=
6996 params.count)
6997 return -EINVAL;
6998 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006999 }
7000
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007001skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007002 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7003 if (err)
7004 return err;
7005
Arik Nemtsov923b3522015-07-08 15:41:44 +03007006 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7007 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007008 return -EINVAL;
7009
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007010 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7011 &params.chandef,
7012 wdev->iftype);
7013 if (err < 0)
7014 return err;
7015
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007016 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007017 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007018
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007019 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7020 params.block_tx = true;
7021
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007022 wdev_lock(wdev);
7023 err = rdev_channel_switch(rdev, dev, &params);
7024 wdev_unlock(wdev);
7025
7026 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007027}
7028
Johannes Berg9720bb32011-06-21 09:45:33 +02007029static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7030 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007031 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007032 struct wireless_dev *wdev,
7033 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007034{
Johannes Berg48ab9052009-07-10 18:42:31 +02007035 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007036 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007037 void *hdr;
7038 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007039
7040 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007041
Eric W. Biederman15e47302012-09-07 20:12:54 +00007042 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007043 NL80211_CMD_NEW_SCAN_RESULTS);
7044 if (!hdr)
7045 return -1;
7046
Johannes Berg9720bb32011-06-21 09:45:33 +02007047 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7048
Johannes Berg97990a02013-04-19 01:02:55 +02007049 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7050 goto nla_put_failure;
7051 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007052 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7053 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007054 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7055 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007056 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007057
7058 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7059 if (!bss)
7060 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007061 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007062 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007063 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007064
7065 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007066 /* indicate whether we have probe response data or not */
7067 if (rcu_access_pointer(res->proberesp_ies) &&
7068 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7069 goto fail_unlock_rcu;
7070
7071 /* this pointer prefers to be pointed to probe response data
7072 * but is always valid
7073 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007074 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007075 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007076 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7077 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007078 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007079 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7080 ies->len, ies->data))
7081 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007082 }
Johannes Berg0e227082014-08-12 20:34:30 +02007083
7084 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007085 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007086 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007087 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7088 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007089 goto fail_unlock_rcu;
7090 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7091 ies->len, ies->data))
7092 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007093 }
7094 rcu_read_unlock();
7095
David S. Miller9360ffd2012-03-29 04:41:26 -04007096 if (res->beacon_interval &&
7097 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7098 goto nla_put_failure;
7099 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7100 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007101 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007102 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7103 jiffies_to_msecs(jiffies - intbss->ts)))
7104 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007105
Avraham Stern1d762502016-07-05 17:10:13 +03007106 if (intbss->parent_tsf &&
7107 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7108 intbss->parent_tsf, NL80211_BSS_PAD) ||
7109 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7110 intbss->parent_bssid)))
7111 goto nla_put_failure;
7112
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007113 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007114 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7115 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007116 goto nla_put_failure;
7117
Johannes Berg77965c92009-02-18 18:45:06 +01007118 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007119 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007120 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7121 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007122 break;
7123 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007124 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7125 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007126 break;
7127 default:
7128 break;
7129 }
7130
Johannes Berg48ab9052009-07-10 18:42:31 +02007131 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007132 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007133 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007134 if (intbss == wdev->current_bss &&
7135 nla_put_u32(msg, NL80211_BSS_STATUS,
7136 NL80211_BSS_STATUS_ASSOCIATED))
7137 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007138 break;
7139 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007140 if (intbss == wdev->current_bss &&
7141 nla_put_u32(msg, NL80211_BSS_STATUS,
7142 NL80211_BSS_STATUS_IBSS_JOINED))
7143 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007144 break;
7145 default:
7146 break;
7147 }
7148
Johannes Berg2a519312009-02-10 21:25:55 +01007149 nla_nest_end(msg, bss);
7150
Johannes Berg053c0952015-01-16 22:09:00 +01007151 genlmsg_end(msg, hdr);
7152 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007153
Johannes Berg8cef2c92013-02-05 16:54:31 +01007154 fail_unlock_rcu:
7155 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007156 nla_put_failure:
7157 genlmsg_cancel(msg, hdr);
7158 return -EMSGSIZE;
7159}
7160
Johannes Berg97990a02013-04-19 01:02:55 +02007161static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007162{
Johannes Berg48ab9052009-07-10 18:42:31 +02007163 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007164 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007165 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007166 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007167 int err;
7168
Johannes Berg97990a02013-04-19 01:02:55 +02007169 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007170 if (err)
7171 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007172
Johannes Berg48ab9052009-07-10 18:42:31 +02007173 wdev_lock(wdev);
7174 spin_lock_bh(&rdev->bss_lock);
7175 cfg80211_bss_expire(rdev);
7176
Johannes Berg9720bb32011-06-21 09:45:33 +02007177 cb->seq = rdev->bss_generation;
7178
Johannes Berg48ab9052009-07-10 18:42:31 +02007179 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007180 if (++idx <= start)
7181 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007182 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007183 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007184 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007185 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007186 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007187 }
7188 }
7189
Johannes Berg48ab9052009-07-10 18:42:31 +02007190 spin_unlock_bh(&rdev->bss_lock);
7191 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007192
Johannes Berg97990a02013-04-19 01:02:55 +02007193 cb->args[2] = idx;
7194 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007195
Johannes Berg67748892010-10-04 21:14:06 +02007196 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007197}
7198
Eric W. Biederman15e47302012-09-07 20:12:54 +00007199static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007200 int flags, struct net_device *dev,
7201 bool allow_radio_stats,
7202 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007203{
7204 void *hdr;
7205 struct nlattr *infoattr;
7206
Johannes Berg11f78ac2014-11-14 16:43:50 +01007207 /* skip radio stats if userspace didn't request them */
7208 if (!survey->channel && !allow_radio_stats)
7209 return 0;
7210
Eric W. Biederman15e47302012-09-07 20:12:54 +00007211 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007212 NL80211_CMD_NEW_SURVEY_RESULTS);
7213 if (!hdr)
7214 return -ENOMEM;
7215
David S. Miller9360ffd2012-03-29 04:41:26 -04007216 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7217 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007218
7219 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7220 if (!infoattr)
7221 goto nla_put_failure;
7222
Johannes Berg11f78ac2014-11-14 16:43:50 +01007223 if (survey->channel &&
7224 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007225 survey->channel->center_freq))
7226 goto nla_put_failure;
7227
7228 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7229 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7230 goto nla_put_failure;
7231 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7232 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7233 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007234 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007235 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7236 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007237 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007238 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007239 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7240 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007241 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007242 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007243 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7244 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007245 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007246 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007247 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7248 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007249 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007250 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007251 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7252 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007253 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007254 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007255 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7256 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007257 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007258
7259 nla_nest_end(msg, infoattr);
7260
Johannes Berg053c0952015-01-16 22:09:00 +01007261 genlmsg_end(msg, hdr);
7262 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007263
7264 nla_put_failure:
7265 genlmsg_cancel(msg, hdr);
7266 return -EMSGSIZE;
7267}
7268
Johannes Berg11f78ac2014-11-14 16:43:50 +01007269static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007270{
7271 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007272 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007273 struct wireless_dev *wdev;
7274 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007275 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007276 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007277
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007278 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007279 if (res)
7280 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007281
Johannes Berg11f78ac2014-11-14 16:43:50 +01007282 /* prepare_wdev_dump parsed the attributes */
7283 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7284
Johannes Berg97990a02013-04-19 01:02:55 +02007285 if (!wdev->netdev) {
7286 res = -EINVAL;
7287 goto out_err;
7288 }
7289
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007290 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007291 res = -EOPNOTSUPP;
7292 goto out_err;
7293 }
7294
7295 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007296 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007297 if (res == -ENOENT)
7298 break;
7299 if (res)
7300 goto out_err;
7301
Johannes Berg11f78ac2014-11-14 16:43:50 +01007302 /* don't send disabled channels, but do send non-channel data */
7303 if (survey.channel &&
7304 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007305 survey_idx++;
7306 continue;
7307 }
7308
Holger Schurig61fa7132009-11-11 12:25:40 +01007309 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007310 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007311 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007312 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007313 goto out;
7314 survey_idx++;
7315 }
7316
7317 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007318 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007319 res = skb->len;
7320 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007321 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007322 return res;
7323}
7324
Samuel Ortizb23aa672009-07-01 21:26:54 +02007325static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7326{
7327 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7328 NL80211_WPA_VERSION_2));
7329}
7330
Jouni Malinen636a5d32009-03-19 13:39:22 +02007331static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7332{
Johannes Berg4c476992010-10-04 21:36:35 +02007333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7334 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007335 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007336 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7337 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007338 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007339 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007340 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007341
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007342 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7343 return -EINVAL;
7344
7345 if (!info->attrs[NL80211_ATTR_MAC])
7346 return -EINVAL;
7347
Jouni Malinen17780922009-03-27 20:52:47 +02007348 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7349 return -EINVAL;
7350
Johannes Berg19957bb2009-07-02 17:20:43 +02007351 if (!info->attrs[NL80211_ATTR_SSID])
7352 return -EINVAL;
7353
7354 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7355 return -EINVAL;
7356
Johannes Bergfffd0932009-07-08 14:22:54 +02007357 err = nl80211_parse_key(info, &key);
7358 if (err)
7359 return err;
7360
7361 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007362 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7363 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007364 if (!key.p.key || !key.p.key_len)
7365 return -EINVAL;
7366 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7367 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7368 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7369 key.p.key_len != WLAN_KEY_LEN_WEP104))
7370 return -EINVAL;
7371 if (key.idx > 4)
7372 return -EINVAL;
7373 } else {
7374 key.p.key_len = 0;
7375 key.p.key = NULL;
7376 }
7377
Johannes Bergafea0b72010-08-10 09:46:42 +02007378 if (key.idx >= 0) {
7379 int i;
7380 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007381
Johannes Bergafea0b72010-08-10 09:46:42 +02007382 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7383 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7384 ok = true;
7385 break;
7386 }
7387 }
Johannes Berg4c476992010-10-04 21:36:35 +02007388 if (!ok)
7389 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007390 }
7391
Johannes Berg4c476992010-10-04 21:36:35 +02007392 if (!rdev->ops->auth)
7393 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007394
Johannes Berg074ac8d2010-09-16 14:58:22 +02007395 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007396 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7397 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007398
Johannes Berg19957bb2009-07-02 17:20:43 +02007399 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007400 chan = nl80211_get_valid_chan(&rdev->wiphy,
7401 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7402 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007403 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007404
Johannes Berg19957bb2009-07-02 17:20:43 +02007405 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7406 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7407
7408 if (info->attrs[NL80211_ATTR_IE]) {
7409 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7410 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7411 }
7412
7413 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007414 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007415 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007416
Jouni Malinene39e5b52012-09-30 19:29:39 +03007417 if (auth_type == NL80211_AUTHTYPE_SAE &&
7418 !info->attrs[NL80211_ATTR_SAE_DATA])
7419 return -EINVAL;
7420
7421 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7422 if (auth_type != NL80211_AUTHTYPE_SAE)
7423 return -EINVAL;
7424 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7425 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7426 /* need to include at least Auth Transaction and Status Code */
7427 if (sae_data_len < 4)
7428 return -EINVAL;
7429 }
7430
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007431 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7432
Johannes Berg95de8172012-01-20 13:55:25 +01007433 /*
7434 * Since we no longer track auth state, ignore
7435 * requests to only change local state.
7436 */
7437 if (local_state_change)
7438 return 0;
7439
Johannes Berg91bf9b22013-05-15 17:44:01 +02007440 wdev_lock(dev->ieee80211_ptr);
7441 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7442 ssid, ssid_len, ie, ie_len,
7443 key.p.key, key.p.key_len, key.idx,
7444 sae_data, sae_data_len);
7445 wdev_unlock(dev->ieee80211_ptr);
7446 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007447}
7448
Johannes Bergc0692b82010-08-27 14:26:53 +03007449static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7450 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007451 struct cfg80211_crypto_settings *settings,
7452 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007453{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007454 memset(settings, 0, sizeof(*settings));
7455
Samuel Ortizb23aa672009-07-01 21:26:54 +02007456 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7457
Johannes Bergc0692b82010-08-27 14:26:53 +03007458 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7459 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007460
Johannes Bergc0692b82010-08-27 14:26:53 +03007461 proto = nla_get_u16(
7462 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7463 settings->control_port_ethertype = cpu_to_be16(proto);
7464 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7465 proto != ETH_P_PAE)
7466 return -EINVAL;
7467 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7468 settings->control_port_no_encrypt = true;
7469 } else
7470 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7471
Samuel Ortizb23aa672009-07-01 21:26:54 +02007472 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7473 void *data;
7474 int len, i;
7475
7476 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7477 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7478 settings->n_ciphers_pairwise = len / sizeof(u32);
7479
7480 if (len % sizeof(u32))
7481 return -EINVAL;
7482
Johannes Berg3dc27d22009-07-02 21:36:37 +02007483 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007484 return -EINVAL;
7485
7486 memcpy(settings->ciphers_pairwise, data, len);
7487
7488 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007489 if (!cfg80211_supported_cipher_suite(
7490 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007491 settings->ciphers_pairwise[i]))
7492 return -EINVAL;
7493 }
7494
7495 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7496 settings->cipher_group =
7497 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007498 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7499 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007500 return -EINVAL;
7501 }
7502
7503 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7504 settings->wpa_versions =
7505 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7506 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7507 return -EINVAL;
7508 }
7509
7510 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7511 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007512 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007513
7514 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7515 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7516 settings->n_akm_suites = len / sizeof(u32);
7517
7518 if (len % sizeof(u32))
7519 return -EINVAL;
7520
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007521 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7522 return -EINVAL;
7523
Samuel Ortizb23aa672009-07-01 21:26:54 +02007524 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007525 }
7526
7527 return 0;
7528}
7529
Jouni Malinen636a5d32009-03-19 13:39:22 +02007530static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7531{
Johannes Berg4c476992010-10-04 21:36:35 +02007532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7533 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007534 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007535 struct cfg80211_assoc_request req = {};
7536 const u8 *bssid, *ssid;
7537 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007538
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007539 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7540 return -EINVAL;
7541
7542 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007543 !info->attrs[NL80211_ATTR_SSID] ||
7544 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007545 return -EINVAL;
7546
Johannes Berg4c476992010-10-04 21:36:35 +02007547 if (!rdev->ops->assoc)
7548 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007549
Johannes Berg074ac8d2010-09-16 14:58:22 +02007550 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007551 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7552 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007553
Johannes Berg19957bb2009-07-02 17:20:43 +02007554 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007555
Jouni Malinen664834d2014-01-15 00:01:44 +02007556 chan = nl80211_get_valid_chan(&rdev->wiphy,
7557 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7558 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007559 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007560
Johannes Berg19957bb2009-07-02 17:20:43 +02007561 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7562 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007563
7564 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007565 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7566 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007567 }
7568
Jouni Malinendc6382c2009-05-06 22:09:37 +03007569 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007570 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007571 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007572 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007573 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007574 else if (mfp != NL80211_MFP_NO)
7575 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007576 }
7577
Johannes Berg3e5d7642009-07-07 14:37:26 +02007578 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007579 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007580
Ben Greear7e7c8922011-11-18 11:31:59 -08007581 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007582 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007583
7584 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007585 memcpy(&req.ht_capa_mask,
7586 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7587 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007588
7589 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007590 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007591 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007592 memcpy(&req.ht_capa,
7593 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7594 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007595 }
7596
Johannes Bergee2aca32013-02-21 17:36:01 +01007597 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007598 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007599
7600 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007601 memcpy(&req.vht_capa_mask,
7602 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7603 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007604
7605 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007606 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007607 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007608 memcpy(&req.vht_capa,
7609 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7610 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007611 }
7612
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007613 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007614 if (!((rdev->wiphy.features &
7615 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7616 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7617 !wiphy_ext_feature_isset(&rdev->wiphy,
7618 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007619 return -EINVAL;
7620 req.flags |= ASSOC_REQ_USE_RRM;
7621 }
7622
Johannes Bergf62fab72013-02-21 20:09:09 +01007623 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007624 if (!err) {
7625 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007626 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7627 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007628 wdev_unlock(dev->ieee80211_ptr);
7629 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007630
Jouni Malinen636a5d32009-03-19 13:39:22 +02007631 return err;
7632}
7633
7634static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7635{
Johannes Berg4c476992010-10-04 21:36:35 +02007636 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7637 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007638 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007639 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007640 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007641 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007642
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007643 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7644 return -EINVAL;
7645
7646 if (!info->attrs[NL80211_ATTR_MAC])
7647 return -EINVAL;
7648
7649 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7650 return -EINVAL;
7651
Johannes Berg4c476992010-10-04 21:36:35 +02007652 if (!rdev->ops->deauth)
7653 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007654
Johannes Berg074ac8d2010-09-16 14:58:22 +02007655 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007656 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7657 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007658
Johannes Berg19957bb2009-07-02 17:20:43 +02007659 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007660
Johannes Berg19957bb2009-07-02 17:20:43 +02007661 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7662 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007663 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007664 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007665 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007666
7667 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007668 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7669 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007670 }
7671
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007672 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7673
Johannes Berg91bf9b22013-05-15 17:44:01 +02007674 wdev_lock(dev->ieee80211_ptr);
7675 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7676 local_state_change);
7677 wdev_unlock(dev->ieee80211_ptr);
7678 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007679}
7680
7681static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7682{
Johannes Berg4c476992010-10-04 21:36:35 +02007683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7684 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007685 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007686 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007687 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007688 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007689
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007690 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7691 return -EINVAL;
7692
7693 if (!info->attrs[NL80211_ATTR_MAC])
7694 return -EINVAL;
7695
7696 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7697 return -EINVAL;
7698
Johannes Berg4c476992010-10-04 21:36:35 +02007699 if (!rdev->ops->disassoc)
7700 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007701
Johannes Berg074ac8d2010-09-16 14:58:22 +02007702 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007703 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7704 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007705
Johannes Berg19957bb2009-07-02 17:20:43 +02007706 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007707
Johannes Berg19957bb2009-07-02 17:20:43 +02007708 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7709 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007710 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007711 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007712 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007713
7714 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007715 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7716 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007717 }
7718
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007719 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7720
Johannes Berg91bf9b22013-05-15 17:44:01 +02007721 wdev_lock(dev->ieee80211_ptr);
7722 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7723 local_state_change);
7724 wdev_unlock(dev->ieee80211_ptr);
7725 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007726}
7727
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007728static bool
7729nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007730 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007731 int rateval)
7732{
7733 struct wiphy *wiphy = &rdev->wiphy;
7734 bool found = false;
7735 int band, i;
7736
Johannes Berg57fbcce2016-04-12 15:56:15 +02007737 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007738 struct ieee80211_supported_band *sband;
7739
7740 sband = wiphy->bands[band];
7741 if (!sband)
7742 continue;
7743
7744 for (i = 0; i < sband->n_bitrates; i++) {
7745 if (sband->bitrates[i].bitrate == rateval) {
7746 mcast_rate[band] = i + 1;
7747 found = true;
7748 break;
7749 }
7750 }
7751 }
7752
7753 return found;
7754}
7755
Johannes Berg04a773a2009-04-19 21:24:32 +02007756static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7757{
Johannes Berg4c476992010-10-04 21:36:35 +02007758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7759 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007760 struct cfg80211_ibss_params ibss;
7761 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007762 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007763 int err;
7764
Johannes Berg8e30bc52009-04-22 17:45:38 +02007765 memset(&ibss, 0, sizeof(ibss));
7766
Johannes Berg04a773a2009-04-19 21:24:32 +02007767 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7768 return -EINVAL;
7769
Johannes Berg683b6d32012-11-08 21:25:48 +01007770 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007771 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7772 return -EINVAL;
7773
Johannes Berg8e30bc52009-04-22 17:45:38 +02007774 ibss.beacon_interval = 100;
7775
7776 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7777 ibss.beacon_interval =
7778 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7779 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7780 return -EINVAL;
7781 }
7782
Johannes Berg4c476992010-10-04 21:36:35 +02007783 if (!rdev->ops->join_ibss)
7784 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007785
Johannes Berg4c476992010-10-04 21:36:35 +02007786 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7787 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007788
Johannes Berg79c97e92009-07-07 03:56:12 +02007789 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007790
Johannes Berg39193492011-09-16 13:45:25 +02007791 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007792 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007793
7794 if (!is_valid_ether_addr(ibss.bssid))
7795 return -EINVAL;
7796 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007797 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7798 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7799
7800 if (info->attrs[NL80211_ATTR_IE]) {
7801 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7802 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7803 }
7804
Johannes Berg683b6d32012-11-08 21:25:48 +01007805 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7806 if (err)
7807 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007808
Ilan Peer174e0cd2014-02-23 09:13:01 +02007809 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7810 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007811 return -EINVAL;
7812
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007813 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007814 case NL80211_CHAN_WIDTH_5:
7815 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007816 case NL80211_CHAN_WIDTH_20_NOHT:
7817 break;
7818 case NL80211_CHAN_WIDTH_20:
7819 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007820 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7821 return -EINVAL;
7822 break;
7823 case NL80211_CHAN_WIDTH_80:
7824 case NL80211_CHAN_WIDTH_80P80:
7825 case NL80211_CHAN_WIDTH_160:
7826 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7827 return -EINVAL;
7828 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7829 NL80211_EXT_FEATURE_VHT_IBSS))
7830 return -EINVAL;
7831 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007832 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007833 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007834 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007835
Johannes Berg04a773a2009-04-19 21:24:32 +02007836 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007837 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007838
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007839 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7840 u8 *rates =
7841 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7842 int n_rates =
7843 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7844 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007845 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007846
Johannes Berg34850ab2011-07-18 18:08:35 +02007847 err = ieee80211_get_ratemask(sband, rates, n_rates,
7848 &ibss.basic_rates);
7849 if (err)
7850 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007851 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007852
Simon Wunderlich803768f2013-06-28 10:39:58 +02007853 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7854 memcpy(&ibss.ht_capa_mask,
7855 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7856 sizeof(ibss.ht_capa_mask));
7857
7858 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7859 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7860 return -EINVAL;
7861 memcpy(&ibss.ht_capa,
7862 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7863 sizeof(ibss.ht_capa));
7864 }
7865
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007866 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7867 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7868 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7869 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007870
Johannes Berg4c476992010-10-04 21:36:35 +02007871 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307872 bool no_ht = false;
7873
Johannes Berg4c476992010-10-04 21:36:35 +02007874 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307875 info->attrs[NL80211_ATTR_KEYS],
7876 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007877 if (IS_ERR(connkeys))
7878 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307879
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007880 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7881 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007882 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307883 return -EINVAL;
7884 }
Johannes Berg4c476992010-10-04 21:36:35 +02007885 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007886
Antonio Quartulli267335d2012-01-31 20:25:47 +01007887 ibss.control_port =
7888 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7889
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007890 ibss.userspace_handles_dfs =
7891 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7892
Johannes Berg4c476992010-10-04 21:36:35 +02007893 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007894 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007895 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007896 return err;
7897}
7898
7899static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7900{
Johannes Berg4c476992010-10-04 21:36:35 +02007901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7902 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007903
Johannes Berg4c476992010-10-04 21:36:35 +02007904 if (!rdev->ops->leave_ibss)
7905 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007906
Johannes Berg4c476992010-10-04 21:36:35 +02007907 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7908 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007909
Johannes Berg4c476992010-10-04 21:36:35 +02007910 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007911}
7912
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007913static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7914{
7915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7916 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007917 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007918 u32 nla_rate;
7919 int err;
7920
7921 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007922 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7923 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007924 return -EOPNOTSUPP;
7925
7926 if (!rdev->ops->set_mcast_rate)
7927 return -EOPNOTSUPP;
7928
7929 memset(mcast_rate, 0, sizeof(mcast_rate));
7930
7931 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7932 return -EINVAL;
7933
7934 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7935 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7936 return -EINVAL;
7937
Ilan Peera1056b12015-10-22 22:27:46 +03007938 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007939
7940 return err;
7941}
7942
Johannes Bergad7e7182013-11-13 13:37:47 +01007943static struct sk_buff *
7944__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007945 struct wireless_dev *wdev, int approxlen,
7946 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007947 enum nl80211_attrs attr,
7948 const struct nl80211_vendor_cmd_info *info,
7949 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007950{
7951 struct sk_buff *skb;
7952 void *hdr;
7953 struct nlattr *data;
7954
7955 skb = nlmsg_new(approxlen + 100, gfp);
7956 if (!skb)
7957 return NULL;
7958
7959 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7960 if (!hdr) {
7961 kfree_skb(skb);
7962 return NULL;
7963 }
7964
7965 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7966 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007967
7968 if (info) {
7969 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7970 info->vendor_id))
7971 goto nla_put_failure;
7972 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7973 info->subcmd))
7974 goto nla_put_failure;
7975 }
7976
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007977 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007978 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7979 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007980 goto nla_put_failure;
7981 if (wdev->netdev &&
7982 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7983 wdev->netdev->ifindex))
7984 goto nla_put_failure;
7985 }
7986
Johannes Bergad7e7182013-11-13 13:37:47 +01007987 data = nla_nest_start(skb, attr);
7988
7989 ((void **)skb->cb)[0] = rdev;
7990 ((void **)skb->cb)[1] = hdr;
7991 ((void **)skb->cb)[2] = data;
7992
7993 return skb;
7994
7995 nla_put_failure:
7996 kfree_skb(skb);
7997 return NULL;
7998}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007999
Johannes Berge03ad6e2014-01-01 17:22:30 +01008000struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008001 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008002 enum nl80211_commands cmd,
8003 enum nl80211_attrs attr,
8004 int vendor_event_idx,
8005 int approxlen, gfp_t gfp)
8006{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008007 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008008 const struct nl80211_vendor_cmd_info *info;
8009
8010 switch (cmd) {
8011 case NL80211_CMD_TESTMODE:
8012 if (WARN_ON(vendor_event_idx != -1))
8013 return NULL;
8014 info = NULL;
8015 break;
8016 case NL80211_CMD_VENDOR:
8017 if (WARN_ON(vendor_event_idx < 0 ||
8018 vendor_event_idx >= wiphy->n_vendor_events))
8019 return NULL;
8020 info = &wiphy->vendor_events[vendor_event_idx];
8021 break;
8022 default:
8023 WARN_ON(1);
8024 return NULL;
8025 }
8026
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008027 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008028 cmd, attr, info, gfp);
8029}
8030EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8031
8032void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8033{
8034 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8035 void *hdr = ((void **)skb->cb)[1];
8036 struct nlattr *data = ((void **)skb->cb)[2];
8037 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8038
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008039 /* clear CB data for netlink core to own from now on */
8040 memset(skb->cb, 0, sizeof(skb->cb));
8041
Johannes Berge03ad6e2014-01-01 17:22:30 +01008042 nla_nest_end(skb, data);
8043 genlmsg_end(skb, hdr);
8044
8045 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8046 mcgrp = NL80211_MCGRP_VENDOR;
8047
8048 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8049 mcgrp, gfp);
8050}
8051EXPORT_SYMBOL(__cfg80211_send_event_skb);
8052
Johannes Bergaff89a92009-07-01 21:26:51 +02008053#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008054static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8055{
Johannes Berg4c476992010-10-04 21:36:35 +02008056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008057 struct wireless_dev *wdev =
8058 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008059 int err;
8060
David Spinadelfc73f112013-07-31 18:04:15 +03008061 if (!rdev->ops->testmode_cmd)
8062 return -EOPNOTSUPP;
8063
8064 if (IS_ERR(wdev)) {
8065 err = PTR_ERR(wdev);
8066 if (err != -EINVAL)
8067 return err;
8068 wdev = NULL;
8069 } else if (wdev->wiphy != &rdev->wiphy) {
8070 return -EINVAL;
8071 }
8072
Johannes Bergaff89a92009-07-01 21:26:51 +02008073 if (!info->attrs[NL80211_ATTR_TESTDATA])
8074 return -EINVAL;
8075
Johannes Bergad7e7182013-11-13 13:37:47 +01008076 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008077 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008078 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8079 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008080 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008081
Johannes Bergaff89a92009-07-01 21:26:51 +02008082 return err;
8083}
8084
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008085static int nl80211_testmode_dump(struct sk_buff *skb,
8086 struct netlink_callback *cb)
8087{
Johannes Berg00918d32011-12-13 17:22:05 +01008088 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008089 int err;
8090 long phy_idx;
8091 void *data = NULL;
8092 int data_len = 0;
8093
Johannes Berg5fe231e2013-05-08 21:45:15 +02008094 rtnl_lock();
8095
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008096 if (cb->args[0]) {
8097 /*
8098 * 0 is a valid index, but not valid for args[0],
8099 * so we need to offset by 1.
8100 */
8101 phy_idx = cb->args[0] - 1;
8102 } else {
8103 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8104 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8105 nl80211_policy);
8106 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008107 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008108
Johannes Berg2bd7e352012-06-15 14:23:16 +02008109 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8110 nl80211_fam.attrbuf);
8111 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008112 err = PTR_ERR(rdev);
8113 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008114 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008115 phy_idx = rdev->wiphy_idx;
8116 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008117
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008118 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8119 cb->args[1] =
8120 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8121 }
8122
8123 if (cb->args[1]) {
8124 data = nla_data((void *)cb->args[1]);
8125 data_len = nla_len((void *)cb->args[1]);
8126 }
8127
Johannes Berg00918d32011-12-13 17:22:05 +01008128 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8129 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008130 err = -ENOENT;
8131 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008132 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008133
Johannes Berg00918d32011-12-13 17:22:05 +01008134 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008135 err = -EOPNOTSUPP;
8136 goto out_err;
8137 }
8138
8139 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008140 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008141 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8142 NL80211_CMD_TESTMODE);
8143 struct nlattr *tmdata;
8144
Dan Carpentercb35fba2013-08-14 14:50:01 +03008145 if (!hdr)
8146 break;
8147
David S. Miller9360ffd2012-03-29 04:41:26 -04008148 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008149 genlmsg_cancel(skb, hdr);
8150 break;
8151 }
8152
8153 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8154 if (!tmdata) {
8155 genlmsg_cancel(skb, hdr);
8156 break;
8157 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008158 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008159 nla_nest_end(skb, tmdata);
8160
8161 if (err == -ENOBUFS || err == -ENOENT) {
8162 genlmsg_cancel(skb, hdr);
8163 break;
8164 } else if (err) {
8165 genlmsg_cancel(skb, hdr);
8166 goto out_err;
8167 }
8168
8169 genlmsg_end(skb, hdr);
8170 }
8171
8172 err = skb->len;
8173 /* see above */
8174 cb->args[0] = phy_idx + 1;
8175 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008176 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008177 return err;
8178}
Johannes Bergaff89a92009-07-01 21:26:51 +02008179#endif
8180
Samuel Ortizb23aa672009-07-01 21:26:54 +02008181static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8182{
Johannes Berg4c476992010-10-04 21:36:35 +02008183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8184 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008185 struct cfg80211_connect_params connect;
8186 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008187 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008188 int err;
8189
8190 memset(&connect, 0, sizeof(connect));
8191
8192 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8193 return -EINVAL;
8194
8195 if (!info->attrs[NL80211_ATTR_SSID] ||
8196 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8197 return -EINVAL;
8198
8199 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8200 connect.auth_type =
8201 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008202 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8203 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008204 return -EINVAL;
8205 } else
8206 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8207
8208 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8209
Johannes Bergc0692b82010-08-27 14:26:53 +03008210 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008211 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008212 if (err)
8213 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008214
Johannes Berg074ac8d2010-09-16 14:58:22 +02008215 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008216 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8217 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008218
Johannes Berg79c97e92009-07-07 03:56:12 +02008219 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008220
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308221 connect.bg_scan_period = -1;
8222 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8223 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8224 connect.bg_scan_period =
8225 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8226 }
8227
Samuel Ortizb23aa672009-07-01 21:26:54 +02008228 if (info->attrs[NL80211_ATTR_MAC])
8229 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008230 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8231 connect.bssid_hint =
8232 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008233 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8234 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8235
8236 if (info->attrs[NL80211_ATTR_IE]) {
8237 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8238 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8239 }
8240
Jouni Malinencee00a92013-01-15 17:15:57 +02008241 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8242 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8243 if (connect.mfp != NL80211_MFP_REQUIRED &&
8244 connect.mfp != NL80211_MFP_NO)
8245 return -EINVAL;
8246 } else {
8247 connect.mfp = NL80211_MFP_NO;
8248 }
8249
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008250 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8251 connect.prev_bssid =
8252 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8253
Samuel Ortizb23aa672009-07-01 21:26:54 +02008254 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008255 connect.channel = nl80211_get_valid_chan(
8256 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8257 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008258 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008259 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008260 connect.channel_hint = nl80211_get_valid_chan(
8261 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8262 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008263 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008264 }
8265
Johannes Bergfffd0932009-07-08 14:22:54 +02008266 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8267 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308268 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008269 if (IS_ERR(connkeys))
8270 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008271 }
8272
Ben Greear7e7c8922011-11-18 11:31:59 -08008273 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8274 connect.flags |= ASSOC_REQ_DISABLE_HT;
8275
8276 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8277 memcpy(&connect.ht_capa_mask,
8278 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8279 sizeof(connect.ht_capa_mask));
8280
8281 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008282 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008283 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008284 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008285 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008286 memcpy(&connect.ht_capa,
8287 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8288 sizeof(connect.ht_capa));
8289 }
8290
Johannes Bergee2aca32013-02-21 17:36:01 +01008291 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8292 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8293
8294 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8295 memcpy(&connect.vht_capa_mask,
8296 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8297 sizeof(connect.vht_capa_mask));
8298
8299 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8300 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008301 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008302 return -EINVAL;
8303 }
8304 memcpy(&connect.vht_capa,
8305 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8306 sizeof(connect.vht_capa));
8307 }
8308
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008309 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008310 if (!((rdev->wiphy.features &
8311 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8312 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8313 !wiphy_ext_feature_isset(&rdev->wiphy,
8314 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008315 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008316 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008317 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008318 connect.flags |= ASSOC_REQ_USE_RRM;
8319 }
8320
Lior David34d50512016-01-28 10:58:25 +02008321 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008322 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008323 kzfree(connkeys);
8324 return -EOPNOTSUPP;
8325 }
8326
Arend van Spriel38de03d2016-03-02 20:37:18 +01008327 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8328 /* bss selection makes no sense if bssid is set */
8329 if (connect.bssid) {
8330 kzfree(connkeys);
8331 return -EINVAL;
8332 }
8333
8334 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8335 wiphy, &connect.bss_select);
8336 if (err) {
8337 kzfree(connkeys);
8338 return err;
8339 }
8340 }
8341
Johannes Berg83739b02013-05-15 17:44:01 +02008342 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008343 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8344 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008345 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008346 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008347 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008348 return err;
8349}
8350
8351static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8352{
Johannes Berg4c476992010-10-04 21:36:35 +02008353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8354 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008355 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008356 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008357
8358 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8359 reason = WLAN_REASON_DEAUTH_LEAVING;
8360 else
8361 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8362
8363 if (reason == 0)
8364 return -EINVAL;
8365
Johannes Berg074ac8d2010-09-16 14:58:22 +02008366 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008367 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8368 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008369
Johannes Berg83739b02013-05-15 17:44:01 +02008370 wdev_lock(dev->ieee80211_ptr);
8371 ret = cfg80211_disconnect(rdev, dev, reason, true);
8372 wdev_unlock(dev->ieee80211_ptr);
8373 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008374}
8375
Johannes Berg463d0182009-07-14 00:33:35 +02008376static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8377{
Johannes Berg4c476992010-10-04 21:36:35 +02008378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008379 struct net *net;
8380 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008381
Vadim Kochan4b681c82015-01-12 16:34:05 +02008382 if (info->attrs[NL80211_ATTR_PID]) {
8383 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8384
8385 net = get_net_ns_by_pid(pid);
8386 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8387 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8388
8389 net = get_net_ns_by_fd(fd);
8390 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008391 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008392 }
Johannes Berg463d0182009-07-14 00:33:35 +02008393
Johannes Berg4c476992010-10-04 21:36:35 +02008394 if (IS_ERR(net))
8395 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008396
8397 err = 0;
8398
8399 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008400 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8401 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008402
Johannes Berg463d0182009-07-14 00:33:35 +02008403 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008404 return err;
8405}
8406
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008407static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8408{
Johannes Berg4c476992010-10-04 21:36:35 +02008409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008410 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8411 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008412 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008413 struct cfg80211_pmksa pmksa;
8414
8415 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8416
8417 if (!info->attrs[NL80211_ATTR_MAC])
8418 return -EINVAL;
8419
8420 if (!info->attrs[NL80211_ATTR_PMKID])
8421 return -EINVAL;
8422
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008423 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8424 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8425
Johannes Berg074ac8d2010-09-16 14:58:22 +02008426 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008427 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8428 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008429
8430 switch (info->genlhdr->cmd) {
8431 case NL80211_CMD_SET_PMKSA:
8432 rdev_ops = rdev->ops->set_pmksa;
8433 break;
8434 case NL80211_CMD_DEL_PMKSA:
8435 rdev_ops = rdev->ops->del_pmksa;
8436 break;
8437 default:
8438 WARN_ON(1);
8439 break;
8440 }
8441
Johannes Berg4c476992010-10-04 21:36:35 +02008442 if (!rdev_ops)
8443 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008444
Johannes Berg4c476992010-10-04 21:36:35 +02008445 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008446}
8447
8448static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8449{
Johannes Berg4c476992010-10-04 21:36:35 +02008450 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8451 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008452
Johannes Berg074ac8d2010-09-16 14:58:22 +02008453 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008454 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8455 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008456
Johannes Berg4c476992010-10-04 21:36:35 +02008457 if (!rdev->ops->flush_pmksa)
8458 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008459
Hila Gonene35e4d22012-06-27 17:19:42 +03008460 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008461}
8462
Arik Nemtsov109086c2011-09-28 14:12:50 +03008463static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8464{
8465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8466 struct net_device *dev = info->user_ptr[1];
8467 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308468 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008469 u16 status_code;
8470 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008471 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008472
8473 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8474 !rdev->ops->tdls_mgmt)
8475 return -EOPNOTSUPP;
8476
8477 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8478 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8479 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8480 !info->attrs[NL80211_ATTR_IE] ||
8481 !info->attrs[NL80211_ATTR_MAC])
8482 return -EINVAL;
8483
8484 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8485 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8486 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8487 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008488 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308489 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8490 peer_capability =
8491 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008492
Hila Gonene35e4d22012-06-27 17:19:42 +03008493 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308494 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008495 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008496 nla_data(info->attrs[NL80211_ATTR_IE]),
8497 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008498}
8499
8500static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8501{
8502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8503 struct net_device *dev = info->user_ptr[1];
8504 enum nl80211_tdls_operation operation;
8505 u8 *peer;
8506
8507 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8508 !rdev->ops->tdls_oper)
8509 return -EOPNOTSUPP;
8510
8511 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8512 !info->attrs[NL80211_ATTR_MAC])
8513 return -EINVAL;
8514
8515 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8516 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8517
Hila Gonene35e4d22012-06-27 17:19:42 +03008518 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008519}
8520
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008521static int nl80211_remain_on_channel(struct sk_buff *skb,
8522 struct genl_info *info)
8523{
Johannes Berg4c476992010-10-04 21:36:35 +02008524 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008525 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008526 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008527 struct sk_buff *msg;
8528 void *hdr;
8529 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008530 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008531 int err;
8532
8533 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8534 !info->attrs[NL80211_ATTR_DURATION])
8535 return -EINVAL;
8536
8537 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8538
Johannes Berg7c4ef712011-11-18 15:33:48 +01008539 if (!rdev->ops->remain_on_channel ||
8540 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008541 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008542
Johannes Bergebf348f2012-06-01 12:50:54 +02008543 /*
8544 * We should be on that channel for at least a minimum amount of
8545 * time (10ms) but no longer than the driver supports.
8546 */
8547 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8548 duration > rdev->wiphy.max_remain_on_channel_duration)
8549 return -EINVAL;
8550
Johannes Berg683b6d32012-11-08 21:25:48 +01008551 err = nl80211_parse_chandef(rdev, info, &chandef);
8552 if (err)
8553 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008554
8555 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008556 if (!msg)
8557 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008558
Eric W. Biederman15e47302012-09-07 20:12:54 +00008559 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008560 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008561 if (!hdr) {
8562 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008563 goto free_msg;
8564 }
8565
Johannes Berg683b6d32012-11-08 21:25:48 +01008566 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8567 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008568
8569 if (err)
8570 goto free_msg;
8571
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008572 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8573 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008574 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008575
8576 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008577
8578 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008579
8580 nla_put_failure:
8581 err = -ENOBUFS;
8582 free_msg:
8583 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008584 return err;
8585}
8586
8587static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8588 struct genl_info *info)
8589{
Johannes Berg4c476992010-10-04 21:36:35 +02008590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008591 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008592 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008593
8594 if (!info->attrs[NL80211_ATTR_COOKIE])
8595 return -EINVAL;
8596
Johannes Berg4c476992010-10-04 21:36:35 +02008597 if (!rdev->ops->cancel_remain_on_channel)
8598 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008599
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008600 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8601
Hila Gonene35e4d22012-06-27 17:19:42 +03008602 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008603}
8604
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008605static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8606 u8 *rates, u8 rates_len)
8607{
8608 u8 i;
8609 u32 mask = 0;
8610
8611 for (i = 0; i < rates_len; i++) {
8612 int rate = (rates[i] & 0x7f) * 5;
8613 int ridx;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008614
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008615 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8616 struct ieee80211_rate *srate =
8617 &sband->bitrates[ridx];
8618 if (rate == srate->bitrate) {
8619 mask |= 1 << ridx;
8620 break;
8621 }
8622 }
8623 if (ridx == sband->n_bitrates)
8624 return 0; /* rate not found */
8625 }
8626
8627 return mask;
8628}
8629
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008630static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8631 u8 *rates, u8 rates_len,
8632 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8633{
8634 u8 i;
8635
8636 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8637
8638 for (i = 0; i < rates_len; i++) {
8639 int ridx, rbit;
8640
8641 ridx = rates[i] / 8;
8642 rbit = BIT(rates[i] % 8);
8643
8644 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008645 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008646 return false;
8647
8648 /* check availability */
8649 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8650 mcs[ridx] |= rbit;
8651 else
8652 return false;
8653 }
8654
8655 return true;
8656}
8657
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008658static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8659{
8660 u16 mcs_mask = 0;
8661
8662 switch (vht_mcs_map) {
8663 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8664 break;
8665 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8666 mcs_mask = 0x00FF;
8667 break;
8668 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8669 mcs_mask = 0x01FF;
8670 break;
8671 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8672 mcs_mask = 0x03FF;
8673 break;
8674 default:
8675 break;
8676 }
8677
8678 return mcs_mask;
8679}
8680
8681static void vht_build_mcs_mask(u16 vht_mcs_map,
8682 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8683{
8684 u8 nss;
8685
8686 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8687 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8688 vht_mcs_map >>= 2;
8689 }
8690}
8691
8692static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8693 struct nl80211_txrate_vht *txrate,
8694 u16 mcs[NL80211_VHT_NSS_MAX])
8695{
8696 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8697 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8698 u8 i;
8699
8700 if (!sband->vht_cap.vht_supported)
8701 return false;
8702
8703 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8704
8705 /* Build vht_mcs_mask from VHT capabilities */
8706 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8707
8708 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8709 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8710 mcs[i] = txrate->mcs[i];
8711 else
8712 return false;
8713 }
8714
8715 return true;
8716}
8717
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008718static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008719 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8720 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008721 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8722 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008723 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008724 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008725};
8726
8727static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8728 struct genl_info *info)
8729{
8730 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008732 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008733 int rem, i;
8734 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008735 struct nlattr *tx_rates;
8736 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008737 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008738
Johannes Berg4c476992010-10-04 21:36:35 +02008739 if (!rdev->ops->set_bitrate_mask)
8740 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008741
8742 memset(&mask, 0, sizeof(mask));
8743 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008744 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008745 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008746
8747 if (!sband)
8748 continue;
8749
8750 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008751 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008752 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008753 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008754
8755 if (!sband->vht_cap.vht_supported)
8756 continue;
8757
8758 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8759 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008760 }
8761
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008762 /* if no rates are given set it back to the defaults */
8763 if (!info->attrs[NL80211_ATTR_TX_RATES])
8764 goto out;
8765
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008766 /*
8767 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008768 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008769 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008770 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008771 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008772 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008773 int err;
8774
Johannes Berg57fbcce2016-04-12 15:56:15 +02008775 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008776 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008777 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008778 if (sband == NULL)
8779 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008780 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8781 nla_len(tx_rates), nl80211_txattr_policy);
8782 if (err)
8783 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008784 if (tb[NL80211_TXRATE_LEGACY]) {
8785 mask.control[band].legacy = rateset_to_mask(
8786 sband,
8787 nla_data(tb[NL80211_TXRATE_LEGACY]),
8788 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308789 if ((mask.control[band].legacy == 0) &&
8790 nla_len(tb[NL80211_TXRATE_LEGACY]))
8791 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008792 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008793 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008794 if (!ht_rateset_to_mask(
8795 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008796 nla_data(tb[NL80211_TXRATE_HT]),
8797 nla_len(tb[NL80211_TXRATE_HT]),
8798 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008799 return -EINVAL;
8800 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008801 if (tb[NL80211_TXRATE_VHT]) {
8802 if (!vht_set_mcs_mask(
8803 sband,
8804 nla_data(tb[NL80211_TXRATE_VHT]),
8805 mask.control[band].vht_mcs))
8806 return -EINVAL;
8807 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008808 if (tb[NL80211_TXRATE_GI]) {
8809 mask.control[band].gi =
8810 nla_get_u8(tb[NL80211_TXRATE_GI]);
8811 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8812 return -EINVAL;
8813 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008814
8815 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008816 /* don't allow empty legacy rates if HT or VHT
8817 * are not even supported.
8818 */
8819 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8820 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008821 return -EINVAL;
8822
8823 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008824 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008825 goto out;
8826
8827 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8828 if (mask.control[band].vht_mcs[i])
8829 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008830
8831 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008832 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008833 }
8834 }
8835
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008836out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008837 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008838}
8839
Johannes Berg2e161f72010-08-12 15:38:38 +02008840static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008841{
Johannes Berg4c476992010-10-04 21:36:35 +02008842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008843 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008844 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008845
8846 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8847 return -EINVAL;
8848
Johannes Berg2e161f72010-08-12 15:38:38 +02008849 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8850 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008851
Johannes Berg71bbc992012-06-15 15:30:18 +02008852 switch (wdev->iftype) {
8853 case NL80211_IFTYPE_STATION:
8854 case NL80211_IFTYPE_ADHOC:
8855 case NL80211_IFTYPE_P2P_CLIENT:
8856 case NL80211_IFTYPE_AP:
8857 case NL80211_IFTYPE_AP_VLAN:
8858 case NL80211_IFTYPE_MESH_POINT:
8859 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008860 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008861 break;
8862 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008863 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008864 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008865
8866 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008867 if (!rdev->ops->mgmt_tx)
8868 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008869
Eric W. Biederman15e47302012-09-07 20:12:54 +00008870 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008871 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8872 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008873}
8874
Johannes Berg2e161f72010-08-12 15:38:38 +02008875static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008876{
Johannes Berg4c476992010-10-04 21:36:35 +02008877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008878 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008879 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008880 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008881 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008882 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008883 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008884 struct cfg80211_mgmt_tx_params params = {
8885 .dont_wait_for_ack =
8886 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8887 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008888
Johannes Berg683b6d32012-11-08 21:25:48 +01008889 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008890 return -EINVAL;
8891
Johannes Berg4c476992010-10-04 21:36:35 +02008892 if (!rdev->ops->mgmt_tx)
8893 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008894
Johannes Berg71bbc992012-06-15 15:30:18 +02008895 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008896 case NL80211_IFTYPE_P2P_DEVICE:
8897 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8898 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008899 case NL80211_IFTYPE_STATION:
8900 case NL80211_IFTYPE_ADHOC:
8901 case NL80211_IFTYPE_P2P_CLIENT:
8902 case NL80211_IFTYPE_AP:
8903 case NL80211_IFTYPE_AP_VLAN:
8904 case NL80211_IFTYPE_MESH_POINT:
8905 case NL80211_IFTYPE_P2P_GO:
8906 break;
8907 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008908 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008909 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008910
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008911 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008912 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008913 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008914 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008915
8916 /*
8917 * We should wait on the channel for at least a minimum amount
8918 * of time (10ms) but no longer than the driver supports.
8919 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008920 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8921 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008922 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008923 }
8924
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008925 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008926
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008927 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008928 return -EINVAL;
8929
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008930 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308931
Antonio Quartulliea141b752013-06-11 14:20:03 +02008932 /* get the channel if any has been specified, otherwise pass NULL to
8933 * the driver. The latter will use the current one
8934 */
8935 chandef.chan = NULL;
8936 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8937 err = nl80211_parse_chandef(rdev, info, &chandef);
8938 if (err)
8939 return err;
8940 }
8941
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008942 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008943 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008944
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008945 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8946 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8947
8948 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8949 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8950 int i;
8951
8952 if (len % sizeof(u16))
8953 return -EINVAL;
8954
8955 params.n_csa_offsets = len / sizeof(u16);
8956 params.csa_offsets =
8957 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8958
8959 /* check that all the offsets fit the frame */
8960 for (i = 0; i < params.n_csa_offsets; i++) {
8961 if (params.csa_offsets[i] >= params.len)
8962 return -EINVAL;
8963 }
8964 }
8965
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008966 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008967 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8968 if (!msg)
8969 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008970
Eric W. Biederman15e47302012-09-07 20:12:54 +00008971 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008972 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008973 if (!hdr) {
8974 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008975 goto free_msg;
8976 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008977 }
Johannes Berge247bd902011-11-04 11:18:21 +01008978
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008979 params.chan = chandef.chan;
8980 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008981 if (err)
8982 goto free_msg;
8983
Johannes Berge247bd902011-11-04 11:18:21 +01008984 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008985 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8986 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008987 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008988
Johannes Berge247bd902011-11-04 11:18:21 +01008989 genlmsg_end(msg, hdr);
8990 return genlmsg_reply(msg, info);
8991 }
8992
8993 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008994
8995 nla_put_failure:
8996 err = -ENOBUFS;
8997 free_msg:
8998 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008999 return err;
9000}
9001
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009002static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9003{
9004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009005 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009006 u64 cookie;
9007
9008 if (!info->attrs[NL80211_ATTR_COOKIE])
9009 return -EINVAL;
9010
9011 if (!rdev->ops->mgmt_tx_cancel_wait)
9012 return -EOPNOTSUPP;
9013
Johannes Berg71bbc992012-06-15 15:30:18 +02009014 switch (wdev->iftype) {
9015 case NL80211_IFTYPE_STATION:
9016 case NL80211_IFTYPE_ADHOC:
9017 case NL80211_IFTYPE_P2P_CLIENT:
9018 case NL80211_IFTYPE_AP:
9019 case NL80211_IFTYPE_AP_VLAN:
9020 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009021 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009022 break;
9023 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009024 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009025 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009026
9027 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9028
Hila Gonene35e4d22012-06-27 17:19:42 +03009029 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009030}
9031
Kalle Valoffb9eb32010-02-17 17:58:10 +02009032static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9033{
Johannes Berg4c476992010-10-04 21:36:35 +02009034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009035 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009036 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009037 u8 ps_state;
9038 bool state;
9039 int err;
9040
Johannes Berg4c476992010-10-04 21:36:35 +02009041 if (!info->attrs[NL80211_ATTR_PS_STATE])
9042 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009043
9044 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9045
Johannes Berg4c476992010-10-04 21:36:35 +02009046 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9047 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009048
9049 wdev = dev->ieee80211_ptr;
9050
Johannes Berg4c476992010-10-04 21:36:35 +02009051 if (!rdev->ops->set_power_mgmt)
9052 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009053
9054 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9055
9056 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009057 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009058
Hila Gonene35e4d22012-06-27 17:19:42 +03009059 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009060 if (!err)
9061 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009062 return err;
9063}
9064
9065static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9066{
Johannes Berg4c476992010-10-04 21:36:35 +02009067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009068 enum nl80211_ps_state ps_state;
9069 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009070 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009071 struct sk_buff *msg;
9072 void *hdr;
9073 int err;
9074
Kalle Valoffb9eb32010-02-17 17:58:10 +02009075 wdev = dev->ieee80211_ptr;
9076
Johannes Berg4c476992010-10-04 21:36:35 +02009077 if (!rdev->ops->set_power_mgmt)
9078 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009079
9080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009081 if (!msg)
9082 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009083
Eric W. Biederman15e47302012-09-07 20:12:54 +00009084 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009085 NL80211_CMD_GET_POWER_SAVE);
9086 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009087 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009088 goto free_msg;
9089 }
9090
9091 if (wdev->ps)
9092 ps_state = NL80211_PS_ENABLED;
9093 else
9094 ps_state = NL80211_PS_DISABLED;
9095
David S. Miller9360ffd2012-03-29 04:41:26 -04009096 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9097 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009098
9099 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009100 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009101
Johannes Berg4c476992010-10-04 21:36:35 +02009102 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009103 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009104 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009105 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009106 return err;
9107}
9108
Johannes Berg94e860f2014-01-20 23:58:15 +01009109static const struct nla_policy
9110nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009111 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9112 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9113 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009114 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9115 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9116 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009117};
9118
Thomas Pedersen84f10702012-07-12 16:17:33 -07009119static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009120 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009121{
9122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009123 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009124 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009125
Johannes Bergd9d8b012012-11-26 12:51:52 +01009126 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009127 return -EINVAL;
9128
Thomas Pedersen84f10702012-07-12 16:17:33 -07009129 if (!rdev->ops->set_cqm_txe_config)
9130 return -EOPNOTSUPP;
9131
9132 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9133 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9134 return -EOPNOTSUPP;
9135
Hila Gonene35e4d22012-06-27 17:19:42 +03009136 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009137}
9138
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009139static int nl80211_set_cqm_rssi(struct genl_info *info,
9140 s32 threshold, u32 hysteresis)
9141{
Johannes Berg4c476992010-10-04 21:36:35 +02009142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009143 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009144 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009145
9146 if (threshold > 0)
9147 return -EINVAL;
9148
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009149 /* disabling - hysteresis should also be zero then */
9150 if (threshold == 0)
9151 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009152
Johannes Berg4c476992010-10-04 21:36:35 +02009153 if (!rdev->ops->set_cqm_rssi_config)
9154 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009155
Johannes Berg074ac8d2010-09-16 14:58:22 +02009156 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009157 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9158 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009159
Hila Gonene35e4d22012-06-27 17:19:42 +03009160 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009161}
9162
9163static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9164{
9165 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9166 struct nlattr *cqm;
9167 int err;
9168
9169 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009170 if (!cqm)
9171 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009172
9173 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9174 nl80211_attr_cqm_policy);
9175 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009176 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009177
9178 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9179 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009180 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9181 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009182
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009183 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9184 }
9185
9186 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9187 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9188 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9189 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9190 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9191 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9192
9193 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9194 }
9195
9196 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009197}
9198
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009199static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9200{
9201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9202 struct net_device *dev = info->user_ptr[1];
9203 struct ocb_setup setup = {};
9204 int err;
9205
9206 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9207 if (err)
9208 return err;
9209
9210 return cfg80211_join_ocb(rdev, dev, &setup);
9211}
9212
9213static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9214{
9215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9216 struct net_device *dev = info->user_ptr[1];
9217
9218 return cfg80211_leave_ocb(rdev, dev);
9219}
9220
Johannes Berg29cbe682010-12-03 09:20:44 +01009221static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9222{
9223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9224 struct net_device *dev = info->user_ptr[1];
9225 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009226 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009227 int err;
9228
9229 /* start with default */
9230 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009231 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009232
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009233 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009234 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009235 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009236 if (err)
9237 return err;
9238 }
9239
9240 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9241 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9242 return -EINVAL;
9243
Javier Cardonac80d5452010-12-16 17:37:49 -08009244 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9245 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9246
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009247 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9248 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9249 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9250 return -EINVAL;
9251
Marco Porsch9bdbf042013-01-07 16:04:51 +01009252 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9253 setup.beacon_interval =
9254 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9255 if (setup.beacon_interval < 10 ||
9256 setup.beacon_interval > 10000)
9257 return -EINVAL;
9258 }
9259
9260 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9261 setup.dtim_period =
9262 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9263 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9264 return -EINVAL;
9265 }
9266
Javier Cardonac80d5452010-12-16 17:37:49 -08009267 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9268 /* parse additional setup parameters if given */
9269 err = nl80211_parse_mesh_setup(info, &setup);
9270 if (err)
9271 return err;
9272 }
9273
Thomas Pedersend37bb182013-03-04 13:06:13 -08009274 if (setup.user_mpm)
9275 cfg.auto_open_plinks = false;
9276
Johannes Bergcc1d2802012-05-16 23:50:20 +02009277 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009278 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9279 if (err)
9280 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009281 } else {
9282 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009283 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009284 }
9285
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009286 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9287 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9288 int n_rates =
9289 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9290 struct ieee80211_supported_band *sband;
9291
9292 if (!setup.chandef.chan)
9293 return -EINVAL;
9294
9295 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9296
9297 err = ieee80211_get_ratemask(sband, rates, n_rates,
9298 &setup.basic_rates);
9299 if (err)
9300 return err;
9301 }
9302
Javier Cardonac80d5452010-12-16 17:37:49 -08009303 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009304}
9305
9306static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9307{
9308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9309 struct net_device *dev = info->user_ptr[1];
9310
9311 return cfg80211_leave_mesh(rdev, dev);
9312}
9313
Johannes Bergdfb89c52012-06-27 09:23:48 +02009314#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009315static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9316 struct cfg80211_registered_device *rdev)
9317{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009318 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009319 struct nlattr *nl_pats, *nl_pat;
9320 int i, pat_len;
9321
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009322 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009323 return 0;
9324
9325 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9326 if (!nl_pats)
9327 return -ENOBUFS;
9328
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009329 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009330 nl_pat = nla_nest_start(msg, i + 1);
9331 if (!nl_pat)
9332 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009333 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009334 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009335 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009336 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9337 wowlan->patterns[i].pattern) ||
9338 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009339 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009340 return -ENOBUFS;
9341 nla_nest_end(msg, nl_pat);
9342 }
9343 nla_nest_end(msg, nl_pats);
9344
9345 return 0;
9346}
9347
Johannes Berg2a0e0472013-01-23 22:57:40 +01009348static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9349 struct cfg80211_wowlan_tcp *tcp)
9350{
9351 struct nlattr *nl_tcp;
9352
9353 if (!tcp)
9354 return 0;
9355
9356 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9357 if (!nl_tcp)
9358 return -ENOBUFS;
9359
Jiri Benc930345e2015-03-29 16:59:25 +02009360 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9361 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009362 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9363 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9364 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9365 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9366 tcp->payload_len, tcp->payload) ||
9367 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9368 tcp->data_interval) ||
9369 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9370 tcp->wake_len, tcp->wake_data) ||
9371 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9372 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9373 return -ENOBUFS;
9374
9375 if (tcp->payload_seq.len &&
9376 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9377 sizeof(tcp->payload_seq), &tcp->payload_seq))
9378 return -ENOBUFS;
9379
9380 if (tcp->payload_tok.len &&
9381 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9382 sizeof(tcp->payload_tok) + tcp->tokens_size,
9383 &tcp->payload_tok))
9384 return -ENOBUFS;
9385
Johannes Berge248ad32013-05-16 10:24:28 +02009386 nla_nest_end(msg, nl_tcp);
9387
Johannes Berg2a0e0472013-01-23 22:57:40 +01009388 return 0;
9389}
9390
Luciano Coelho75453cc2015-01-09 14:06:37 +02009391static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9392 struct cfg80211_sched_scan_request *req)
9393{
Avraham Stern3b06d272015-10-12 09:51:34 +03009394 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009395 int i;
9396
9397 if (!req)
9398 return 0;
9399
9400 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9401 if (!nd)
9402 return -ENOBUFS;
9403
Avraham Stern3b06d272015-10-12 09:51:34 +03009404 if (req->n_scan_plans == 1 &&
9405 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9406 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009407 return -ENOBUFS;
9408
Luciano Coelho21fea562015-03-17 16:36:01 +02009409 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9410 return -ENOBUFS;
9411
Luciano Coelho75453cc2015-01-09 14:06:37 +02009412 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9413 if (!freqs)
9414 return -ENOBUFS;
9415
9416 for (i = 0; i < req->n_channels; i++)
9417 nla_put_u32(msg, i, req->channels[i]->center_freq);
9418
9419 nla_nest_end(msg, freqs);
9420
9421 if (req->n_match_sets) {
9422 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9423 for (i = 0; i < req->n_match_sets; i++) {
9424 match = nla_nest_start(msg, i);
9425 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9426 req->match_sets[i].ssid.ssid_len,
9427 req->match_sets[i].ssid.ssid);
9428 nla_nest_end(msg, match);
9429 }
9430 nla_nest_end(msg, matches);
9431 }
9432
Avraham Stern3b06d272015-10-12 09:51:34 +03009433 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9434 if (!scan_plans)
9435 return -ENOBUFS;
9436
9437 for (i = 0; i < req->n_scan_plans; i++) {
9438 scan_plan = nla_nest_start(msg, i + 1);
9439 if (!scan_plan ||
9440 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9441 req->scan_plans[i].interval) ||
9442 (req->scan_plans[i].iterations &&
9443 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9444 req->scan_plans[i].iterations)))
9445 return -ENOBUFS;
9446 nla_nest_end(msg, scan_plan);
9447 }
9448 nla_nest_end(msg, scan_plans);
9449
Luciano Coelho75453cc2015-01-09 14:06:37 +02009450 nla_nest_end(msg, nd);
9451
9452 return 0;
9453}
9454
Johannes Bergff1b6e62011-05-04 15:37:28 +02009455static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9456{
9457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9458 struct sk_buff *msg;
9459 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009460 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009461
Johannes Berg964dc9e2013-06-03 17:25:34 +02009462 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009463 return -EOPNOTSUPP;
9464
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009465 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009466 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009467 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9468 rdev->wiphy.wowlan_config->tcp->payload_len +
9469 rdev->wiphy.wowlan_config->tcp->wake_len +
9470 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009471 }
9472
9473 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009474 if (!msg)
9475 return -ENOMEM;
9476
Eric W. Biederman15e47302012-09-07 20:12:54 +00009477 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009478 NL80211_CMD_GET_WOWLAN);
9479 if (!hdr)
9480 goto nla_put_failure;
9481
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009482 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009483 struct nlattr *nl_wowlan;
9484
9485 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9486 if (!nl_wowlan)
9487 goto nla_put_failure;
9488
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009489 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009490 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009491 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009492 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009493 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009494 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009495 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009496 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009497 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009498 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009499 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009500 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009501 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009502 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9503 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009504
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009505 if (nl80211_send_wowlan_patterns(msg, rdev))
9506 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009507
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009508 if (nl80211_send_wowlan_tcp(msg,
9509 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009510 goto nla_put_failure;
9511
Luciano Coelho75453cc2015-01-09 14:06:37 +02009512 if (nl80211_send_wowlan_nd(
9513 msg,
9514 rdev->wiphy.wowlan_config->nd_config))
9515 goto nla_put_failure;
9516
Johannes Bergff1b6e62011-05-04 15:37:28 +02009517 nla_nest_end(msg, nl_wowlan);
9518 }
9519
9520 genlmsg_end(msg, hdr);
9521 return genlmsg_reply(msg, info);
9522
9523nla_put_failure:
9524 nlmsg_free(msg);
9525 return -ENOBUFS;
9526}
9527
Johannes Berg2a0e0472013-01-23 22:57:40 +01009528static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9529 struct nlattr *attr,
9530 struct cfg80211_wowlan *trig)
9531{
9532 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9533 struct cfg80211_wowlan_tcp *cfg;
9534 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9535 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9536 u32 size;
9537 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9538 int err, port;
9539
Johannes Berg964dc9e2013-06-03 17:25:34 +02009540 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009541 return -EINVAL;
9542
9543 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9544 nla_data(attr), nla_len(attr),
9545 nl80211_wowlan_tcp_policy);
9546 if (err)
9547 return err;
9548
9549 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9550 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9551 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9552 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9553 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9554 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9555 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9556 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9557 return -EINVAL;
9558
9559 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009560 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009561 return -EINVAL;
9562
9563 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009564 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009565 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009566 return -EINVAL;
9567
9568 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009569 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009570 return -EINVAL;
9571
9572 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9573 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9574 return -EINVAL;
9575
9576 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9577 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9578
9579 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9580 tokens_size = tokln - sizeof(*tok);
9581
9582 if (!tok->len || tokens_size % tok->len)
9583 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009584 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009585 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009586 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009587 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009588 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009589 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009590 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009591 return -EINVAL;
9592 if (tok->offset + tok->len > data_size)
9593 return -EINVAL;
9594 }
9595
9596 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9597 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009598 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009599 return -EINVAL;
9600 if (seq->len == 0 || seq->len > 4)
9601 return -EINVAL;
9602 if (seq->len + seq->offset > data_size)
9603 return -EINVAL;
9604 }
9605
9606 size = sizeof(*cfg);
9607 size += data_size;
9608 size += wake_size + wake_mask_size;
9609 size += tokens_size;
9610
9611 cfg = kzalloc(size, GFP_KERNEL);
9612 if (!cfg)
9613 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009614 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9615 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009616 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9617 ETH_ALEN);
9618 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9619 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9620 else
9621 port = 0;
9622#ifdef CONFIG_INET
9623 /* allocate a socket and port for it and use it */
9624 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9625 IPPROTO_TCP, &cfg->sock, 1);
9626 if (err) {
9627 kfree(cfg);
9628 return err;
9629 }
9630 if (inet_csk_get_port(cfg->sock->sk, port)) {
9631 sock_release(cfg->sock);
9632 kfree(cfg);
9633 return -EADDRINUSE;
9634 }
9635 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9636#else
9637 if (!port) {
9638 kfree(cfg);
9639 return -EINVAL;
9640 }
9641 cfg->src_port = port;
9642#endif
9643
9644 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9645 cfg->payload_len = data_size;
9646 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9647 memcpy((void *)cfg->payload,
9648 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9649 data_size);
9650 if (seq)
9651 cfg->payload_seq = *seq;
9652 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9653 cfg->wake_len = wake_size;
9654 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9655 memcpy((void *)cfg->wake_data,
9656 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9657 wake_size);
9658 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9659 data_size + wake_size;
9660 memcpy((void *)cfg->wake_mask,
9661 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9662 wake_mask_size);
9663 if (tok) {
9664 cfg->tokens_size = tokens_size;
9665 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9666 }
9667
9668 trig->tcp = cfg;
9669
9670 return 0;
9671}
9672
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009673static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9674 const struct wiphy_wowlan_support *wowlan,
9675 struct nlattr *attr,
9676 struct cfg80211_wowlan *trig)
9677{
9678 struct nlattr **tb;
9679 int err;
9680
9681 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9682 if (!tb)
9683 return -ENOMEM;
9684
9685 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9686 err = -EOPNOTSUPP;
9687 goto out;
9688 }
9689
9690 err = nla_parse(tb, NL80211_ATTR_MAX,
9691 nla_data(attr), nla_len(attr),
9692 nl80211_policy);
9693 if (err)
9694 goto out;
9695
Johannes Bergad2b26a2014-06-12 21:39:05 +02009696 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009697 err = PTR_ERR_OR_ZERO(trig->nd_config);
9698 if (err)
9699 trig->nd_config = NULL;
9700
9701out:
9702 kfree(tb);
9703 return err;
9704}
9705
Johannes Bergff1b6e62011-05-04 15:37:28 +02009706static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9707{
9708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9709 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009710 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009711 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009712 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009713 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009714 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009715 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009716
Johannes Berg964dc9e2013-06-03 17:25:34 +02009717 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009718 return -EOPNOTSUPP;
9719
Johannes Bergae33bd82012-07-12 16:25:02 +02009720 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9721 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009722 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009723 goto set_wakeup;
9724 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009725
9726 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9727 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9728 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9729 nl80211_wowlan_policy);
9730 if (err)
9731 return err;
9732
9733 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9734 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9735 return -EINVAL;
9736 new_triggers.any = true;
9737 }
9738
9739 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9740 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9741 return -EINVAL;
9742 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009743 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009744 }
9745
9746 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9747 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9748 return -EINVAL;
9749 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009750 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009751 }
9752
Johannes Berg77dbbb12011-07-13 10:48:55 +02009753 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9754 return -EINVAL;
9755
9756 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9757 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9758 return -EINVAL;
9759 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009760 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009761 }
9762
9763 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9764 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9765 return -EINVAL;
9766 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009767 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009768 }
9769
9770 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9771 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9772 return -EINVAL;
9773 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009774 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009775 }
9776
9777 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9778 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9779 return -EINVAL;
9780 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009781 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009782 }
9783
Johannes Bergff1b6e62011-05-04 15:37:28 +02009784 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9785 struct nlattr *pat;
9786 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009787 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009788 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009789
Johannes Berg98fc4382015-03-01 09:10:13 +02009790 regular = true;
9791
Johannes Bergff1b6e62011-05-04 15:37:28 +02009792 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9793 rem)
9794 n_patterns++;
9795 if (n_patterns > wowlan->n_patterns)
9796 return -EINVAL;
9797
9798 new_triggers.patterns = kcalloc(n_patterns,
9799 sizeof(new_triggers.patterns[0]),
9800 GFP_KERNEL);
9801 if (!new_triggers.patterns)
9802 return -ENOMEM;
9803
9804 new_triggers.n_patterns = n_patterns;
9805 i = 0;
9806
9807 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9808 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009809 u8 *mask_pat;
9810
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009811 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9812 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009813 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009814 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9815 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009816 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009817 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009818 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009819 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009820 goto error;
9821 if (pat_len > wowlan->pattern_max_len ||
9822 pat_len < wowlan->pattern_min_len)
9823 goto error;
9824
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009825 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009826 pkt_offset = 0;
9827 else
9828 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009829 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009830 if (pkt_offset > wowlan->max_pkt_offset)
9831 goto error;
9832 new_triggers.patterns[i].pkt_offset = pkt_offset;
9833
Johannes Berg922bd802014-05-19 17:59:50 +02009834 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9835 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009836 err = -ENOMEM;
9837 goto error;
9838 }
Johannes Berg922bd802014-05-19 17:59:50 +02009839 new_triggers.patterns[i].mask = mask_pat;
9840 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009841 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009842 mask_pat += mask_len;
9843 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009844 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009845 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009846 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009847 pat_len);
9848 i++;
9849 }
9850 }
9851
Johannes Berg2a0e0472013-01-23 22:57:40 +01009852 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009853 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009854 err = nl80211_parse_wowlan_tcp(
9855 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9856 &new_triggers);
9857 if (err)
9858 goto error;
9859 }
9860
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009861 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009862 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009863 err = nl80211_parse_wowlan_nd(
9864 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9865 &new_triggers);
9866 if (err)
9867 goto error;
9868 }
9869
Johannes Berg98fc4382015-03-01 09:10:13 +02009870 /* The 'any' trigger means the device continues operating more or less
9871 * as in its normal operation mode and wakes up the host on most of the
9872 * normal interrupts (like packet RX, ...)
9873 * It therefore makes little sense to combine with the more constrained
9874 * wakeup trigger modes.
9875 */
9876 if (new_triggers.any && regular) {
9877 err = -EINVAL;
9878 goto error;
9879 }
9880
Johannes Bergae33bd82012-07-12 16:25:02 +02009881 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9882 if (!ntrig) {
9883 err = -ENOMEM;
9884 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009885 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009886 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009887 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009888
Johannes Bergae33bd82012-07-12 16:25:02 +02009889 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009890 if (rdev->ops->set_wakeup &&
9891 prev_enabled != !!rdev->wiphy.wowlan_config)
9892 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009893
Johannes Bergff1b6e62011-05-04 15:37:28 +02009894 return 0;
9895 error:
9896 for (i = 0; i < new_triggers.n_patterns; i++)
9897 kfree(new_triggers.patterns[i].mask);
9898 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009899 if (new_triggers.tcp && new_triggers.tcp->sock)
9900 sock_release(new_triggers.tcp->sock);
9901 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009902 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009903 return err;
9904}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009905#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009906
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009907static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9908 struct cfg80211_registered_device *rdev)
9909{
9910 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9911 int i, j, pat_len;
9912 struct cfg80211_coalesce_rules *rule;
9913
9914 if (!rdev->coalesce->n_rules)
9915 return 0;
9916
9917 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9918 if (!nl_rules)
9919 return -ENOBUFS;
9920
9921 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9922 nl_rule = nla_nest_start(msg, i + 1);
9923 if (!nl_rule)
9924 return -ENOBUFS;
9925
9926 rule = &rdev->coalesce->rules[i];
9927 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9928 rule->delay))
9929 return -ENOBUFS;
9930
9931 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9932 rule->condition))
9933 return -ENOBUFS;
9934
9935 nl_pats = nla_nest_start(msg,
9936 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9937 if (!nl_pats)
9938 return -ENOBUFS;
9939
9940 for (j = 0; j < rule->n_patterns; j++) {
9941 nl_pat = nla_nest_start(msg, j + 1);
9942 if (!nl_pat)
9943 return -ENOBUFS;
9944 pat_len = rule->patterns[j].pattern_len;
9945 if (nla_put(msg, NL80211_PKTPAT_MASK,
9946 DIV_ROUND_UP(pat_len, 8),
9947 rule->patterns[j].mask) ||
9948 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9949 rule->patterns[j].pattern) ||
9950 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9951 rule->patterns[j].pkt_offset))
9952 return -ENOBUFS;
9953 nla_nest_end(msg, nl_pat);
9954 }
9955 nla_nest_end(msg, nl_pats);
9956 nla_nest_end(msg, nl_rule);
9957 }
9958 nla_nest_end(msg, nl_rules);
9959
9960 return 0;
9961}
9962
9963static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9964{
9965 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9966 struct sk_buff *msg;
9967 void *hdr;
9968
9969 if (!rdev->wiphy.coalesce)
9970 return -EOPNOTSUPP;
9971
9972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9973 if (!msg)
9974 return -ENOMEM;
9975
9976 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9977 NL80211_CMD_GET_COALESCE);
9978 if (!hdr)
9979 goto nla_put_failure;
9980
9981 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9982 goto nla_put_failure;
9983
9984 genlmsg_end(msg, hdr);
9985 return genlmsg_reply(msg, info);
9986
9987nla_put_failure:
9988 nlmsg_free(msg);
9989 return -ENOBUFS;
9990}
9991
9992void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9993{
9994 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9995 int i, j;
9996 struct cfg80211_coalesce_rules *rule;
9997
9998 if (!coalesce)
9999 return;
10000
10001 for (i = 0; i < coalesce->n_rules; i++) {
10002 rule = &coalesce->rules[i];
10003 for (j = 0; j < rule->n_patterns; j++)
10004 kfree(rule->patterns[j].mask);
10005 kfree(rule->patterns);
10006 }
10007 kfree(coalesce->rules);
10008 kfree(coalesce);
10009 rdev->coalesce = NULL;
10010}
10011
10012static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10013 struct nlattr *rule,
10014 struct cfg80211_coalesce_rules *new_rule)
10015{
10016 int err, i;
10017 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10018 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10019 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10020 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10021
10022 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10023 nla_len(rule), nl80211_coalesce_policy);
10024 if (err)
10025 return err;
10026
10027 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10028 new_rule->delay =
10029 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10030 if (new_rule->delay > coalesce->max_delay)
10031 return -EINVAL;
10032
10033 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10034 new_rule->condition =
10035 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10036 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10037 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10038 return -EINVAL;
10039
10040 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10041 return -EINVAL;
10042
10043 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10044 rem)
10045 n_patterns++;
10046 if (n_patterns > coalesce->n_patterns)
10047 return -EINVAL;
10048
10049 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10050 GFP_KERNEL);
10051 if (!new_rule->patterns)
10052 return -ENOMEM;
10053
10054 new_rule->n_patterns = n_patterns;
10055 i = 0;
10056
10057 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10058 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010059 u8 *mask_pat;
10060
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010061 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10062 nla_len(pat), NULL);
10063 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10064 !pat_tb[NL80211_PKTPAT_PATTERN])
10065 return -EINVAL;
10066 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10067 mask_len = DIV_ROUND_UP(pat_len, 8);
10068 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10069 return -EINVAL;
10070 if (pat_len > coalesce->pattern_max_len ||
10071 pat_len < coalesce->pattern_min_len)
10072 return -EINVAL;
10073
10074 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10075 pkt_offset = 0;
10076 else
10077 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10078 if (pkt_offset > coalesce->max_pkt_offset)
10079 return -EINVAL;
10080 new_rule->patterns[i].pkt_offset = pkt_offset;
10081
Johannes Berg922bd802014-05-19 17:59:50 +020010082 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10083 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010084 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010085
10086 new_rule->patterns[i].mask = mask_pat;
10087 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10088 mask_len);
10089
10090 mask_pat += mask_len;
10091 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010092 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010093 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10094 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010095 i++;
10096 }
10097
10098 return 0;
10099}
10100
10101static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10102{
10103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10104 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10105 struct cfg80211_coalesce new_coalesce = {};
10106 struct cfg80211_coalesce *n_coalesce;
10107 int err, rem_rule, n_rules = 0, i, j;
10108 struct nlattr *rule;
10109 struct cfg80211_coalesce_rules *tmp_rule;
10110
10111 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10112 return -EOPNOTSUPP;
10113
10114 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10115 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010116 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010117 return 0;
10118 }
10119
10120 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10121 rem_rule)
10122 n_rules++;
10123 if (n_rules > coalesce->n_rules)
10124 return -EINVAL;
10125
10126 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10127 GFP_KERNEL);
10128 if (!new_coalesce.rules)
10129 return -ENOMEM;
10130
10131 new_coalesce.n_rules = n_rules;
10132 i = 0;
10133
10134 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10135 rem_rule) {
10136 err = nl80211_parse_coalesce_rule(rdev, rule,
10137 &new_coalesce.rules[i]);
10138 if (err)
10139 goto error;
10140
10141 i++;
10142 }
10143
Ilan Peera1056b12015-10-22 22:27:46 +030010144 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010145 if (err)
10146 goto error;
10147
10148 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10149 if (!n_coalesce) {
10150 err = -ENOMEM;
10151 goto error;
10152 }
10153 cfg80211_rdev_free_coalesce(rdev);
10154 rdev->coalesce = n_coalesce;
10155
10156 return 0;
10157error:
10158 for (i = 0; i < new_coalesce.n_rules; i++) {
10159 tmp_rule = &new_coalesce.rules[i];
10160 for (j = 0; j < tmp_rule->n_patterns; j++)
10161 kfree(tmp_rule->patterns[j].mask);
10162 kfree(tmp_rule->patterns);
10163 }
10164 kfree(new_coalesce.rules);
10165
10166 return err;
10167}
10168
Johannes Berge5497d72011-07-05 16:35:40 +020010169static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10170{
10171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10172 struct net_device *dev = info->user_ptr[1];
10173 struct wireless_dev *wdev = dev->ieee80211_ptr;
10174 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10175 struct cfg80211_gtk_rekey_data rekey_data;
10176 int err;
10177
10178 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10179 return -EINVAL;
10180
10181 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10182 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10183 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10184 nl80211_rekey_policy);
10185 if (err)
10186 return err;
10187
10188 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10189 return -ERANGE;
10190 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10191 return -ERANGE;
10192 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10193 return -ERANGE;
10194
Johannes Berg78f686c2014-09-10 22:28:06 +030010195 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10196 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10197 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010198
10199 wdev_lock(wdev);
10200 if (!wdev->current_bss) {
10201 err = -ENOTCONN;
10202 goto out;
10203 }
10204
10205 if (!rdev->ops->set_rekey_data) {
10206 err = -EOPNOTSUPP;
10207 goto out;
10208 }
10209
Hila Gonene35e4d22012-06-27 17:19:42 +030010210 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010211 out:
10212 wdev_unlock(wdev);
10213 return err;
10214}
10215
Johannes Berg28946da2011-11-04 11:18:12 +010010216static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10217 struct genl_info *info)
10218{
10219 struct net_device *dev = info->user_ptr[1];
10220 struct wireless_dev *wdev = dev->ieee80211_ptr;
10221
10222 if (wdev->iftype != NL80211_IFTYPE_AP &&
10223 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10224 return -EINVAL;
10225
Eric W. Biederman15e47302012-09-07 20:12:54 +000010226 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010227 return -EBUSY;
10228
Eric W. Biederman15e47302012-09-07 20:12:54 +000010229 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010230 return 0;
10231}
10232
Johannes Berg7f6cf312011-11-04 11:18:15 +010010233static int nl80211_probe_client(struct sk_buff *skb,
10234 struct genl_info *info)
10235{
10236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10237 struct net_device *dev = info->user_ptr[1];
10238 struct wireless_dev *wdev = dev->ieee80211_ptr;
10239 struct sk_buff *msg;
10240 void *hdr;
10241 const u8 *addr;
10242 u64 cookie;
10243 int err;
10244
10245 if (wdev->iftype != NL80211_IFTYPE_AP &&
10246 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10247 return -EOPNOTSUPP;
10248
10249 if (!info->attrs[NL80211_ATTR_MAC])
10250 return -EINVAL;
10251
10252 if (!rdev->ops->probe_client)
10253 return -EOPNOTSUPP;
10254
10255 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10256 if (!msg)
10257 return -ENOMEM;
10258
Eric W. Biederman15e47302012-09-07 20:12:54 +000010259 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010260 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010261 if (!hdr) {
10262 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010263 goto free_msg;
10264 }
10265
10266 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10267
Hila Gonene35e4d22012-06-27 17:19:42 +030010268 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010269 if (err)
10270 goto free_msg;
10271
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010272 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10273 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010274 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010275
10276 genlmsg_end(msg, hdr);
10277
10278 return genlmsg_reply(msg, info);
10279
10280 nla_put_failure:
10281 err = -ENOBUFS;
10282 free_msg:
10283 nlmsg_free(msg);
10284 return err;
10285}
10286
Johannes Berg5e7602302011-11-04 11:18:17 +010010287static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10288{
10289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010290 struct cfg80211_beacon_registration *reg, *nreg;
10291 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010292
10293 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10294 return -EOPNOTSUPP;
10295
Ben Greear37c73b52012-10-26 14:49:25 -070010296 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10297 if (!nreg)
10298 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010299
Ben Greear37c73b52012-10-26 14:49:25 -070010300 /* First, check if already registered. */
10301 spin_lock_bh(&rdev->beacon_registrations_lock);
10302 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10303 if (reg->nlportid == info->snd_portid) {
10304 rv = -EALREADY;
10305 goto out_err;
10306 }
10307 }
10308 /* Add it to the list */
10309 nreg->nlportid = info->snd_portid;
10310 list_add(&nreg->list, &rdev->beacon_registrations);
10311
10312 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010313
10314 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010315out_err:
10316 spin_unlock_bh(&rdev->beacon_registrations_lock);
10317 kfree(nreg);
10318 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010319}
10320
Johannes Berg98104fde2012-06-16 00:19:54 +020010321static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10322{
10323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10324 struct wireless_dev *wdev = info->user_ptr[1];
10325 int err;
10326
10327 if (!rdev->ops->start_p2p_device)
10328 return -EOPNOTSUPP;
10329
10330 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10331 return -EOPNOTSUPP;
10332
10333 if (wdev->p2p_started)
10334 return 0;
10335
Luciano Coelhob6a55012014-02-27 11:07:21 +020010336 if (rfkill_blocked(rdev->rfkill))
10337 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010338
Johannes Bergeeb126e2012-10-23 15:16:50 +020010339 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010340 if (err)
10341 return err;
10342
10343 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010344 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010345
10346 return 0;
10347}
10348
10349static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10350{
10351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10352 struct wireless_dev *wdev = info->user_ptr[1];
10353
10354 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10355 return -EOPNOTSUPP;
10356
10357 if (!rdev->ops->stop_p2p_device)
10358 return -EOPNOTSUPP;
10359
Johannes Bergf9f47522013-03-19 15:04:07 +010010360 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010361
10362 return 0;
10363}
10364
Johannes Berg3713b4e2013-02-14 16:19:38 +010010365static int nl80211_get_protocol_features(struct sk_buff *skb,
10366 struct genl_info *info)
10367{
10368 void *hdr;
10369 struct sk_buff *msg;
10370
10371 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10372 if (!msg)
10373 return -ENOMEM;
10374
10375 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10376 NL80211_CMD_GET_PROTOCOL_FEATURES);
10377 if (!hdr)
10378 goto nla_put_failure;
10379
10380 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10381 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10382 goto nla_put_failure;
10383
10384 genlmsg_end(msg, hdr);
10385 return genlmsg_reply(msg, info);
10386
10387 nla_put_failure:
10388 kfree_skb(msg);
10389 return -ENOBUFS;
10390}
10391
Jouni Malinen355199e2013-02-27 17:14:27 +020010392static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10393{
10394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10395 struct cfg80211_update_ft_ies_params ft_params;
10396 struct net_device *dev = info->user_ptr[1];
10397
10398 if (!rdev->ops->update_ft_ies)
10399 return -EOPNOTSUPP;
10400
10401 if (!info->attrs[NL80211_ATTR_MDID] ||
10402 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10403 return -EINVAL;
10404
10405 memset(&ft_params, 0, sizeof(ft_params));
10406 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10407 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10408 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10409
10410 return rdev_update_ft_ies(rdev, dev, &ft_params);
10411}
10412
Arend van Spriel5de17982013-04-18 15:49:00 +020010413static int nl80211_crit_protocol_start(struct sk_buff *skb,
10414 struct genl_info *info)
10415{
10416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10417 struct wireless_dev *wdev = info->user_ptr[1];
10418 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10419 u16 duration;
10420 int ret;
10421
10422 if (!rdev->ops->crit_proto_start)
10423 return -EOPNOTSUPP;
10424
10425 if (WARN_ON(!rdev->ops->crit_proto_stop))
10426 return -EINVAL;
10427
10428 if (rdev->crit_proto_nlportid)
10429 return -EBUSY;
10430
10431 /* determine protocol if provided */
10432 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10433 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10434
10435 if (proto >= NUM_NL80211_CRIT_PROTO)
10436 return -EINVAL;
10437
10438 /* timeout must be provided */
10439 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10440 return -EINVAL;
10441
10442 duration =
10443 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10444
10445 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10446 return -ERANGE;
10447
10448 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10449 if (!ret)
10450 rdev->crit_proto_nlportid = info->snd_portid;
10451
10452 return ret;
10453}
10454
10455static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10456 struct genl_info *info)
10457{
10458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10459 struct wireless_dev *wdev = info->user_ptr[1];
10460
10461 if (!rdev->ops->crit_proto_stop)
10462 return -EOPNOTSUPP;
10463
10464 if (rdev->crit_proto_nlportid) {
10465 rdev->crit_proto_nlportid = 0;
10466 rdev_crit_proto_stop(rdev, wdev);
10467 }
10468 return 0;
10469}
10470
Johannes Bergad7e7182013-11-13 13:37:47 +010010471static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10472{
10473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10474 struct wireless_dev *wdev =
10475 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10476 int i, err;
10477 u32 vid, subcmd;
10478
10479 if (!rdev->wiphy.vendor_commands)
10480 return -EOPNOTSUPP;
10481
10482 if (IS_ERR(wdev)) {
10483 err = PTR_ERR(wdev);
10484 if (err != -EINVAL)
10485 return err;
10486 wdev = NULL;
10487 } else if (wdev->wiphy != &rdev->wiphy) {
10488 return -EINVAL;
10489 }
10490
10491 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10492 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10493 return -EINVAL;
10494
10495 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10496 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10497 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10498 const struct wiphy_vendor_command *vcmd;
10499 void *data = NULL;
10500 int len = 0;
10501
10502 vcmd = &rdev->wiphy.vendor_commands[i];
10503
10504 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10505 continue;
10506
10507 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10508 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10509 if (!wdev)
10510 return -EINVAL;
10511 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10512 !wdev->netdev)
10513 return -EINVAL;
10514
10515 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10516 if (wdev->netdev &&
10517 !netif_running(wdev->netdev))
10518 return -ENETDOWN;
10519 if (!wdev->netdev && !wdev->p2p_started)
10520 return -ENETDOWN;
10521 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010522
10523 if (!vcmd->doit)
10524 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010525 } else {
10526 wdev = NULL;
10527 }
10528
10529 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10530 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10531 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10532 }
10533
10534 rdev->cur_cmd_info = info;
10535 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10536 data, len);
10537 rdev->cur_cmd_info = NULL;
10538 return err;
10539 }
10540
10541 return -EOPNOTSUPP;
10542}
10543
Johannes Berg7bdbe402015-08-15 22:39:49 +030010544static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10545 struct netlink_callback *cb,
10546 struct cfg80211_registered_device **rdev,
10547 struct wireless_dev **wdev)
10548{
10549 u32 vid, subcmd;
10550 unsigned int i;
10551 int vcmd_idx = -1;
10552 int err;
10553 void *data = NULL;
10554 unsigned int data_len = 0;
10555
10556 rtnl_lock();
10557
10558 if (cb->args[0]) {
10559 /* subtract the 1 again here */
10560 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10561 struct wireless_dev *tmp;
10562
10563 if (!wiphy) {
10564 err = -ENODEV;
10565 goto out_unlock;
10566 }
10567 *rdev = wiphy_to_rdev(wiphy);
10568 *wdev = NULL;
10569
10570 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010571 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010572 if (tmp->identifier == cb->args[1] - 1) {
10573 *wdev = tmp;
10574 break;
10575 }
10576 }
10577 }
10578
10579 /* keep rtnl locked in successful case */
10580 return 0;
10581 }
10582
10583 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10584 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10585 nl80211_policy);
10586 if (err)
10587 goto out_unlock;
10588
10589 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10590 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10591 err = -EINVAL;
10592 goto out_unlock;
10593 }
10594
10595 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10596 nl80211_fam.attrbuf);
10597 if (IS_ERR(*wdev))
10598 *wdev = NULL;
10599
10600 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10601 nl80211_fam.attrbuf);
10602 if (IS_ERR(*rdev)) {
10603 err = PTR_ERR(*rdev);
10604 goto out_unlock;
10605 }
10606
10607 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10608 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10609
10610 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10611 const struct wiphy_vendor_command *vcmd;
10612
10613 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10614
10615 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10616 continue;
10617
10618 if (!vcmd->dumpit) {
10619 err = -EOPNOTSUPP;
10620 goto out_unlock;
10621 }
10622
10623 vcmd_idx = i;
10624 break;
10625 }
10626
10627 if (vcmd_idx < 0) {
10628 err = -EOPNOTSUPP;
10629 goto out_unlock;
10630 }
10631
10632 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10633 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10634 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10635 }
10636
10637 /* 0 is the first index - add 1 to parse only once */
10638 cb->args[0] = (*rdev)->wiphy_idx + 1;
10639 /* add 1 to know if it was NULL */
10640 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10641 cb->args[2] = vcmd_idx;
10642 cb->args[3] = (unsigned long)data;
10643 cb->args[4] = data_len;
10644
10645 /* keep rtnl locked in successful case */
10646 return 0;
10647 out_unlock:
10648 rtnl_unlock();
10649 return err;
10650}
10651
10652static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10653 struct netlink_callback *cb)
10654{
10655 struct cfg80211_registered_device *rdev;
10656 struct wireless_dev *wdev;
10657 unsigned int vcmd_idx;
10658 const struct wiphy_vendor_command *vcmd;
10659 void *data;
10660 int data_len;
10661 int err;
10662 struct nlattr *vendor_data;
10663
10664 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10665 if (err)
10666 return err;
10667
10668 vcmd_idx = cb->args[2];
10669 data = (void *)cb->args[3];
10670 data_len = cb->args[4];
10671 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10672
10673 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10674 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10675 if (!wdev)
10676 return -EINVAL;
10677 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10678 !wdev->netdev)
10679 return -EINVAL;
10680
10681 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10682 if (wdev->netdev &&
10683 !netif_running(wdev->netdev))
10684 return -ENETDOWN;
10685 if (!wdev->netdev && !wdev->p2p_started)
10686 return -ENETDOWN;
10687 }
10688 }
10689
10690 while (1) {
10691 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10692 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10693 NL80211_CMD_VENDOR);
10694 if (!hdr)
10695 break;
10696
10697 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010698 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10699 wdev_id(wdev),
10700 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010701 genlmsg_cancel(skb, hdr);
10702 break;
10703 }
10704
10705 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10706 if (!vendor_data) {
10707 genlmsg_cancel(skb, hdr);
10708 break;
10709 }
10710
10711 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10712 (unsigned long *)&cb->args[5]);
10713 nla_nest_end(skb, vendor_data);
10714
10715 if (err == -ENOBUFS || err == -ENOENT) {
10716 genlmsg_cancel(skb, hdr);
10717 break;
10718 } else if (err) {
10719 genlmsg_cancel(skb, hdr);
10720 goto out;
10721 }
10722
10723 genlmsg_end(skb, hdr);
10724 }
10725
10726 err = skb->len;
10727 out:
10728 rtnl_unlock();
10729 return err;
10730}
10731
Johannes Bergad7e7182013-11-13 13:37:47 +010010732struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10733 enum nl80211_commands cmd,
10734 enum nl80211_attrs attr,
10735 int approxlen)
10736{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010737 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010738
10739 if (WARN_ON(!rdev->cur_cmd_info))
10740 return NULL;
10741
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010742 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010743 rdev->cur_cmd_info->snd_portid,
10744 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010745 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010746}
10747EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10748
10749int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10750{
10751 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10752 void *hdr = ((void **)skb->cb)[1];
10753 struct nlattr *data = ((void **)skb->cb)[2];
10754
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010755 /* clear CB data for netlink core to own from now on */
10756 memset(skb->cb, 0, sizeof(skb->cb));
10757
Johannes Bergad7e7182013-11-13 13:37:47 +010010758 if (WARN_ON(!rdev->cur_cmd_info)) {
10759 kfree_skb(skb);
10760 return -EINVAL;
10761 }
10762
10763 nla_nest_end(skb, data);
10764 genlmsg_end(skb, hdr);
10765 return genlmsg_reply(skb, rdev->cur_cmd_info);
10766}
10767EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10768
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010769static int nl80211_set_qos_map(struct sk_buff *skb,
10770 struct genl_info *info)
10771{
10772 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10773 struct cfg80211_qos_map *qos_map = NULL;
10774 struct net_device *dev = info->user_ptr[1];
10775 u8 *pos, len, num_des, des_len, des;
10776 int ret;
10777
10778 if (!rdev->ops->set_qos_map)
10779 return -EOPNOTSUPP;
10780
10781 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10782 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10783 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10784
10785 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10786 len > IEEE80211_QOS_MAP_LEN_MAX)
10787 return -EINVAL;
10788
10789 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10790 if (!qos_map)
10791 return -ENOMEM;
10792
10793 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10794 if (num_des) {
10795 des_len = num_des *
10796 sizeof(struct cfg80211_dscp_exception);
10797 memcpy(qos_map->dscp_exception, pos, des_len);
10798 qos_map->num_des = num_des;
10799 for (des = 0; des < num_des; des++) {
10800 if (qos_map->dscp_exception[des].up > 7) {
10801 kfree(qos_map);
10802 return -EINVAL;
10803 }
10804 }
10805 pos += des_len;
10806 }
10807 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10808 }
10809
10810 wdev_lock(dev->ieee80211_ptr);
10811 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10812 if (!ret)
10813 ret = rdev_set_qos_map(rdev, dev, qos_map);
10814 wdev_unlock(dev->ieee80211_ptr);
10815
10816 kfree(qos_map);
10817 return ret;
10818}
10819
Johannes Berg960d01a2014-09-09 22:55:35 +030010820static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10821{
10822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10823 struct net_device *dev = info->user_ptr[1];
10824 struct wireless_dev *wdev = dev->ieee80211_ptr;
10825 const u8 *peer;
10826 u8 tsid, up;
10827 u16 admitted_time = 0;
10828 int err;
10829
Johannes Berg723e73a2014-10-22 09:25:06 +020010830 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010831 return -EOPNOTSUPP;
10832
10833 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10834 !info->attrs[NL80211_ATTR_USER_PRIO])
10835 return -EINVAL;
10836
10837 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10838 if (tsid >= IEEE80211_NUM_TIDS)
10839 return -EINVAL;
10840
10841 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10842 if (up >= IEEE80211_NUM_UPS)
10843 return -EINVAL;
10844
10845 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010846 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010847 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010848 * need more attributes for that (e.g. BA session requirement);
10849 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010850 */
10851 return -EINVAL;
10852 }
10853
10854 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10855
10856 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10857 admitted_time =
10858 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10859 if (!admitted_time)
10860 return -EINVAL;
10861 }
10862
10863 wdev_lock(wdev);
10864 switch (wdev->iftype) {
10865 case NL80211_IFTYPE_STATION:
10866 case NL80211_IFTYPE_P2P_CLIENT:
10867 if (wdev->current_bss)
10868 break;
10869 err = -ENOTCONN;
10870 goto out;
10871 default:
10872 err = -EOPNOTSUPP;
10873 goto out;
10874 }
10875
10876 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10877
10878 out:
10879 wdev_unlock(wdev);
10880 return err;
10881}
10882
10883static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10884{
10885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10886 struct net_device *dev = info->user_ptr[1];
10887 struct wireless_dev *wdev = dev->ieee80211_ptr;
10888 const u8 *peer;
10889 u8 tsid;
10890 int err;
10891
10892 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10893 return -EINVAL;
10894
10895 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10896 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10897
10898 wdev_lock(wdev);
10899 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10900 wdev_unlock(wdev);
10901
10902 return err;
10903}
10904
Arik Nemtsov1057d352014-11-19 12:54:26 +020010905static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10906 struct genl_info *info)
10907{
10908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10909 struct net_device *dev = info->user_ptr[1];
10910 struct wireless_dev *wdev = dev->ieee80211_ptr;
10911 struct cfg80211_chan_def chandef = {};
10912 const u8 *addr;
10913 u8 oper_class;
10914 int err;
10915
10916 if (!rdev->ops->tdls_channel_switch ||
10917 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10918 return -EOPNOTSUPP;
10919
10920 switch (dev->ieee80211_ptr->iftype) {
10921 case NL80211_IFTYPE_STATION:
10922 case NL80211_IFTYPE_P2P_CLIENT:
10923 break;
10924 default:
10925 return -EOPNOTSUPP;
10926 }
10927
10928 if (!info->attrs[NL80211_ATTR_MAC] ||
10929 !info->attrs[NL80211_ATTR_OPER_CLASS])
10930 return -EINVAL;
10931
10932 err = nl80211_parse_chandef(rdev, info, &chandef);
10933 if (err)
10934 return err;
10935
10936 /*
10937 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10938 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10939 * specification is not defined for them.
10940 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010941 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010942 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10943 chandef.width != NL80211_CHAN_WIDTH_20)
10944 return -EINVAL;
10945
10946 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010947 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10948 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010949 return -EINVAL;
10950
10951 /* don't allow switching to DFS channels */
10952 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10953 return -EINVAL;
10954
10955 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10956 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10957
10958 wdev_lock(wdev);
10959 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10960 wdev_unlock(wdev);
10961
10962 return err;
10963}
10964
10965static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10966 struct genl_info *info)
10967{
10968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10969 struct net_device *dev = info->user_ptr[1];
10970 struct wireless_dev *wdev = dev->ieee80211_ptr;
10971 const u8 *addr;
10972
10973 if (!rdev->ops->tdls_channel_switch ||
10974 !rdev->ops->tdls_cancel_channel_switch ||
10975 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10976 return -EOPNOTSUPP;
10977
10978 switch (dev->ieee80211_ptr->iftype) {
10979 case NL80211_IFTYPE_STATION:
10980 case NL80211_IFTYPE_P2P_CLIENT:
10981 break;
10982 default:
10983 return -EOPNOTSUPP;
10984 }
10985
10986 if (!info->attrs[NL80211_ATTR_MAC])
10987 return -EINVAL;
10988
10989 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10990
10991 wdev_lock(wdev);
10992 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10993 wdev_unlock(wdev);
10994
10995 return 0;
10996}
10997
Johannes Berg4c476992010-10-04 21:36:35 +020010998#define NL80211_FLAG_NEED_WIPHY 0x01
10999#define NL80211_FLAG_NEED_NETDEV 0x02
11000#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011001#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11002#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11003 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011004#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011005/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011006#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11007 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011008#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011009
Johannes Bergf84f7712013-11-14 17:14:45 +010011010static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011011 struct genl_info *info)
11012{
11013 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011014 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011015 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011016 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11017
11018 if (rtnl)
11019 rtnl_lock();
11020
11021 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011022 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011023 if (IS_ERR(rdev)) {
11024 if (rtnl)
11025 rtnl_unlock();
11026 return PTR_ERR(rdev);
11027 }
11028 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011029 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11030 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011031 ASSERT_RTNL();
11032
Johannes Berg89a54e42012-06-15 14:33:17 +020011033 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11034 info->attrs);
11035 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011036 if (rtnl)
11037 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011038 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011039 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011040
Johannes Berg89a54e42012-06-15 14:33:17 +020011041 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011042 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011043
Johannes Berg1bf614e2012-06-15 15:23:36 +020011044 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11045 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011046 if (rtnl)
11047 rtnl_unlock();
11048 return -EINVAL;
11049 }
11050
11051 info->user_ptr[1] = dev;
11052 } else {
11053 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011054 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011055
Johannes Berg1bf614e2012-06-15 15:23:36 +020011056 if (dev) {
11057 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11058 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011059 if (rtnl)
11060 rtnl_unlock();
11061 return -ENETDOWN;
11062 }
11063
11064 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011065 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
11066 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020011067 if (rtnl)
11068 rtnl_unlock();
11069 return -ENETDOWN;
11070 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020011071 }
11072
Johannes Berg4c476992010-10-04 21:36:35 +020011073 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011074 }
11075
11076 return 0;
11077}
11078
Johannes Bergf84f7712013-11-14 17:14:45 +010011079static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011080 struct genl_info *info)
11081{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011082 if (info->user_ptr[1]) {
11083 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11084 struct wireless_dev *wdev = info->user_ptr[1];
11085
11086 if (wdev->netdev)
11087 dev_put(wdev->netdev);
11088 } else {
11089 dev_put(info->user_ptr[1]);
11090 }
11091 }
Johannes Berg5393b912014-09-10 15:00:16 +030011092
Johannes Berg4c476992010-10-04 21:36:35 +020011093 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11094 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011095
11096 /* If needed, clear the netlink message payload from the SKB
11097 * as it might contain key data that shouldn't stick around on
11098 * the heap after the SKB is freed. The netlink message header
11099 * is still needed for further processing, so leave it intact.
11100 */
11101 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11102 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11103
11104 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11105 }
Johannes Berg4c476992010-10-04 21:36:35 +020011106}
11107
Johannes Berg4534de82013-11-14 17:14:46 +010011108static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011109 {
11110 .cmd = NL80211_CMD_GET_WIPHY,
11111 .doit = nl80211_get_wiphy,
11112 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011113 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011114 .policy = nl80211_policy,
11115 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011116 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11117 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011118 },
11119 {
11120 .cmd = NL80211_CMD_SET_WIPHY,
11121 .doit = nl80211_set_wiphy,
11122 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011123 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011124 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011125 },
11126 {
11127 .cmd = NL80211_CMD_GET_INTERFACE,
11128 .doit = nl80211_get_interface,
11129 .dumpit = nl80211_dump_interface,
11130 .policy = nl80211_policy,
11131 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011132 .internal_flags = NL80211_FLAG_NEED_WDEV |
11133 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011134 },
11135 {
11136 .cmd = NL80211_CMD_SET_INTERFACE,
11137 .doit = nl80211_set_interface,
11138 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011139 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011140 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11141 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011142 },
11143 {
11144 .cmd = NL80211_CMD_NEW_INTERFACE,
11145 .doit = nl80211_new_interface,
11146 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011147 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011148 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11149 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011150 },
11151 {
11152 .cmd = NL80211_CMD_DEL_INTERFACE,
11153 .doit = nl80211_del_interface,
11154 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011155 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011156 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011157 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011158 },
Johannes Berg41ade002007-12-19 02:03:29 +010011159 {
11160 .cmd = NL80211_CMD_GET_KEY,
11161 .doit = nl80211_get_key,
11162 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011163 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011165 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011166 },
11167 {
11168 .cmd = NL80211_CMD_SET_KEY,
11169 .doit = nl80211_set_key,
11170 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011171 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011173 NL80211_FLAG_NEED_RTNL |
11174 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011175 },
11176 {
11177 .cmd = NL80211_CMD_NEW_KEY,
11178 .doit = nl80211_new_key,
11179 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011180 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011181 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011182 NL80211_FLAG_NEED_RTNL |
11183 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011184 },
11185 {
11186 .cmd = NL80211_CMD_DEL_KEY,
11187 .doit = nl80211_del_key,
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,
Johannes Berg41ade002007-12-19 02:03:29 +010011192 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011193 {
11194 .cmd = NL80211_CMD_SET_BEACON,
11195 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011196 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011197 .doit = nl80211_set_beacon,
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,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011200 },
11201 {
Johannes Berg88600202012-02-13 15:17:18 +010011202 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011203 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011204 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011205 .doit = nl80211_start_ap,
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,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011208 },
11209 {
Johannes Berg88600202012-02-13 15:17:18 +010011210 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011211 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011212 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011213 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011214 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011215 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011216 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011217 {
11218 .cmd = NL80211_CMD_GET_STATION,
11219 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011220 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011221 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011222 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11223 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011224 },
11225 {
11226 .cmd = NL80211_CMD_SET_STATION,
11227 .doit = nl80211_set_station,
11228 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011229 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011231 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011232 },
11233 {
11234 .cmd = NL80211_CMD_NEW_STATION,
11235 .doit = nl80211_new_station,
11236 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011237 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011239 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011240 },
11241 {
11242 .cmd = NL80211_CMD_DEL_STATION,
11243 .doit = nl80211_del_station,
11244 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011245 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011247 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011248 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011249 {
11250 .cmd = NL80211_CMD_GET_MPATH,
11251 .doit = nl80211_get_mpath,
11252 .dumpit = nl80211_dump_mpath,
11253 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011254 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011255 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011256 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011257 },
11258 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011259 .cmd = NL80211_CMD_GET_MPP,
11260 .doit = nl80211_get_mpp,
11261 .dumpit = nl80211_dump_mpp,
11262 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011263 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011264 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11265 NL80211_FLAG_NEED_RTNL,
11266 },
11267 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011268 .cmd = NL80211_CMD_SET_MPATH,
11269 .doit = nl80211_set_mpath,
11270 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011271 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011272 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011273 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011274 },
11275 {
11276 .cmd = NL80211_CMD_NEW_MPATH,
11277 .doit = nl80211_new_mpath,
11278 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011279 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011280 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011281 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011282 },
11283 {
11284 .cmd = NL80211_CMD_DEL_MPATH,
11285 .doit = nl80211_del_mpath,
11286 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011287 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011288 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011289 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011290 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011291 {
11292 .cmd = NL80211_CMD_SET_BSS,
11293 .doit = nl80211_set_bss,
11294 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011295 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011296 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011297 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011298 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011299 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011300 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011301 .doit = nl80211_get_reg_do,
11302 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011303 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011304 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011305 /* can be retrieved by unprivileged users */
11306 },
Johannes Bergb6863032015-10-15 09:25:18 +020011307#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011308 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011309 .cmd = NL80211_CMD_SET_REG,
11310 .doit = nl80211_set_reg,
11311 .policy = nl80211_policy,
11312 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011313 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011314 },
Johannes Bergb6863032015-10-15 09:25:18 +020011315#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011316 {
11317 .cmd = NL80211_CMD_REQ_SET_REG,
11318 .doit = nl80211_req_set_reg,
11319 .policy = nl80211_policy,
11320 .flags = GENL_ADMIN_PERM,
11321 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011322 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011323 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11324 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011325 .policy = nl80211_policy,
11326 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011327 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011328 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011329 },
11330 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011331 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11332 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011333 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011334 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011335 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011336 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011337 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011338 {
Johannes Berg2a519312009-02-10 21:25:55 +010011339 .cmd = NL80211_CMD_TRIGGER_SCAN,
11340 .doit = nl80211_trigger_scan,
11341 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011342 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011343 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011344 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011345 },
11346 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011347 .cmd = NL80211_CMD_ABORT_SCAN,
11348 .doit = nl80211_abort_scan,
11349 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011350 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011351 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11352 NL80211_FLAG_NEED_RTNL,
11353 },
11354 {
Johannes Berg2a519312009-02-10 21:25:55 +010011355 .cmd = NL80211_CMD_GET_SCAN,
11356 .policy = nl80211_policy,
11357 .dumpit = nl80211_dump_scan,
11358 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011359 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011360 .cmd = NL80211_CMD_START_SCHED_SCAN,
11361 .doit = nl80211_start_sched_scan,
11362 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011363 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011364 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11365 NL80211_FLAG_NEED_RTNL,
11366 },
11367 {
11368 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11369 .doit = nl80211_stop_sched_scan,
11370 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011371 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011372 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11373 NL80211_FLAG_NEED_RTNL,
11374 },
11375 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011376 .cmd = NL80211_CMD_AUTHENTICATE,
11377 .doit = nl80211_authenticate,
11378 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011379 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011380 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011381 NL80211_FLAG_NEED_RTNL |
11382 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011383 },
11384 {
11385 .cmd = NL80211_CMD_ASSOCIATE,
11386 .doit = nl80211_associate,
11387 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011388 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011389 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011390 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011391 },
11392 {
11393 .cmd = NL80211_CMD_DEAUTHENTICATE,
11394 .doit = nl80211_deauthenticate,
11395 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011396 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011398 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011399 },
11400 {
11401 .cmd = NL80211_CMD_DISASSOCIATE,
11402 .doit = nl80211_disassociate,
11403 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011404 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011406 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011407 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011408 {
11409 .cmd = NL80211_CMD_JOIN_IBSS,
11410 .doit = nl80211_join_ibss,
11411 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011412 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011413 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011414 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011415 },
11416 {
11417 .cmd = NL80211_CMD_LEAVE_IBSS,
11418 .doit = nl80211_leave_ibss,
11419 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011420 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011421 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011422 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011423 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011424#ifdef CONFIG_NL80211_TESTMODE
11425 {
11426 .cmd = NL80211_CMD_TESTMODE,
11427 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011428 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011429 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011430 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011431 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11432 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011433 },
11434#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011435 {
11436 .cmd = NL80211_CMD_CONNECT,
11437 .doit = nl80211_connect,
11438 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011439 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011440 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011441 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011442 },
11443 {
11444 .cmd = NL80211_CMD_DISCONNECT,
11445 .doit = nl80211_disconnect,
11446 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011447 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011448 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011449 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011450 },
Johannes Berg463d0182009-07-14 00:33:35 +020011451 {
11452 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11453 .doit = nl80211_wiphy_netns,
11454 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011455 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011456 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11457 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011458 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011459 {
11460 .cmd = NL80211_CMD_GET_SURVEY,
11461 .policy = nl80211_policy,
11462 .dumpit = nl80211_dump_survey,
11463 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011464 {
11465 .cmd = NL80211_CMD_SET_PMKSA,
11466 .doit = nl80211_setdel_pmksa,
11467 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011468 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011470 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011471 },
11472 {
11473 .cmd = NL80211_CMD_DEL_PMKSA,
11474 .doit = nl80211_setdel_pmksa,
11475 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011476 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011477 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011478 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011479 },
11480 {
11481 .cmd = NL80211_CMD_FLUSH_PMKSA,
11482 .doit = nl80211_flush_pmksa,
11483 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011484 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011485 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011486 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011487 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011488 {
11489 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11490 .doit = nl80211_remain_on_channel,
11491 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011492 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011493 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011494 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011495 },
11496 {
11497 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11498 .doit = nl80211_cancel_remain_on_channel,
11499 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011500 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011501 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011502 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011503 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011504 {
11505 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11506 .doit = nl80211_set_tx_bitrate_mask,
11507 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011508 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011509 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11510 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011511 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011512 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011513 .cmd = NL80211_CMD_REGISTER_FRAME,
11514 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011515 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011516 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011517 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011518 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011519 },
11520 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011521 .cmd = NL80211_CMD_FRAME,
11522 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011523 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011524 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011525 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011526 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011527 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011528 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011529 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11530 .doit = nl80211_tx_mgmt_cancel_wait,
11531 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011532 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011533 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011534 NL80211_FLAG_NEED_RTNL,
11535 },
11536 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011537 .cmd = NL80211_CMD_SET_POWER_SAVE,
11538 .doit = nl80211_set_power_save,
11539 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011540 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011541 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11542 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011543 },
11544 {
11545 .cmd = NL80211_CMD_GET_POWER_SAVE,
11546 .doit = nl80211_get_power_save,
11547 .policy = nl80211_policy,
11548 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011549 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11550 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011551 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011552 {
11553 .cmd = NL80211_CMD_SET_CQM,
11554 .doit = nl80211_set_cqm,
11555 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011556 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011557 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11558 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011559 },
Johannes Bergf444de02010-05-05 15:25:02 +020011560 {
11561 .cmd = NL80211_CMD_SET_CHANNEL,
11562 .doit = nl80211_set_channel,
11563 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011564 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011565 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11566 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011567 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011568 {
11569 .cmd = NL80211_CMD_SET_WDS_PEER,
11570 .doit = nl80211_set_wds_peer,
11571 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011572 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011573 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11574 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011575 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011576 {
11577 .cmd = NL80211_CMD_JOIN_MESH,
11578 .doit = nl80211_join_mesh,
11579 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011580 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11582 NL80211_FLAG_NEED_RTNL,
11583 },
11584 {
11585 .cmd = NL80211_CMD_LEAVE_MESH,
11586 .doit = nl80211_leave_mesh,
11587 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011588 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11590 NL80211_FLAG_NEED_RTNL,
11591 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011592 {
11593 .cmd = NL80211_CMD_JOIN_OCB,
11594 .doit = nl80211_join_ocb,
11595 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011596 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11598 NL80211_FLAG_NEED_RTNL,
11599 },
11600 {
11601 .cmd = NL80211_CMD_LEAVE_OCB,
11602 .doit = nl80211_leave_ocb,
11603 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011604 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11606 NL80211_FLAG_NEED_RTNL,
11607 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011608#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011609 {
11610 .cmd = NL80211_CMD_GET_WOWLAN,
11611 .doit = nl80211_get_wowlan,
11612 .policy = nl80211_policy,
11613 /* can be retrieved by unprivileged users */
11614 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11615 NL80211_FLAG_NEED_RTNL,
11616 },
11617 {
11618 .cmd = NL80211_CMD_SET_WOWLAN,
11619 .doit = nl80211_set_wowlan,
11620 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011621 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011622 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11623 NL80211_FLAG_NEED_RTNL,
11624 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011625#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011626 {
11627 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11628 .doit = nl80211_set_rekey_data,
11629 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011630 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011631 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011632 NL80211_FLAG_NEED_RTNL |
11633 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011634 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011635 {
11636 .cmd = NL80211_CMD_TDLS_MGMT,
11637 .doit = nl80211_tdls_mgmt,
11638 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011639 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011640 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11641 NL80211_FLAG_NEED_RTNL,
11642 },
11643 {
11644 .cmd = NL80211_CMD_TDLS_OPER,
11645 .doit = nl80211_tdls_oper,
11646 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011647 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011648 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11649 NL80211_FLAG_NEED_RTNL,
11650 },
Johannes Berg28946da2011-11-04 11:18:12 +010011651 {
11652 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11653 .doit = nl80211_register_unexpected_frame,
11654 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011655 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011656 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11657 NL80211_FLAG_NEED_RTNL,
11658 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011659 {
11660 .cmd = NL80211_CMD_PROBE_CLIENT,
11661 .doit = nl80211_probe_client,
11662 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011663 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011664 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011665 NL80211_FLAG_NEED_RTNL,
11666 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011667 {
11668 .cmd = NL80211_CMD_REGISTER_BEACONS,
11669 .doit = nl80211_register_beacons,
11670 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011671 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010011672 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11673 NL80211_FLAG_NEED_RTNL,
11674 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011675 {
11676 .cmd = NL80211_CMD_SET_NOACK_MAP,
11677 .doit = nl80211_set_noack_map,
11678 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011679 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011680 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11681 NL80211_FLAG_NEED_RTNL,
11682 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011683 {
11684 .cmd = NL80211_CMD_START_P2P_DEVICE,
11685 .doit = nl80211_start_p2p_device,
11686 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011687 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011688 .internal_flags = NL80211_FLAG_NEED_WDEV |
11689 NL80211_FLAG_NEED_RTNL,
11690 },
11691 {
11692 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11693 .doit = nl80211_stop_p2p_device,
11694 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011695 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011696 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11697 NL80211_FLAG_NEED_RTNL,
11698 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011699 {
11700 .cmd = NL80211_CMD_SET_MCAST_RATE,
11701 .doit = nl80211_set_mcast_rate,
11702 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011703 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011704 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11705 NL80211_FLAG_NEED_RTNL,
11706 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011707 {
11708 .cmd = NL80211_CMD_SET_MAC_ACL,
11709 .doit = nl80211_set_mac_acl,
11710 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011711 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011712 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11713 NL80211_FLAG_NEED_RTNL,
11714 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011715 {
11716 .cmd = NL80211_CMD_RADAR_DETECT,
11717 .doit = nl80211_start_radar_detection,
11718 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011719 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011720 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11721 NL80211_FLAG_NEED_RTNL,
11722 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011723 {
11724 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11725 .doit = nl80211_get_protocol_features,
11726 .policy = nl80211_policy,
11727 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011728 {
11729 .cmd = NL80211_CMD_UPDATE_FT_IES,
11730 .doit = nl80211_update_ft_ies,
11731 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011732 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011733 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11734 NL80211_FLAG_NEED_RTNL,
11735 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011736 {
11737 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11738 .doit = nl80211_crit_protocol_start,
11739 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011740 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011741 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11742 NL80211_FLAG_NEED_RTNL,
11743 },
11744 {
11745 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11746 .doit = nl80211_crit_protocol_stop,
11747 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011748 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011749 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11750 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011751 },
11752 {
11753 .cmd = NL80211_CMD_GET_COALESCE,
11754 .doit = nl80211_get_coalesce,
11755 .policy = nl80211_policy,
11756 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11757 NL80211_FLAG_NEED_RTNL,
11758 },
11759 {
11760 .cmd = NL80211_CMD_SET_COALESCE,
11761 .doit = nl80211_set_coalesce,
11762 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011763 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011764 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11765 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011766 },
11767 {
11768 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11769 .doit = nl80211_channel_switch,
11770 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011771 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11773 NL80211_FLAG_NEED_RTNL,
11774 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011775 {
11776 .cmd = NL80211_CMD_VENDOR,
11777 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011778 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011779 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011780 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011781 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11782 NL80211_FLAG_NEED_RTNL,
11783 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011784 {
11785 .cmd = NL80211_CMD_SET_QOS_MAP,
11786 .doit = nl80211_set_qos_map,
11787 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011788 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11790 NL80211_FLAG_NEED_RTNL,
11791 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011792 {
11793 .cmd = NL80211_CMD_ADD_TX_TS,
11794 .doit = nl80211_add_tx_ts,
11795 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011796 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011797 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11798 NL80211_FLAG_NEED_RTNL,
11799 },
11800 {
11801 .cmd = NL80211_CMD_DEL_TX_TS,
11802 .doit = nl80211_del_tx_ts,
11803 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011804 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011805 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11806 NL80211_FLAG_NEED_RTNL,
11807 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011808 {
11809 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11810 .doit = nl80211_tdls_channel_switch,
11811 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011812 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011813 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11814 NL80211_FLAG_NEED_RTNL,
11815 },
11816 {
11817 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11818 .doit = nl80211_tdls_cancel_channel_switch,
11819 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011820 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011821 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11822 NL80211_FLAG_NEED_RTNL,
11823 },
Johannes Berg55682962007-09-20 13:09:35 -040011824};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011825
Johannes Berg55682962007-09-20 13:09:35 -040011826/* notification functions */
11827
Johannes Berg3bb20552014-05-26 13:52:25 +020011828void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11829 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011830{
11831 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011832 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011833
Johannes Berg3bb20552014-05-26 13:52:25 +020011834 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11835 cmd != NL80211_CMD_DEL_WIPHY);
11836
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011837 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011838 if (!msg)
11839 return;
11840
Johannes Berg3bb20552014-05-26 13:52:25 +020011841 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011842 nlmsg_free(msg);
11843 return;
11844 }
11845
Johannes Berg68eb5502013-11-19 15:19:38 +010011846 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011847 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011848}
11849
Johannes Berg362a4152009-05-24 16:43:15 +020011850static int nl80211_add_scan_req(struct sk_buff *msg,
11851 struct cfg80211_registered_device *rdev)
11852{
11853 struct cfg80211_scan_request *req = rdev->scan_req;
11854 struct nlattr *nest;
11855 int i;
11856
11857 if (WARN_ON(!req))
11858 return 0;
11859
11860 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11861 if (!nest)
11862 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011863 for (i = 0; i < req->n_ssids; i++) {
11864 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11865 goto nla_put_failure;
11866 }
Johannes Berg362a4152009-05-24 16:43:15 +020011867 nla_nest_end(msg, nest);
11868
11869 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11870 if (!nest)
11871 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011872 for (i = 0; i < req->n_channels; i++) {
11873 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11874 goto nla_put_failure;
11875 }
Johannes Berg362a4152009-05-24 16:43:15 +020011876 nla_nest_end(msg, nest);
11877
David S. Miller9360ffd2012-03-29 04:41:26 -040011878 if (req->ie &&
11879 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11880 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011881
Johannes Bergae917c92013-10-25 11:05:22 +020011882 if (req->flags &&
11883 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11884 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011885
Avraham Stern1d762502016-07-05 17:10:13 +030011886 if (req->info.scan_start_tsf &&
11887 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
11888 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
11889 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
11890 req->info.tsf_bssid)))
11891 goto nla_put_failure;
11892
Johannes Berg362a4152009-05-24 16:43:15 +020011893 return 0;
11894 nla_put_failure:
11895 return -ENOBUFS;
11896}
11897
Johannes Berga538e2d2009-06-16 19:56:42 +020011898static int nl80211_send_scan_msg(struct sk_buff *msg,
11899 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011900 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011901 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011902 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011903{
11904 void *hdr;
11905
Eric W. Biederman15e47302012-09-07 20:12:54 +000011906 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011907 if (!hdr)
11908 return -1;
11909
David S. Miller9360ffd2012-03-29 04:41:26 -040011910 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011911 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11912 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011913 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11914 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011915 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011916
Johannes Berg362a4152009-05-24 16:43:15 +020011917 /* ignore errors and send incomplete event anyway */
11918 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011919
Johannes Berg053c0952015-01-16 22:09:00 +010011920 genlmsg_end(msg, hdr);
11921 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011922
11923 nla_put_failure:
11924 genlmsg_cancel(msg, hdr);
11925 return -EMSGSIZE;
11926}
11927
Luciano Coelho807f8a82011-05-11 17:09:35 +030011928static int
11929nl80211_send_sched_scan_msg(struct sk_buff *msg,
11930 struct cfg80211_registered_device *rdev,
11931 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011932 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011933{
11934 void *hdr;
11935
Eric W. Biederman15e47302012-09-07 20:12:54 +000011936 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011937 if (!hdr)
11938 return -1;
11939
David S. Miller9360ffd2012-03-29 04:41:26 -040011940 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11941 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11942 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011943
Johannes Berg053c0952015-01-16 22:09:00 +010011944 genlmsg_end(msg, hdr);
11945 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011946
11947 nla_put_failure:
11948 genlmsg_cancel(msg, hdr);
11949 return -EMSGSIZE;
11950}
11951
Johannes Berga538e2d2009-06-16 19:56:42 +020011952void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011953 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011954{
11955 struct sk_buff *msg;
11956
Thomas Graf58050fc2012-06-28 03:57:45 +000011957 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011958 if (!msg)
11959 return;
11960
Johannes Bergfd014282012-06-18 19:17:03 +020011961 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011962 NL80211_CMD_TRIGGER_SCAN) < 0) {
11963 nlmsg_free(msg);
11964 return;
11965 }
11966
Johannes Berg68eb5502013-11-19 15:19:38 +010011967 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011968 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011969}
11970
Johannes Bergf9d15d12014-01-22 11:14:19 +020011971struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11972 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011973{
11974 struct sk_buff *msg;
11975
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011976 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011977 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011978 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011979
Johannes Bergfd014282012-06-18 19:17:03 +020011980 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011981 aborted ? NL80211_CMD_SCAN_ABORTED :
11982 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011983 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011984 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011985 }
11986
Johannes Bergf9d15d12014-01-22 11:14:19 +020011987 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011988}
11989
Johannes Bergf9d15d12014-01-22 11:14:19 +020011990void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11991 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011992{
Johannes Berg2a519312009-02-10 21:25:55 +010011993 if (!msg)
11994 return;
11995
Johannes Berg68eb5502013-11-19 15:19:38 +010011996 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011997 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011998}
11999
Luciano Coelho807f8a82011-05-11 17:09:35 +030012000void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12001 struct net_device *netdev)
12002{
12003 struct sk_buff *msg;
12004
12005 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12006 if (!msg)
12007 return;
12008
12009 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12010 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12011 nlmsg_free(msg);
12012 return;
12013 }
12014
Johannes Berg68eb5502013-11-19 15:19:38 +010012015 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012016 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012017}
12018
12019void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12020 struct net_device *netdev, u32 cmd)
12021{
12022 struct sk_buff *msg;
12023
Thomas Graf58050fc2012-06-28 03:57:45 +000012024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012025 if (!msg)
12026 return;
12027
12028 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12029 nlmsg_free(msg);
12030 return;
12031 }
12032
Johannes Berg68eb5502013-11-19 15:19:38 +010012033 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012034 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012035}
12036
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012037static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12038 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012039{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012040 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012041 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12042 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012043
David S. Miller9360ffd2012-03-29 04:41:26 -040012044 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12045 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12046 NL80211_REGDOM_TYPE_WORLD))
12047 goto nla_put_failure;
12048 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12049 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12050 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12051 goto nla_put_failure;
12052 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12053 request->intersect) {
12054 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12055 NL80211_REGDOM_TYPE_INTERSECTION))
12056 goto nla_put_failure;
12057 } else {
12058 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12059 NL80211_REGDOM_TYPE_COUNTRY) ||
12060 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12061 request->alpha2))
12062 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012063 }
12064
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012065 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12066 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12067
12068 if (wiphy &&
12069 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12070 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012071
12072 if (wiphy &&
12073 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12074 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12075 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012076 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012077
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012078 return true;
12079
12080nla_put_failure:
12081 return false;
12082}
12083
12084/*
12085 * This can happen on global regulatory changes or device specific settings
12086 * based on custom regulatory domains.
12087 */
12088void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12089 struct regulatory_request *request)
12090{
12091 struct sk_buff *msg;
12092 void *hdr;
12093
12094 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12095 if (!msg)
12096 return;
12097
12098 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12099 if (!hdr) {
12100 nlmsg_free(msg);
12101 return;
12102 }
12103
12104 if (nl80211_reg_change_event_fill(msg, request) == false)
12105 goto nla_put_failure;
12106
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012107 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012108
Johannes Bergbc43b282009-07-25 10:54:13 +020012109 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012110 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012111 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012112 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012113
12114 return;
12115
12116nla_put_failure:
12117 genlmsg_cancel(msg, hdr);
12118 nlmsg_free(msg);
12119}
12120
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012121static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12122 struct net_device *netdev,
12123 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012124 enum nl80211_commands cmd, gfp_t gfp,
12125 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012126{
12127 struct sk_buff *msg;
12128 void *hdr;
12129
Johannes Berge6d6e342009-07-01 21:26:47 +020012130 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012131 if (!msg)
12132 return;
12133
12134 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12135 if (!hdr) {
12136 nlmsg_free(msg);
12137 return;
12138 }
12139
David S. Miller9360ffd2012-03-29 04:41:26 -040012140 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12141 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12142 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12143 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012144
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012145 if (uapsd_queues >= 0) {
12146 struct nlattr *nla_wmm =
12147 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12148 if (!nla_wmm)
12149 goto nla_put_failure;
12150
12151 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12152 uapsd_queues))
12153 goto nla_put_failure;
12154
12155 nla_nest_end(msg, nla_wmm);
12156 }
12157
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012158 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012159
Johannes Berg68eb5502013-11-19 15:19:38 +010012160 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012161 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012162 return;
12163
12164 nla_put_failure:
12165 genlmsg_cancel(msg, hdr);
12166 nlmsg_free(msg);
12167}
12168
12169void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012170 struct net_device *netdev, const u8 *buf,
12171 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012172{
12173 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012174 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012175}
12176
12177void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12178 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012179 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012180{
Johannes Berge6d6e342009-07-01 21:26:47 +020012181 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012182 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012183}
12184
Jouni Malinen53b46b82009-03-27 20:53:56 +020012185void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012186 struct net_device *netdev, const u8 *buf,
12187 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012188{
12189 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012190 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012191}
12192
Jouni Malinen53b46b82009-03-27 20:53:56 +020012193void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12194 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012195 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012196{
12197 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012198 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012199}
12200
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012201void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12202 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012203{
Johannes Berg947add32013-02-22 22:05:20 +010012204 struct wireless_dev *wdev = dev->ieee80211_ptr;
12205 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012206 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012207 const struct ieee80211_mgmt *mgmt = (void *)buf;
12208 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012209
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012210 if (WARN_ON(len < 2))
12211 return;
12212
12213 if (ieee80211_is_deauth(mgmt->frame_control))
12214 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12215 else
12216 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12217
12218 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012219 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012220}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012221EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012222
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012223static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12224 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012225 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012226{
12227 struct sk_buff *msg;
12228 void *hdr;
12229
Johannes Berge6d6e342009-07-01 21:26:47 +020012230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012231 if (!msg)
12232 return;
12233
12234 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12235 if (!hdr) {
12236 nlmsg_free(msg);
12237 return;
12238 }
12239
David S. Miller9360ffd2012-03-29 04:41:26 -040012240 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12242 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12243 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12244 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012245
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012246 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012247
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);
Jouni Malinen1965c852009-04-22 21:38:25 +030012250 return;
12251
12252 nla_put_failure:
12253 genlmsg_cancel(msg, hdr);
12254 nlmsg_free(msg);
12255}
12256
12257void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012258 struct net_device *netdev, const u8 *addr,
12259 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012260{
12261 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012262 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012263}
12264
12265void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012266 struct net_device *netdev, const u8 *addr,
12267 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012268{
Johannes Berge6d6e342009-07-01 21:26:47 +020012269 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12270 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012271}
12272
Samuel Ortizb23aa672009-07-01 21:26:54 +020012273void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12274 struct net_device *netdev, const u8 *bssid,
12275 const u8 *req_ie, size_t req_ie_len,
12276 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012277 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012278{
12279 struct sk_buff *msg;
12280 void *hdr;
12281
Thomas Graf58050fc2012-06-28 03:57:45 +000012282 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012283 if (!msg)
12284 return;
12285
12286 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12287 if (!hdr) {
12288 nlmsg_free(msg);
12289 return;
12290 }
12291
David S. Miller9360ffd2012-03-29 04:41:26 -040012292 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12293 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12294 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012295 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12296 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12297 status) ||
12298 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012299 (req_ie &&
12300 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12301 (resp_ie &&
12302 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12303 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012304
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012305 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012306
Johannes Berg68eb5502013-11-19 15:19:38 +010012307 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012308 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012309 return;
12310
12311 nla_put_failure:
12312 genlmsg_cancel(msg, hdr);
12313 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012314}
12315
12316void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12317 struct net_device *netdev, const u8 *bssid,
12318 const u8 *req_ie, size_t req_ie_len,
12319 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12320{
12321 struct sk_buff *msg;
12322 void *hdr;
12323
Thomas Graf58050fc2012-06-28 03:57:45 +000012324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012325 if (!msg)
12326 return;
12327
12328 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12329 if (!hdr) {
12330 nlmsg_free(msg);
12331 return;
12332 }
12333
David S. Miller9360ffd2012-03-29 04:41:26 -040012334 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12335 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12336 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12337 (req_ie &&
12338 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12339 (resp_ie &&
12340 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12341 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012342
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012343 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012344
Johannes Berg68eb5502013-11-19 15:19:38 +010012345 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012346 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012347 return;
12348
12349 nla_put_failure:
12350 genlmsg_cancel(msg, hdr);
12351 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012352}
12353
12354void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12355 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012356 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012357{
12358 struct sk_buff *msg;
12359 void *hdr;
12360
Thomas Graf58050fc2012-06-28 03:57:45 +000012361 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012362 if (!msg)
12363 return;
12364
12365 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12366 if (!hdr) {
12367 nlmsg_free(msg);
12368 return;
12369 }
12370
David S. Miller9360ffd2012-03-29 04:41:26 -040012371 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12372 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12373 (from_ap && reason &&
12374 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12375 (from_ap &&
12376 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12377 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12378 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012379
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012380 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012381
Johannes Berg68eb5502013-11-19 15:19:38 +010012382 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012383 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012384 return;
12385
12386 nla_put_failure:
12387 genlmsg_cancel(msg, hdr);
12388 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012389}
12390
Johannes Berg04a773a2009-04-19 21:24:32 +020012391void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12392 struct net_device *netdev, const u8 *bssid,
12393 gfp_t gfp)
12394{
12395 struct sk_buff *msg;
12396 void *hdr;
12397
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012398 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012399 if (!msg)
12400 return;
12401
12402 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12403 if (!hdr) {
12404 nlmsg_free(msg);
12405 return;
12406 }
12407
David S. Miller9360ffd2012-03-29 04:41:26 -040012408 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12409 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12410 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12411 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012412
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012413 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012414
Johannes Berg68eb5502013-11-19 15:19:38 +010012415 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012416 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012417 return;
12418
12419 nla_put_failure:
12420 genlmsg_cancel(msg, hdr);
12421 nlmsg_free(msg);
12422}
12423
Johannes Berg947add32013-02-22 22:05:20 +010012424void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12425 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012426{
Johannes Berg947add32013-02-22 22:05:20 +010012427 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012428 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012429 struct sk_buff *msg;
12430 void *hdr;
12431
Johannes Berg947add32013-02-22 22:05:20 +010012432 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12433 return;
12434
12435 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12436
Javier Cardonac93b5e72011-04-07 15:08:34 -070012437 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12438 if (!msg)
12439 return;
12440
12441 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12442 if (!hdr) {
12443 nlmsg_free(msg);
12444 return;
12445 }
12446
David S. Miller9360ffd2012-03-29 04:41:26 -040012447 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012448 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12449 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012450 (ie_len && ie &&
12451 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12452 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012453
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012454 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012455
Johannes Berg68eb5502013-11-19 15:19:38 +010012456 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012457 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012458 return;
12459
12460 nla_put_failure:
12461 genlmsg_cancel(msg, hdr);
12462 nlmsg_free(msg);
12463}
Johannes Berg947add32013-02-22 22:05:20 +010012464EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012465
Jouni Malinena3b8b052009-03-27 21:59:49 +020012466void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12467 struct net_device *netdev, const u8 *addr,
12468 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012469 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012470{
12471 struct sk_buff *msg;
12472 void *hdr;
12473
Johannes Berge6d6e342009-07-01 21:26:47 +020012474 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012475 if (!msg)
12476 return;
12477
12478 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12479 if (!hdr) {
12480 nlmsg_free(msg);
12481 return;
12482 }
12483
David S. Miller9360ffd2012-03-29 04:41:26 -040012484 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12485 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12486 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12487 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12488 (key_id != -1 &&
12489 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12490 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12491 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012492
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012493 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012494
Johannes Berg68eb5502013-11-19 15:19:38 +010012495 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012496 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012497 return;
12498
12499 nla_put_failure:
12500 genlmsg_cancel(msg, hdr);
12501 nlmsg_free(msg);
12502}
12503
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012504void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12505 struct ieee80211_channel *channel_before,
12506 struct ieee80211_channel *channel_after)
12507{
12508 struct sk_buff *msg;
12509 void *hdr;
12510 struct nlattr *nl_freq;
12511
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012512 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012513 if (!msg)
12514 return;
12515
12516 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12517 if (!hdr) {
12518 nlmsg_free(msg);
12519 return;
12520 }
12521
12522 /*
12523 * Since we are applying the beacon hint to a wiphy we know its
12524 * wiphy_idx is valid
12525 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12527 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012528
12529 /* Before */
12530 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12531 if (!nl_freq)
12532 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012533 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012534 goto nla_put_failure;
12535 nla_nest_end(msg, nl_freq);
12536
12537 /* After */
12538 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12539 if (!nl_freq)
12540 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012541 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012542 goto nla_put_failure;
12543 nla_nest_end(msg, nl_freq);
12544
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012545 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012546
Johannes Berg463d0182009-07-14 00:33:35 +020012547 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012548 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012549 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012550 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012551
12552 return;
12553
12554nla_put_failure:
12555 genlmsg_cancel(msg, hdr);
12556 nlmsg_free(msg);
12557}
12558
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012559static void nl80211_send_remain_on_chan_event(
12560 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012561 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012562 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012563 unsigned int duration, gfp_t gfp)
12564{
12565 struct sk_buff *msg;
12566 void *hdr;
12567
12568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12569 if (!msg)
12570 return;
12571
12572 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12573 if (!hdr) {
12574 nlmsg_free(msg);
12575 return;
12576 }
12577
David S. Miller9360ffd2012-03-29 04:41:26 -040012578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012579 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12580 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012581 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12582 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012583 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012584 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12585 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012586 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12587 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012588 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012589
David S. Miller9360ffd2012-03-29 04:41:26 -040012590 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12591 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12592 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012593
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012594 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012595
Johannes Berg68eb5502013-11-19 15:19:38 +010012596 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012597 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012598 return;
12599
12600 nla_put_failure:
12601 genlmsg_cancel(msg, hdr);
12602 nlmsg_free(msg);
12603}
12604
Johannes Berg947add32013-02-22 22:05:20 +010012605void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12606 struct ieee80211_channel *chan,
12607 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012608{
Johannes Berg947add32013-02-22 22:05:20 +010012609 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012610 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012611
12612 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012613 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012614 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012615 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012616}
Johannes Berg947add32013-02-22 22:05:20 +010012617EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012618
Johannes Berg947add32013-02-22 22:05:20 +010012619void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12620 struct ieee80211_channel *chan,
12621 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012622{
Johannes Berg947add32013-02-22 22:05:20 +010012623 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012624 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012625
12626 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012627 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012628 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012629}
Johannes Berg947add32013-02-22 22:05:20 +010012630EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012631
Johannes Berg947add32013-02-22 22:05:20 +010012632void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12633 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012634{
Johannes Berg947add32013-02-22 22:05:20 +010012635 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012636 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012637 struct sk_buff *msg;
12638
Johannes Berg947add32013-02-22 22:05:20 +010012639 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12640
Thomas Graf58050fc2012-06-28 03:57:45 +000012641 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012642 if (!msg)
12643 return;
12644
Johannes Bergcf5ead82014-11-14 17:14:00 +010012645 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012646 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012647 nlmsg_free(msg);
12648 return;
12649 }
12650
Johannes Berg68eb5502013-11-19 15:19:38 +010012651 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012652 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012653}
Johannes Berg947add32013-02-22 22:05:20 +010012654EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012655
Johannes Bergcf5ead82014-11-14 17:14:00 +010012656void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12657 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012658{
Johannes Berg947add32013-02-22 22:05:20 +010012659 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012660 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012661 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012662 struct station_info empty_sinfo = {};
12663
12664 if (!sinfo)
12665 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012666
Johannes Berg947add32013-02-22 22:05:20 +010012667 trace_cfg80211_del_sta(dev, mac_addr);
12668
Thomas Graf58050fc2012-06-28 03:57:45 +000012669 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012670 if (!msg)
12671 return;
12672
Johannes Bergcf5ead82014-11-14 17:14:00 +010012673 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012674 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012675 nlmsg_free(msg);
12676 return;
12677 }
12678
Johannes Berg68eb5502013-11-19 15:19:38 +010012679 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012680 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012681}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012682EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012683
Johannes Berg947add32013-02-22 22:05:20 +010012684void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12685 enum nl80211_connect_failed_reason reason,
12686 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012687{
Johannes Berg947add32013-02-22 22:05:20 +010012688 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012689 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012690 struct sk_buff *msg;
12691 void *hdr;
12692
12693 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12694 if (!msg)
12695 return;
12696
12697 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12698 if (!hdr) {
12699 nlmsg_free(msg);
12700 return;
12701 }
12702
12703 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12704 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12705 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12706 goto nla_put_failure;
12707
12708 genlmsg_end(msg, hdr);
12709
Johannes Berg68eb5502013-11-19 15:19:38 +010012710 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012711 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012712 return;
12713
12714 nla_put_failure:
12715 genlmsg_cancel(msg, hdr);
12716 nlmsg_free(msg);
12717}
Johannes Berg947add32013-02-22 22:05:20 +010012718EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012719
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012720static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12721 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012722{
12723 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012724 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012725 struct sk_buff *msg;
12726 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012727 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012728
Eric W. Biederman15e47302012-09-07 20:12:54 +000012729 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012730 return false;
12731
12732 msg = nlmsg_new(100, gfp);
12733 if (!msg)
12734 return true;
12735
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012736 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012737 if (!hdr) {
12738 nlmsg_free(msg);
12739 return true;
12740 }
12741
David S. Miller9360ffd2012-03-29 04:41:26 -040012742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12743 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12744 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12745 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012746
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012747 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012748 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012749 return true;
12750
12751 nla_put_failure:
12752 genlmsg_cancel(msg, hdr);
12753 nlmsg_free(msg);
12754 return true;
12755}
12756
Johannes Berg947add32013-02-22 22:05:20 +010012757bool cfg80211_rx_spurious_frame(struct net_device *dev,
12758 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012759{
Johannes Berg947add32013-02-22 22:05:20 +010012760 struct wireless_dev *wdev = dev->ieee80211_ptr;
12761 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012762
Johannes Berg947add32013-02-22 22:05:20 +010012763 trace_cfg80211_rx_spurious_frame(dev, addr);
12764
12765 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12766 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12767 trace_cfg80211_return_bool(false);
12768 return false;
12769 }
12770 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12771 addr, gfp);
12772 trace_cfg80211_return_bool(ret);
12773 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012774}
Johannes Berg947add32013-02-22 22:05:20 +010012775EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12776
12777bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12778 const u8 *addr, gfp_t gfp)
12779{
12780 struct wireless_dev *wdev = dev->ieee80211_ptr;
12781 bool ret;
12782
12783 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12784
12785 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12786 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12787 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12788 trace_cfg80211_return_bool(false);
12789 return false;
12790 }
12791 ret = __nl80211_unexpected_frame(dev,
12792 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12793 addr, gfp);
12794 trace_cfg80211_return_bool(ret);
12795 return ret;
12796}
12797EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012798
Johannes Berg2e161f72010-08-12 15:38:38 +020012799int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012800 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012801 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012802 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012803{
Johannes Berg71bbc992012-06-15 15:30:18 +020012804 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012805 struct sk_buff *msg;
12806 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012807
12808 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12809 if (!msg)
12810 return -ENOMEM;
12811
Johannes Berg2e161f72010-08-12 15:38:38 +020012812 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012813 if (!hdr) {
12814 nlmsg_free(msg);
12815 return -ENOMEM;
12816 }
12817
David S. Miller9360ffd2012-03-29 04:41:26 -040012818 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012819 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12820 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012821 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12822 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012823 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12824 (sig_dbm &&
12825 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012826 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12827 (flags &&
12828 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012829 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012830
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012831 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012832
Eric W. Biederman15e47302012-09-07 20:12:54 +000012833 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012834
12835 nla_put_failure:
12836 genlmsg_cancel(msg, hdr);
12837 nlmsg_free(msg);
12838 return -ENOBUFS;
12839}
12840
Johannes Berg947add32013-02-22 22:05:20 +010012841void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12842 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012843{
Johannes Berg947add32013-02-22 22:05:20 +010012844 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012845 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012846 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012847 struct sk_buff *msg;
12848 void *hdr;
12849
Johannes Berg947add32013-02-22 22:05:20 +010012850 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12851
Jouni Malinen026331c2010-02-15 12:53:10 +020012852 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12853 if (!msg)
12854 return;
12855
Johannes Berg2e161f72010-08-12 15:38:38 +020012856 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012857 if (!hdr) {
12858 nlmsg_free(msg);
12859 return;
12860 }
12861
David S. Miller9360ffd2012-03-29 04:41:26 -040012862 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012863 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12864 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012865 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12866 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012867 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012868 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12869 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012870 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12871 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012872
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012873 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012874
Johannes Berg68eb5502013-11-19 15:19:38 +010012875 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012876 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012877 return;
12878
12879 nla_put_failure:
12880 genlmsg_cancel(msg, hdr);
12881 nlmsg_free(msg);
12882}
Johannes Berg947add32013-02-22 22:05:20 +010012883EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012884
Johannes Berg5b97f492014-11-26 12:37:43 +010012885static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12886 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012887{
Johannes Berg947add32013-02-22 22:05:20 +010012888 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012889 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12890 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12891 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012892
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012893 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012894 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012895
Johannes Berg5b97f492014-11-26 12:37:43 +010012896 cb = (void **)msg->cb;
12897
12898 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12899 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012900 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012901 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012902 }
12903
David S. Miller9360ffd2012-03-29 04:41:26 -040012904 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012905 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012906 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012907
Johannes Berg5b97f492014-11-26 12:37:43 +010012908 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012909 goto nla_put_failure;
12910
Johannes Berg5b97f492014-11-26 12:37:43 +010012911 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12912 if (!cb[1])
12913 goto nla_put_failure;
12914
12915 cb[2] = rdev;
12916
12917 return msg;
12918 nla_put_failure:
12919 nlmsg_free(msg);
12920 return NULL;
12921}
12922
12923static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12924{
12925 void **cb = (void **)msg->cb;
12926 struct cfg80211_registered_device *rdev = cb[2];
12927
12928 nla_nest_end(msg, cb[1]);
12929 genlmsg_end(msg, cb[0]);
12930
12931 memset(msg->cb, 0, sizeof(msg->cb));
12932
12933 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12934 NL80211_MCGRP_MLME, gfp);
12935}
12936
12937void cfg80211_cqm_rssi_notify(struct net_device *dev,
12938 enum nl80211_cqm_rssi_threshold_event rssi_event,
12939 gfp_t gfp)
12940{
12941 struct sk_buff *msg;
12942
12943 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12944
Johannes Berg98f03342014-11-26 12:42:02 +010012945 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12946 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12947 return;
12948
Johannes Berg5b97f492014-11-26 12:37:43 +010012949 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12950 if (!msg)
12951 return;
12952
David S. Miller9360ffd2012-03-29 04:41:26 -040012953 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12954 rssi_event))
12955 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012956
Johannes Berg5b97f492014-11-26 12:37:43 +010012957 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012958
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012959 return;
12960
12961 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012962 nlmsg_free(msg);
12963}
Johannes Berg947add32013-02-22 22:05:20 +010012964EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012965
Johannes Berg5b97f492014-11-26 12:37:43 +010012966void cfg80211_cqm_txe_notify(struct net_device *dev,
12967 const u8 *peer, u32 num_packets,
12968 u32 rate, u32 intvl, gfp_t gfp)
12969{
12970 struct sk_buff *msg;
12971
12972 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12973 if (!msg)
12974 return;
12975
12976 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12977 goto nla_put_failure;
12978
12979 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12980 goto nla_put_failure;
12981
12982 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12983 goto nla_put_failure;
12984
12985 cfg80211_send_cqm(msg, gfp);
12986 return;
12987
12988 nla_put_failure:
12989 nlmsg_free(msg);
12990}
12991EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12992
12993void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12994 const u8 *peer, u32 num_packets, gfp_t gfp)
12995{
12996 struct sk_buff *msg;
12997
12998 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12999
13000 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13001 if (!msg)
13002 return;
13003
13004 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13005 goto nla_put_failure;
13006
13007 cfg80211_send_cqm(msg, gfp);
13008 return;
13009
13010 nla_put_failure:
13011 nlmsg_free(msg);
13012}
13013EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13014
Johannes Berg98f03342014-11-26 12:42:02 +010013015void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13016{
13017 struct sk_buff *msg;
13018
13019 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13020 if (!msg)
13021 return;
13022
13023 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13024 goto nla_put_failure;
13025
13026 cfg80211_send_cqm(msg, gfp);
13027 return;
13028
13029 nla_put_failure:
13030 nlmsg_free(msg);
13031}
13032EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13033
Johannes Berg947add32013-02-22 22:05:20 +010013034static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13035 struct net_device *netdev, const u8 *bssid,
13036 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013037{
13038 struct sk_buff *msg;
13039 struct nlattr *rekey_attr;
13040 void *hdr;
13041
Thomas Graf58050fc2012-06-28 03:57:45 +000013042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013043 if (!msg)
13044 return;
13045
13046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13047 if (!hdr) {
13048 nlmsg_free(msg);
13049 return;
13050 }
13051
David S. Miller9360ffd2012-03-29 04:41:26 -040013052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13053 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13054 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13055 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013056
13057 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13058 if (!rekey_attr)
13059 goto nla_put_failure;
13060
David S. Miller9360ffd2012-03-29 04:41:26 -040013061 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13062 NL80211_REPLAY_CTR_LEN, replay_ctr))
13063 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013064
13065 nla_nest_end(msg, rekey_attr);
13066
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013067 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013068
Johannes Berg68eb5502013-11-19 15:19:38 +010013069 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013070 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013071 return;
13072
13073 nla_put_failure:
13074 genlmsg_cancel(msg, hdr);
13075 nlmsg_free(msg);
13076}
13077
Johannes Berg947add32013-02-22 22:05:20 +010013078void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13079 const u8 *replay_ctr, gfp_t gfp)
13080{
13081 struct wireless_dev *wdev = dev->ieee80211_ptr;
13082 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013083 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013084
13085 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13086 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13087}
13088EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13089
13090static void
13091nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13092 struct net_device *netdev, int index,
13093 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013094{
13095 struct sk_buff *msg;
13096 struct nlattr *attr;
13097 void *hdr;
13098
Thomas Graf58050fc2012-06-28 03:57:45 +000013099 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013100 if (!msg)
13101 return;
13102
13103 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13104 if (!hdr) {
13105 nlmsg_free(msg);
13106 return;
13107 }
13108
David S. Miller9360ffd2012-03-29 04:41:26 -040013109 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13110 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13111 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013112
13113 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13114 if (!attr)
13115 goto nla_put_failure;
13116
David S. Miller9360ffd2012-03-29 04:41:26 -040013117 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13118 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13119 (preauth &&
13120 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13121 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013122
13123 nla_nest_end(msg, attr);
13124
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013125 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013126
Johannes Berg68eb5502013-11-19 15:19:38 +010013127 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013128 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013129 return;
13130
13131 nla_put_failure:
13132 genlmsg_cancel(msg, hdr);
13133 nlmsg_free(msg);
13134}
13135
Johannes Berg947add32013-02-22 22:05:20 +010013136void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13137 const u8 *bssid, bool preauth, gfp_t gfp)
13138{
13139 struct wireless_dev *wdev = dev->ieee80211_ptr;
13140 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013141 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013142
13143 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13144 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13145}
13146EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13147
13148static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13149 struct net_device *netdev,
13150 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013151 gfp_t gfp,
13152 enum nl80211_commands notif,
13153 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013154{
13155 struct sk_buff *msg;
13156 void *hdr;
13157
Thomas Graf58050fc2012-06-28 03:57:45 +000013158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013159 if (!msg)
13160 return;
13161
Luciano Coelhof8d75522014-11-07 14:31:35 +020013162 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013163 if (!hdr) {
13164 nlmsg_free(msg);
13165 return;
13166 }
13167
Johannes Berg683b6d32012-11-08 21:25:48 +010013168 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13169 goto nla_put_failure;
13170
13171 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013172 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013173
Luciano Coelhof8d75522014-11-07 14:31:35 +020013174 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13175 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13176 goto nla_put_failure;
13177
Thomas Pedersen53145262012-04-06 13:35:47 -070013178 genlmsg_end(msg, hdr);
13179
Johannes Berg68eb5502013-11-19 15:19:38 +010013180 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013181 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013182 return;
13183
13184 nla_put_failure:
13185 genlmsg_cancel(msg, hdr);
13186 nlmsg_free(msg);
13187}
13188
Johannes Berg947add32013-02-22 22:05:20 +010013189void cfg80211_ch_switch_notify(struct net_device *dev,
13190 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013191{
Johannes Berg947add32013-02-22 22:05:20 +010013192 struct wireless_dev *wdev = dev->ieee80211_ptr;
13193 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013194 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013195
Simon Wunderliche487eae2013-11-21 18:19:51 +010013196 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013197
Simon Wunderliche487eae2013-11-21 18:19:51 +010013198 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013199
Michal Kazior9e0e2962014-01-29 14:22:27 +010013200 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013201 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013202 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13203 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013204}
13205EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13206
Luciano Coelhof8d75522014-11-07 14:31:35 +020013207void cfg80211_ch_switch_started_notify(struct net_device *dev,
13208 struct cfg80211_chan_def *chandef,
13209 u8 count)
13210{
13211 struct wireless_dev *wdev = dev->ieee80211_ptr;
13212 struct wiphy *wiphy = wdev->wiphy;
13213 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13214
13215 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13216
13217 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13218 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13219}
13220EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13221
Thomas Pedersen84f10702012-07-12 16:17:33 -070013222void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013223nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013224 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013225 enum nl80211_radar_event event,
13226 struct net_device *netdev, gfp_t gfp)
13227{
13228 struct sk_buff *msg;
13229 void *hdr;
13230
13231 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13232 if (!msg)
13233 return;
13234
13235 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13236 if (!hdr) {
13237 nlmsg_free(msg);
13238 return;
13239 }
13240
13241 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13242 goto nla_put_failure;
13243
13244 /* NOP and radar events don't need a netdev parameter */
13245 if (netdev) {
13246 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13247
13248 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013249 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13250 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013251 goto nla_put_failure;
13252 }
13253
13254 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13255 goto nla_put_failure;
13256
13257 if (nl80211_send_chandef(msg, chandef))
13258 goto nla_put_failure;
13259
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013260 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013261
Johannes Berg68eb5502013-11-19 15:19:38 +010013262 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013263 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013264 return;
13265
13266 nla_put_failure:
13267 genlmsg_cancel(msg, hdr);
13268 nlmsg_free(msg);
13269}
13270
Johannes Berg7f6cf312011-11-04 11:18:15 +010013271void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13272 u64 cookie, bool acked, gfp_t gfp)
13273{
13274 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013275 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013276 struct sk_buff *msg;
13277 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013278
Beni Lev4ee3e062012-08-27 12:49:39 +030013279 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13280
Thomas Graf58050fc2012-06-28 03:57:45 +000013281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013282
Johannes Berg7f6cf312011-11-04 11:18:15 +010013283 if (!msg)
13284 return;
13285
13286 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13287 if (!hdr) {
13288 nlmsg_free(msg);
13289 return;
13290 }
13291
David S. Miller9360ffd2012-03-29 04:41:26 -040013292 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13293 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13294 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013295 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13296 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013297 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13298 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013299
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013300 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013301
Johannes Berg68eb5502013-11-19 15:19:38 +010013302 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013303 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013304 return;
13305
13306 nla_put_failure:
13307 genlmsg_cancel(msg, hdr);
13308 nlmsg_free(msg);
13309}
13310EXPORT_SYMBOL(cfg80211_probe_status);
13311
Johannes Berg5e7602302011-11-04 11:18:17 +010013312void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13313 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013314 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013315{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013316 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013317 struct sk_buff *msg;
13318 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013319 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013320
Beni Lev4ee3e062012-08-27 12:49:39 +030013321 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13322
Ben Greear37c73b52012-10-26 14:49:25 -070013323 spin_lock_bh(&rdev->beacon_registrations_lock);
13324 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13325 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13326 if (!msg) {
13327 spin_unlock_bh(&rdev->beacon_registrations_lock);
13328 return;
13329 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013330
Ben Greear37c73b52012-10-26 14:49:25 -070013331 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13332 if (!hdr)
13333 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013334
Ben Greear37c73b52012-10-26 14:49:25 -070013335 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13336 (freq &&
13337 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13338 (sig_dbm &&
13339 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13340 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13341 goto nla_put_failure;
13342
13343 genlmsg_end(msg, hdr);
13344
13345 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013346 }
Ben Greear37c73b52012-10-26 14:49:25 -070013347 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013348 return;
13349
13350 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013351 spin_unlock_bh(&rdev->beacon_registrations_lock);
13352 if (hdr)
13353 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013354 nlmsg_free(msg);
13355}
13356EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13357
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013358#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013359static int cfg80211_net_detect_results(struct sk_buff *msg,
13360 struct cfg80211_wowlan_wakeup *wakeup)
13361{
13362 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13363 struct nlattr *nl_results, *nl_match, *nl_freqs;
13364 int i, j;
13365
13366 nl_results = nla_nest_start(
13367 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13368 if (!nl_results)
13369 return -EMSGSIZE;
13370
13371 for (i = 0; i < nd->n_matches; i++) {
13372 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13373
13374 nl_match = nla_nest_start(msg, i);
13375 if (!nl_match)
13376 break;
13377
13378 /* The SSID attribute is optional in nl80211, but for
13379 * simplicity reasons it's always present in the
13380 * cfg80211 structure. If a driver can't pass the
13381 * SSID, that needs to be changed. A zero length SSID
13382 * is still a valid SSID (wildcard), so it cannot be
13383 * used for this purpose.
13384 */
13385 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13386 match->ssid.ssid)) {
13387 nla_nest_cancel(msg, nl_match);
13388 goto out;
13389 }
13390
13391 if (match->n_channels) {
13392 nl_freqs = nla_nest_start(
13393 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13394 if (!nl_freqs) {
13395 nla_nest_cancel(msg, nl_match);
13396 goto out;
13397 }
13398
13399 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013400 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013401 nla_nest_cancel(msg, nl_freqs);
13402 nla_nest_cancel(msg, nl_match);
13403 goto out;
13404 }
13405 }
13406
13407 nla_nest_end(msg, nl_freqs);
13408 }
13409
13410 nla_nest_end(msg, nl_match);
13411 }
13412
13413out:
13414 nla_nest_end(msg, nl_results);
13415 return 0;
13416}
13417
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013418void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13419 struct cfg80211_wowlan_wakeup *wakeup,
13420 gfp_t gfp)
13421{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013422 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013423 struct sk_buff *msg;
13424 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013425 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013426
13427 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13428
13429 if (wakeup)
13430 size += wakeup->packet_present_len;
13431
13432 msg = nlmsg_new(size, gfp);
13433 if (!msg)
13434 return;
13435
13436 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13437 if (!hdr)
13438 goto free_msg;
13439
13440 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013441 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13442 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013443 goto free_msg;
13444
13445 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13446 wdev->netdev->ifindex))
13447 goto free_msg;
13448
13449 if (wakeup) {
13450 struct nlattr *reasons;
13451
13452 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013453 if (!reasons)
13454 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013455
13456 if (wakeup->disconnect &&
13457 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13458 goto free_msg;
13459 if (wakeup->magic_pkt &&
13460 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13461 goto free_msg;
13462 if (wakeup->gtk_rekey_failure &&
13463 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13464 goto free_msg;
13465 if (wakeup->eap_identity_req &&
13466 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13467 goto free_msg;
13468 if (wakeup->four_way_handshake &&
13469 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13470 goto free_msg;
13471 if (wakeup->rfkill_release &&
13472 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13473 goto free_msg;
13474
13475 if (wakeup->pattern_idx >= 0 &&
13476 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13477 wakeup->pattern_idx))
13478 goto free_msg;
13479
Johannes Bergae917c92013-10-25 11:05:22 +020013480 if (wakeup->tcp_match &&
13481 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13482 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013483
Johannes Bergae917c92013-10-25 11:05:22 +020013484 if (wakeup->tcp_connlost &&
13485 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13486 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013487
Johannes Bergae917c92013-10-25 11:05:22 +020013488 if (wakeup->tcp_nomoretokens &&
13489 nla_put_flag(msg,
13490 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13491 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013492
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013493 if (wakeup->packet) {
13494 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13495 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13496
13497 if (!wakeup->packet_80211) {
13498 pkt_attr =
13499 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13500 len_attr =
13501 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13502 }
13503
13504 if (wakeup->packet_len &&
13505 nla_put_u32(msg, len_attr, wakeup->packet_len))
13506 goto free_msg;
13507
13508 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13509 wakeup->packet))
13510 goto free_msg;
13511 }
13512
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013513 if (wakeup->net_detect &&
13514 cfg80211_net_detect_results(msg, wakeup))
13515 goto free_msg;
13516
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013517 nla_nest_end(msg, reasons);
13518 }
13519
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013520 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013521
Johannes Berg68eb5502013-11-19 15:19:38 +010013522 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013523 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013524 return;
13525
13526 free_msg:
13527 nlmsg_free(msg);
13528}
13529EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13530#endif
13531
Jouni Malinen3475b092012-11-16 22:49:57 +020013532void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13533 enum nl80211_tdls_operation oper,
13534 u16 reason_code, gfp_t gfp)
13535{
13536 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013537 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013538 struct sk_buff *msg;
13539 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013540
13541 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13542 reason_code);
13543
13544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13545 if (!msg)
13546 return;
13547
13548 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13549 if (!hdr) {
13550 nlmsg_free(msg);
13551 return;
13552 }
13553
13554 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13555 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13556 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13557 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13558 (reason_code > 0 &&
13559 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13560 goto nla_put_failure;
13561
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013562 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013563
Johannes Berg68eb5502013-11-19 15:19:38 +010013564 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013565 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013566 return;
13567
13568 nla_put_failure:
13569 genlmsg_cancel(msg, hdr);
13570 nlmsg_free(msg);
13571}
13572EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13573
Jouni Malinen026331c2010-02-15 12:53:10 +020013574static int nl80211_netlink_notify(struct notifier_block * nb,
13575 unsigned long state,
13576 void *_notify)
13577{
13578 struct netlink_notify *notify = _notify;
13579 struct cfg80211_registered_device *rdev;
13580 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013581 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013582
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013583 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013584 return NOTIFY_DONE;
13585
13586 rcu_read_lock();
13587
Johannes Berg5e7602302011-11-04 11:18:17 +010013588 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013589 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013590 bool schedule_scan_stop = false;
13591 struct cfg80211_sched_scan_request *sched_scan_req =
13592 rcu_dereference(rdev->sched_scan_req);
13593
13594 if (sched_scan_req && notify->portid &&
13595 sched_scan_req->owner_nlportid == notify->portid)
13596 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013597
Johannes Berg53873f12016-05-03 16:52:04 +030013598 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013599 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013600
Johannes Berg78f22b62014-03-24 17:57:27 +010013601 if (wdev->owner_nlportid == notify->portid)
13602 schedule_destroy_work = true;
13603 }
13604
Ben Greear37c73b52012-10-26 14:49:25 -070013605 spin_lock_bh(&rdev->beacon_registrations_lock);
13606 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13607 list) {
13608 if (reg->nlportid == notify->portid) {
13609 list_del(&reg->list);
13610 kfree(reg);
13611 break;
13612 }
13613 }
13614 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013615
13616 if (schedule_destroy_work) {
13617 struct cfg80211_iface_destroy *destroy;
13618
13619 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13620 if (destroy) {
13621 destroy->nlportid = notify->portid;
13622 spin_lock(&rdev->destroy_list_lock);
13623 list_add(&destroy->list, &rdev->destroy_list);
13624 spin_unlock(&rdev->destroy_list_lock);
13625 schedule_work(&rdev->destroy_work);
13626 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013627 } else if (schedule_scan_stop) {
13628 sched_scan_req->owner_nlportid = 0;
13629
13630 if (rdev->ops->sched_scan_stop &&
13631 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13632 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013633 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013634 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013635
13636 rcu_read_unlock();
13637
Ilan peer05050752015-03-04 00:32:06 -050013638 /*
13639 * It is possible that the user space process that is controlling the
13640 * indoor setting disappeared, so notify the regulatory core.
13641 */
13642 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013643 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013644}
13645
13646static struct notifier_block nl80211_netlink_notifier = {
13647 .notifier_call = nl80211_netlink_notify,
13648};
13649
Jouni Malinen355199e2013-02-27 17:14:27 +020013650void cfg80211_ft_event(struct net_device *netdev,
13651 struct cfg80211_ft_event_params *ft_event)
13652{
13653 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013655 struct sk_buff *msg;
13656 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013657
13658 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13659
13660 if (!ft_event->target_ap)
13661 return;
13662
13663 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13664 if (!msg)
13665 return;
13666
13667 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013668 if (!hdr)
13669 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013670
Johannes Bergae917c92013-10-25 11:05:22 +020013671 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13672 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13673 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13674 goto out;
13675
13676 if (ft_event->ies &&
13677 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13678 goto out;
13679 if (ft_event->ric_ies &&
13680 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13681 ft_event->ric_ies))
13682 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013683
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013684 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013685
Johannes Berg68eb5502013-11-19 15:19:38 +010013686 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013687 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013688 return;
13689 out:
13690 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013691}
13692EXPORT_SYMBOL(cfg80211_ft_event);
13693
Arend van Spriel5de17982013-04-18 15:49:00 +020013694void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13695{
13696 struct cfg80211_registered_device *rdev;
13697 struct sk_buff *msg;
13698 void *hdr;
13699 u32 nlportid;
13700
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013701 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013702 if (!rdev->crit_proto_nlportid)
13703 return;
13704
13705 nlportid = rdev->crit_proto_nlportid;
13706 rdev->crit_proto_nlportid = 0;
13707
13708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13709 if (!msg)
13710 return;
13711
13712 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13713 if (!hdr)
13714 goto nla_put_failure;
13715
13716 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013717 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13718 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013719 goto nla_put_failure;
13720
13721 genlmsg_end(msg, hdr);
13722
13723 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13724 return;
13725
13726 nla_put_failure:
13727 if (hdr)
13728 genlmsg_cancel(msg, hdr);
13729 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020013730}
13731EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13732
Johannes Berg348baf02014-01-24 14:06:29 +010013733void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13734{
13735 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013736 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013737 struct sk_buff *msg;
13738 void *hdr;
13739
13740 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13741 if (!msg)
13742 return;
13743
13744 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13745 if (!hdr)
13746 goto out;
13747
13748 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13749 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013750 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13751 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013752 goto out;
13753
13754 genlmsg_end(msg, hdr);
13755
13756 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13757 NL80211_MCGRP_MLME, GFP_KERNEL);
13758 return;
13759 out:
13760 nlmsg_free(msg);
13761}
13762
Johannes Berg55682962007-09-20 13:09:35 -040013763/* initialisation/exit functions */
13764
13765int nl80211_init(void)
13766{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013767 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013768
Johannes Berg2a94fe42013-11-19 15:19:39 +010013769 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13770 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013771 if (err)
13772 return err;
13773
Jouni Malinen026331c2010-02-15 12:53:10 +020013774 err = netlink_register_notifier(&nl80211_netlink_notifier);
13775 if (err)
13776 goto err_out;
13777
Johannes Berg55682962007-09-20 13:09:35 -040013778 return 0;
13779 err_out:
13780 genl_unregister_family(&nl80211_fam);
13781 return err;
13782}
13783
13784void nl80211_exit(void)
13785{
Jouni Malinen026331c2010-02-15 12:53:10 +020013786 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013787 genl_unregister_family(&nl80211_fam);
13788}