blob: f2a77c3daa59b8f9def389bbd947c40bc7e9f2b5 [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 Malinen36aedc92008-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 Malinendc6382ce2009-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;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200851 bool have_key = false;
852
853 nla_for_each_nested(key, keys, rem) {
854 have_key = true;
855 break;
856 }
857
858 if (!have_key)
859 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200860
861 result = kzalloc(sizeof(*result), GFP_KERNEL);
862 if (!result)
863 return ERR_PTR(-ENOMEM);
864
865 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200866
867 nla_for_each_nested(key, keys, rem) {
868 memset(&parse, 0, sizeof(parse));
869 parse.idx = -1;
870
871 err = nl80211_parse_key_new(key, &parse);
872 if (err)
873 goto error;
874 err = -EINVAL;
875 if (!parse.p.key)
876 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200877 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 goto error;
879 if (parse.def) {
880 if (def)
881 goto error;
882 def = 1;
883 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100884 if (!parse.def_uni || !parse.def_multi)
885 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200886 } else if (parse.defmgmt)
887 goto error;
888 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200889 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200890 if (err)
891 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200892 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
893 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
894 err = -EINVAL;
895 goto error;
896 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200897 result->params[parse.idx].cipher = parse.p.cipher;
898 result->params[parse.idx].key_len = parse.p.key_len;
899 result->params[parse.idx].key = result->data[parse.idx];
900 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530901
Johannes Berg386b1f22016-09-13 16:10:02 +0200902 /* must be WEP key if we got here */
903 if (no_ht)
904 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200905 }
906
Johannes Bergf1c1f172016-09-13 17:08:23 +0200907 if (result->def < 0) {
908 err = -EINVAL;
909 goto error;
910 }
911
Johannes Bergfffd0932009-07-08 14:22:54 +0200912 return result;
913 error:
914 kfree(result);
915 return ERR_PTR(err);
916}
917
918static int nl80211_key_allowed(struct wireless_dev *wdev)
919{
920 ASSERT_WDEV_LOCK(wdev);
921
Johannes Bergfffd0932009-07-08 14:22:54 +0200922 switch (wdev->iftype) {
923 case NL80211_IFTYPE_AP:
924 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200925 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700926 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200927 break;
928 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200929 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200930 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200931 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200932 return -ENOLINK;
933 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100934 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100935 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100936 case NL80211_IFTYPE_MONITOR:
937 case NL80211_IFTYPE_P2P_DEVICE:
938 case NL80211_IFTYPE_WDS:
939 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200940 return -EINVAL;
941 }
942
943 return 0;
944}
945
Jouni Malinen664834d2014-01-15 00:01:44 +0200946static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
947 struct nlattr *tb)
948{
949 struct ieee80211_channel *chan;
950
951 if (tb == NULL)
952 return NULL;
953 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
954 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
955 return NULL;
956 return chan;
957}
958
Johannes Berg7527a782011-05-13 10:58:57 +0200959static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
960{
961 struct nlattr *nl_modes = nla_nest_start(msg, attr);
962 int i;
963
964 if (!nl_modes)
965 goto nla_put_failure;
966
967 i = 0;
968 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400969 if ((ifmodes & 1) && nla_put_flag(msg, i))
970 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200971 ifmodes >>= 1;
972 i++;
973 }
974
975 nla_nest_end(msg, nl_modes);
976 return 0;
977
978nla_put_failure:
979 return -ENOBUFS;
980}
981
982static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100983 struct sk_buff *msg,
984 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200985{
986 struct nlattr *nl_combis;
987 int i, j;
988
989 nl_combis = nla_nest_start(msg,
990 NL80211_ATTR_INTERFACE_COMBINATIONS);
991 if (!nl_combis)
992 goto nla_put_failure;
993
994 for (i = 0; i < wiphy->n_iface_combinations; i++) {
995 const struct ieee80211_iface_combination *c;
996 struct nlattr *nl_combi, *nl_limits;
997
998 c = &wiphy->iface_combinations[i];
999
1000 nl_combi = nla_nest_start(msg, i + 1);
1001 if (!nl_combi)
1002 goto nla_put_failure;
1003
1004 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1005 if (!nl_limits)
1006 goto nla_put_failure;
1007
1008 for (j = 0; j < c->n_limits; j++) {
1009 struct nlattr *nl_limit;
1010
1011 nl_limit = nla_nest_start(msg, j + 1);
1012 if (!nl_limit)
1013 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001014 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1015 c->limits[j].max))
1016 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001017 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1018 c->limits[j].types))
1019 goto nla_put_failure;
1020 nla_nest_end(msg, nl_limit);
1021 }
1022
1023 nla_nest_end(msg, nl_limits);
1024
David S. Miller9360ffd2012-03-29 04:41:26 -04001025 if (c->beacon_int_infra_match &&
1026 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1027 goto nla_put_failure;
1028 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1029 c->num_different_channels) ||
1030 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1031 c->max_interfaces))
1032 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001033 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001034 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1035 c->radar_detect_widths) ||
1036 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1037 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001038 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001039
1040 nla_nest_end(msg, nl_combi);
1041 }
1042
1043 nla_nest_end(msg, nl_combis);
1044
1045 return 0;
1046nla_put_failure:
1047 return -ENOBUFS;
1048}
1049
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001051static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1052 struct sk_buff *msg)
1053{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001054 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001055 struct nlattr *nl_tcp;
1056
1057 if (!tcp)
1058 return 0;
1059
1060 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1061 if (!nl_tcp)
1062 return -ENOBUFS;
1063
1064 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1065 tcp->data_payload_max))
1066 return -ENOBUFS;
1067
1068 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1069 tcp->data_payload_max))
1070 return -ENOBUFS;
1071
1072 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1073 return -ENOBUFS;
1074
1075 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1076 sizeof(*tcp->tok), tcp->tok))
1077 return -ENOBUFS;
1078
1079 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1080 tcp->data_interval_max))
1081 return -ENOBUFS;
1082
1083 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1084 tcp->wake_payload_max))
1085 return -ENOBUFS;
1086
1087 nla_nest_end(msg, nl_tcp);
1088 return 0;
1089}
1090
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001093 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001094{
1095 struct nlattr *nl_wowlan;
1096
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001097 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001098 return 0;
1099
1100 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1101 if (!nl_wowlan)
1102 return -ENOBUFS;
1103
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001104 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001105 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001106 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001107 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001108 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001109 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001110 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001111 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001112 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001113 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001114 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001115 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001116 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001117 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001118 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001119 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1120 return -ENOBUFS;
1121
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001122 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001123 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001124 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1125 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1126 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1127 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001128 };
1129
1130 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1131 sizeof(pat), &pat))
1132 return -ENOBUFS;
1133 }
1134
Luciano Coelho75453cc2015-01-09 14:06:37 +02001135 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1136 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1137 rdev->wiphy.wowlan->max_nd_match_sets))
1138 return -ENOBUFS;
1139
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001140 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001141 return -ENOBUFS;
1142
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_nest_end(msg, nl_wowlan);
1144
1145 return 0;
1146}
1147#endif
1148
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001149static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001150 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001151{
1152 struct nl80211_coalesce_rule_support rule;
1153
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001154 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001155 return 0;
1156
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001157 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1158 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1159 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1160 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1161 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1162 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001163
1164 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1165 return -ENOBUFS;
1166
1167 return 0;
1168}
1169
Johannes Berg3713b4e2013-02-14 16:19:38 +01001170static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1171 struct ieee80211_supported_band *sband)
1172{
1173 struct nlattr *nl_rates, *nl_rate;
1174 struct ieee80211_rate *rate;
1175 int i;
1176
1177 /* add HT info */
1178 if (sband->ht_cap.ht_supported &&
1179 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1180 sizeof(sband->ht_cap.mcs),
1181 &sband->ht_cap.mcs) ||
1182 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1183 sband->ht_cap.cap) ||
1184 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1185 sband->ht_cap.ampdu_factor) ||
1186 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1187 sband->ht_cap.ampdu_density)))
1188 return -ENOBUFS;
1189
1190 /* add VHT info */
1191 if (sband->vht_cap.vht_supported &&
1192 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1193 sizeof(sband->vht_cap.vht_mcs),
1194 &sband->vht_cap.vht_mcs) ||
1195 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1196 sband->vht_cap.cap)))
1197 return -ENOBUFS;
1198
1199 /* add bitrates */
1200 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1201 if (!nl_rates)
1202 return -ENOBUFS;
1203
1204 for (i = 0; i < sband->n_bitrates; i++) {
1205 nl_rate = nla_nest_start(msg, i);
1206 if (!nl_rate)
1207 return -ENOBUFS;
1208
1209 rate = &sband->bitrates[i];
1210 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1211 rate->bitrate))
1212 return -ENOBUFS;
1213 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1214 nla_put_flag(msg,
1215 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1216 return -ENOBUFS;
1217
1218 nla_nest_end(msg, nl_rate);
1219 }
1220
1221 nla_nest_end(msg, nl_rates);
1222
1223 return 0;
1224}
1225
1226static int
1227nl80211_send_mgmt_stypes(struct sk_buff *msg,
1228 const struct ieee80211_txrx_stypes *mgmt_stypes)
1229{
1230 u16 stypes;
1231 struct nlattr *nl_ftypes, *nl_ifs;
1232 enum nl80211_iftype ift;
1233 int i;
1234
1235 if (!mgmt_stypes)
1236 return 0;
1237
1238 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1239 if (!nl_ifs)
1240 return -ENOBUFS;
1241
1242 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1243 nl_ftypes = nla_nest_start(msg, ift);
1244 if (!nl_ftypes)
1245 return -ENOBUFS;
1246 i = 0;
1247 stypes = mgmt_stypes[ift].tx;
1248 while (stypes) {
1249 if ((stypes & 1) &&
1250 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1251 (i << 4) | IEEE80211_FTYPE_MGMT))
1252 return -ENOBUFS;
1253 stypes >>= 1;
1254 i++;
1255 }
1256 nla_nest_end(msg, nl_ftypes);
1257 }
1258
1259 nla_nest_end(msg, nl_ifs);
1260
1261 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1262 if (!nl_ifs)
1263 return -ENOBUFS;
1264
1265 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1266 nl_ftypes = nla_nest_start(msg, ift);
1267 if (!nl_ftypes)
1268 return -ENOBUFS;
1269 i = 0;
1270 stypes = mgmt_stypes[ift].rx;
1271 while (stypes) {
1272 if ((stypes & 1) &&
1273 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1274 (i << 4) | IEEE80211_FTYPE_MGMT))
1275 return -ENOBUFS;
1276 stypes >>= 1;
1277 i++;
1278 }
1279 nla_nest_end(msg, nl_ftypes);
1280 }
1281 nla_nest_end(msg, nl_ifs);
1282
1283 return 0;
1284}
1285
Johannes Berg86e8cf92013-06-19 10:57:22 +02001286struct nl80211_dump_wiphy_state {
1287 s64 filter_wiphy;
1288 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301289 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001290 bool split;
1291};
1292
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001294 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001296 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001297{
1298 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001299 struct nlattr *nl_bands, *nl_band;
1300 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001301 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001302 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001303 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001304 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001305 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001307 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001308
Johannes Berg3bb20552014-05-26 13:52:25 +02001309 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001310 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 return -ENOBUFS;
1312
Johannes Berg86e8cf92013-06-19 10:57:22 +02001313 if (WARN_ON(!state))
1314 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001315
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001318 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001319 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001321 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001322
Johannes Berg3bb20552014-05-26 13:52:25 +02001323 if (cmd != NL80211_CMD_NEW_WIPHY)
1324 goto finish;
1325
Johannes Berg86e8cf92013-06-19 10:57:22 +02001326 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327 case 0:
1328 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001333 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001335 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001336 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001341 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001347 rdev->wiphy.max_match_sets) ||
1348 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1349 rdev->wiphy.max_sched_scan_plans) ||
1350 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1351 rdev->wiphy.max_sched_scan_plan_interval) ||
1352 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1353 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001354 goto nla_put_failure;
1355
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001356 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1358 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001359 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1361 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001362 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001363 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1364 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001365 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1367 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1370 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001373 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001374 state->split_start++;
1375 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376 break;
1377 case 1:
1378 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001379 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1380 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001381 goto nla_put_failure;
1382
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001384 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001385 goto nla_put_failure;
1386
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001387 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001388 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1389 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001390
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001392 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001394 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001396
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001397 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001398 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001399 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001400 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001401
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001402 if ((rdev->wiphy.available_antennas_tx ||
1403 rdev->wiphy.available_antennas_rx) &&
1404 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001405 u32 tx_ant = 0, rx_ant = 0;
1406 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001407
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001408 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001409 if (!res) {
1410 if (nla_put_u32(msg,
1411 NL80211_ATTR_WIPHY_ANTENNA_TX,
1412 tx_ant) ||
1413 nla_put_u32(msg,
1414 NL80211_ATTR_WIPHY_ANTENNA_RX,
1415 rx_ant))
1416 goto nla_put_failure;
1417 }
Johannes Bergee688b002008-01-24 19:38:39 +01001418 }
1419
Johannes Berg86e8cf92013-06-19 10:57:22 +02001420 state->split_start++;
1421 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 break;
1423 case 2:
1424 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001425 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 state->split_start++;
1428 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 break;
1430 case 3:
1431 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1432 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001433 goto nla_put_failure;
1434
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001436 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 struct ieee80211_supported_band *sband;
1438
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001439 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440
1441 if (!sband)
1442 continue;
1443
1444 nl_band = nla_nest_start(msg, band);
1445 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001446 goto nla_put_failure;
1447
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 case 0:
1450 if (nl80211_send_band_rateinfo(msg, sband))
1451 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001452 state->chan_start++;
1453 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 break;
1455 default:
1456 /* add frequencies */
1457 nl_freqs = nla_nest_start(
1458 msg, NL80211_BAND_ATTR_FREQS);
1459 if (!nl_freqs)
1460 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001461
Johannes Berg86e8cf92013-06-19 10:57:22 +02001462 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 i < sband->n_channels;
1464 i++) {
1465 nl_freq = nla_nest_start(msg, i);
1466 if (!nl_freq)
1467 goto nla_put_failure;
1468
1469 chan = &sband->channels[i];
1470
Johannes Berg86e8cf92013-06-19 10:57:22 +02001471 if (nl80211_msg_put_channel(
1472 msg, chan,
1473 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 goto nla_put_failure;
1475
1476 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001477 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 break;
1479 }
1480 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001483 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 nla_nest_end(msg, nl_freqs);
1485 }
1486
1487 nla_nest_end(msg, nl_band);
1488
Johannes Berg86e8cf92013-06-19 10:57:22 +02001489 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001490 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001491 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 band--;
1493 break;
1494 }
Johannes Bergee688b002008-01-24 19:38:39 +01001495 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001497
Johannes Berg57fbcce2016-04-12 15:56:15 +02001498 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001499 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001500 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001501 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001502
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001504 if (state->band_start == 0 && state->chan_start == 0)
1505 state->split_start++;
1506 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 break;
1508 case 4:
1509 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1510 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001511 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512
1513 i = 0;
1514#define CMD(op, n) \
1515 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001516 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001517 i++; \
1518 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1519 goto nla_put_failure; \
1520 } \
1521 } while (0)
1522
1523 CMD(add_virtual_intf, NEW_INTERFACE);
1524 CMD(change_virtual_intf, SET_INTERFACE);
1525 CMD(add_key, NEW_KEY);
1526 CMD(start_ap, START_AP);
1527 CMD(add_station, NEW_STATION);
1528 CMD(add_mpath, NEW_MPATH);
1529 CMD(update_mesh_config, SET_MESH_CONFIG);
1530 CMD(change_bss, SET_BSS);
1531 CMD(auth, AUTHENTICATE);
1532 CMD(assoc, ASSOCIATE);
1533 CMD(deauth, DEAUTHENTICATE);
1534 CMD(disassoc, DISASSOCIATE);
1535 CMD(join_ibss, JOIN_IBSS);
1536 CMD(join_mesh, JOIN_MESH);
1537 CMD(set_pmksa, SET_PMKSA);
1538 CMD(del_pmksa, DEL_PMKSA);
1539 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1542 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1543 CMD(mgmt_tx, FRAME);
1544 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 i++;
1547 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1548 goto nla_put_failure;
1549 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001550 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1551 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 i++;
1553 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1554 goto nla_put_failure;
1555 }
1556 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001557 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001558 CMD(tdls_mgmt, TDLS_MGMT);
1559 CMD(tdls_oper, TDLS_OPER);
1560 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001561 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001562 CMD(sched_scan_start, START_SCHED_SCAN);
1563 CMD(probe_client, PROBE_CLIENT);
1564 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 i++;
1567 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1568 goto nla_put_failure;
1569 }
1570 CMD(start_p2p_device, START_P2P_DEVICE);
1571 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001572#ifdef CONFIG_NL80211_TESTMODE
1573 CMD(testmode_cmd, TESTMODE);
1574#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001575 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001576 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1577 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001579 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001580 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001581 if (rdev->wiphy.features &
1582 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001583 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001584 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001585 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001586#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001587
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 i++;
1590 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001591 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001592 }
1593
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001594 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595 i++;
1596 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1597 goto nla_put_failure;
1598 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001599
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001601 state->split_start++;
1602 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 break;
1604 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001605 if (rdev->ops->remain_on_channel &&
1606 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607 nla_put_u32(msg,
1608 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001609 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001610 goto nla_put_failure;
1611
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1614 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001615
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1617 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001618 state->split_start++;
1619 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001620 break;
1621 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001622#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001625 state->split_start++;
1626 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 break;
1628#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001629 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001630#endif
1631 case 7:
1632 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001634 goto nla_put_failure;
1635
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001636 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001637 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001639
Johannes Berg86e8cf92013-06-19 10:57:22 +02001640 state->split_start++;
1641 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001642 break;
1643 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001644 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647 goto nla_put_failure;
1648
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001650 /*
1651 * We can only add the per-channel limit information if the
1652 * dump is split, otherwise it makes it too big. Therefore
1653 * only advertise it in that case.
1654 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001655 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001656 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1657 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001658 goto nla_put_failure;
1659
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001660 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001661 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001662 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1663 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001664 goto nla_put_failure;
1665
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001666 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1667 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001669 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001670 goto nla_put_failure;
1671
1672 /*
1673 * Any information below this point is only available to
1674 * applications that can deal with it being split. This
1675 * helps ensure that newly added capabilities don't break
1676 * older tools by overrunning their buffers.
1677 *
1678 * We still increment split_start so that in the split
1679 * case we'll continue with more data in the next round,
1680 * but break unconditionally so unsplit data stops here.
1681 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001682 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001683 break;
1684 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001685 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001686 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001687 rdev->wiphy.extended_capabilities_len,
1688 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001689 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 rdev->wiphy.extended_capabilities_len,
1691 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001692 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001693
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001694 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001695 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1697 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001698 goto nla_put_failure;
1699
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001700 state->split_start++;
1701 break;
1702 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001704 goto nla_put_failure;
1705
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001706 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001707 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1708 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1709 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001710
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001712 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001713 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001714 goto nla_put_failure;
1715
Johannes Bergad7e7182013-11-13 13:37:47 +01001716 state->split_start++;
1717 break;
1718 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001719 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001720 const struct nl80211_vendor_cmd_info *info;
1721 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001722
Johannes Berg567ffc32013-12-18 14:43:31 +01001723 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1724 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001725 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001726
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001727 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1728 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001729 if (nla_put(msg, i + 1, sizeof(*info), info))
1730 goto nla_put_failure;
1731 }
1732 nla_nest_end(msg, nested);
1733 }
1734
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001735 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001736 const struct nl80211_vendor_cmd_info *info;
1737 struct nlattr *nested;
1738
1739 nested = nla_nest_start(msg,
1740 NL80211_ATTR_VENDOR_EVENTS);
1741 if (!nested)
1742 goto nla_put_failure;
1743
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001744 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1745 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001746 if (nla_put(msg, i + 1, sizeof(*info), info))
1747 goto nla_put_failure;
1748 }
1749 nla_nest_end(msg, nested);
1750 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001751 state->split_start++;
1752 break;
1753 case 12:
1754 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1755 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1756 rdev->wiphy.max_num_csa_counters))
1757 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001758
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001759 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1760 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1761 goto nla_put_failure;
1762
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001763 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1764 sizeof(rdev->wiphy.ext_features),
1765 rdev->wiphy.ext_features))
1766 goto nla_put_failure;
1767
Arend van Spriel38de03d2016-03-02 20:37:18 +01001768 if (rdev->wiphy.bss_select_support) {
1769 struct nlattr *nested;
1770 u32 bss_select_support = rdev->wiphy.bss_select_support;
1771
1772 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1773 if (!nested)
1774 goto nla_put_failure;
1775
1776 i = 0;
1777 while (bss_select_support) {
1778 if ((bss_select_support & 1) &&
1779 nla_put_flag(msg, i))
1780 goto nla_put_failure;
1781 i++;
1782 bss_select_support >>= 1;
1783 }
1784 nla_nest_end(msg, nested);
1785 }
1786
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301787 state->split_start++;
1788 break;
1789 case 13:
1790 if (rdev->wiphy.num_iftype_ext_capab &&
1791 rdev->wiphy.iftype_ext_capab) {
1792 struct nlattr *nested_ext_capab, *nested;
1793
1794 nested = nla_nest_start(msg,
1795 NL80211_ATTR_IFTYPE_EXT_CAPA);
1796 if (!nested)
1797 goto nla_put_failure;
1798
1799 for (i = state->capa_start;
1800 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1801 const struct wiphy_iftype_ext_capab *capab;
1802
1803 capab = &rdev->wiphy.iftype_ext_capab[i];
1804
1805 nested_ext_capab = nla_nest_start(msg, i);
1806 if (!nested_ext_capab ||
1807 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1808 capab->iftype) ||
1809 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1810 capab->extended_capabilities_len,
1811 capab->extended_capabilities) ||
1812 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1813 capab->extended_capabilities_len,
1814 capab->extended_capabilities_mask))
1815 goto nla_put_failure;
1816
1817 nla_nest_end(msg, nested_ext_capab);
1818 if (state->split)
1819 break;
1820 }
1821 nla_nest_end(msg, nested);
1822 if (i < rdev->wiphy.num_iftype_ext_capab) {
1823 state->capa_start = i + 1;
1824 break;
1825 }
1826 }
1827
Johannes Berg3713b4e2013-02-14 16:19:38 +01001828 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001829 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001830 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001831 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001832 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001833 genlmsg_end(msg, hdr);
1834 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001835
1836 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001837 genlmsg_cancel(msg, hdr);
1838 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001839}
1840
Johannes Berg86e8cf92013-06-19 10:57:22 +02001841static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1842 struct netlink_callback *cb,
1843 struct nl80211_dump_wiphy_state *state)
1844{
1845 struct nlattr **tb = nl80211_fam.attrbuf;
1846 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1847 tb, nl80211_fam.maxattr, nl80211_policy);
1848 /* ignore parse errors for backward compatibility */
1849 if (ret)
1850 return 0;
1851
1852 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1853 if (tb[NL80211_ATTR_WIPHY])
1854 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1855 if (tb[NL80211_ATTR_WDEV])
1856 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1857 if (tb[NL80211_ATTR_IFINDEX]) {
1858 struct net_device *netdev;
1859 struct cfg80211_registered_device *rdev;
1860 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1861
Ying Xue7f2b8562014-01-15 10:23:45 +08001862 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001863 if (!netdev)
1864 return -ENODEV;
1865 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001866 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001867 netdev->ieee80211_ptr->wiphy);
1868 state->filter_wiphy = rdev->wiphy_idx;
1869 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001870 }
1871
1872 return 0;
1873}
1874
Johannes Berg55682962007-09-20 13:09:35 -04001875static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1876{
Johannes Berg645e77d2013-03-01 14:03:49 +01001877 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001878 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001879 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001880
Johannes Berg5fe231e2013-05-08 21:45:15 +02001881 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001882 if (!state) {
1883 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001884 if (!state) {
1885 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001886 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001887 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001888 state->filter_wiphy = -1;
1889 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1890 if (ret) {
1891 kfree(state);
1892 rtnl_unlock();
1893 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001894 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001895 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001896 }
1897
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001898 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1899 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001900 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001901 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001902 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001903 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001904 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001905 continue;
1906 /* attempt to fit multiple wiphy data chunks into the skb */
1907 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001908 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1909 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001910 NETLINK_CB(cb->skb).portid,
1911 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001912 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001913 if (ret < 0) {
1914 /*
1915 * If sending the wiphy data didn't fit (ENOBUFS
1916 * or EMSGSIZE returned), this SKB is still
1917 * empty (so it's not too big because another
1918 * wiphy dataset is already in the skb) and
1919 * we've not tried to adjust the dump allocation
1920 * yet ... then adjust the alloc size to be
1921 * bigger, and return 1 but with the empty skb.
1922 * This results in an empty message being RX'ed
1923 * in userspace, but that is ignored.
1924 *
1925 * We can then retry with the larger buffer.
1926 */
1927 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001928 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001929 cb->min_dump_alloc < 4096) {
1930 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001931 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001932 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001933 return 1;
1934 }
1935 idx--;
1936 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001937 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001938 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001939 break;
Johannes Berg55682962007-09-20 13:09:35 -04001940 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001941 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001942
Johannes Berg86e8cf92013-06-19 10:57:22 +02001943 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001944
1945 return skb->len;
1946}
1947
Johannes Berg86e8cf92013-06-19 10:57:22 +02001948static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1949{
1950 kfree((void *)cb->args[0]);
1951 return 0;
1952}
1953
Johannes Berg55682962007-09-20 13:09:35 -04001954static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1955{
1956 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001958 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001959
Johannes Berg645e77d2013-03-01 14:03:49 +01001960 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001961 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001962 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001963
Johannes Berg3bb20552014-05-26 13:52:25 +02001964 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1965 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001966 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001967 nlmsg_free(msg);
1968 return -ENOBUFS;
1969 }
Johannes Berg55682962007-09-20 13:09:35 -04001970
Johannes Berg134e6372009-07-10 09:51:34 +00001971 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001972}
1973
Jouni Malinen31888482008-10-30 16:59:24 +02001974static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1975 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1976 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1977 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1978 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1979 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1980};
1981
1982static int parse_txq_params(struct nlattr *tb[],
1983 struct ieee80211_txq_params *txq_params)
1984{
Johannes Berga3304b02012-03-28 11:04:24 +02001985 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001986 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1987 !tb[NL80211_TXQ_ATTR_AIFS])
1988 return -EINVAL;
1989
Johannes Berga3304b02012-03-28 11:04:24 +02001990 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001991 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1992 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1993 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1994 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1995
Johannes Berga3304b02012-03-28 11:04:24 +02001996 if (txq_params->ac >= NL80211_NUM_ACS)
1997 return -EINVAL;
1998
Jouni Malinen31888482008-10-30 16:59:24 +02001999 return 0;
2000}
2001
Johannes Bergf444de02010-05-05 15:25:02 +02002002static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2003{
2004 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002005 * You can only set the channel explicitly for WDS interfaces,
2006 * all others have their channel managed via their respective
2007 * "establish a connection" command (connect, join, ...)
2008 *
2009 * For AP/GO and mesh mode, the channel can be set with the
2010 * channel userspace API, but is only stored and passed to the
2011 * low-level driver when the AP starts or the mesh is joined.
2012 * This is for backward compatibility, userspace can also give
2013 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002014 *
2015 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002016 * whatever else is going on, so they have their own special
2017 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002018 */
2019 return !wdev ||
2020 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002021 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002022 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2023 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002024}
2025
Johannes Berg683b6d32012-11-08 21:25:48 +01002026static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2027 struct genl_info *info,
2028 struct cfg80211_chan_def *chandef)
2029{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302030 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002031
2032 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2033 return -EINVAL;
2034
2035 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2036
2037 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002038 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2039 chandef->center_freq1 = control_freq;
2040 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002041
2042 /* Primary channel not allowed */
2043 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2044 return -EINVAL;
2045
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002046 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2047 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002048
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002049 chantype = nla_get_u32(
2050 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2051
2052 switch (chantype) {
2053 case NL80211_CHAN_NO_HT:
2054 case NL80211_CHAN_HT20:
2055 case NL80211_CHAN_HT40PLUS:
2056 case NL80211_CHAN_HT40MINUS:
2057 cfg80211_chandef_create(chandef, chandef->chan,
2058 chantype);
2059 break;
2060 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002061 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002062 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002063 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2064 chandef->width =
2065 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2066 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2067 chandef->center_freq1 =
2068 nla_get_u32(
2069 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2070 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2071 chandef->center_freq2 =
2072 nla_get_u32(
2073 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2074 }
2075
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002076 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002077 return -EINVAL;
2078
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002079 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2080 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002081 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002082
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002083 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2084 chandef->width == NL80211_CHAN_WIDTH_10) &&
2085 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2086 return -EINVAL;
2087
Johannes Berg683b6d32012-11-08 21:25:48 +01002088 return 0;
2089}
2090
Johannes Bergf444de02010-05-05 15:25:02 +02002091static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002092 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002093 struct genl_info *info)
2094{
Johannes Berg683b6d32012-11-08 21:25:48 +01002095 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002096 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002097 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002098 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002099
Jouni Malinene16821b2014-04-28 11:22:08 +03002100 if (dev)
2101 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002102 if (!nl80211_can_set_dev_channel(wdev))
2103 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002104 if (wdev)
2105 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002106
Johannes Berg683b6d32012-11-08 21:25:48 +01002107 result = nl80211_parse_chandef(rdev, info, &chandef);
2108 if (result)
2109 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002110
Johannes Berge8c9bd52012-06-06 08:18:22 +02002111 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002112 case NL80211_IFTYPE_AP:
2113 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002114 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2115 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002116 result = -EINVAL;
2117 break;
2118 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002119 if (wdev->beacon_interval) {
2120 if (!dev || !rdev->ops->set_ap_chanwidth ||
2121 !(rdev->wiphy.features &
2122 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2123 result = -EBUSY;
2124 break;
2125 }
2126
2127 /* Only allow dynamic channel width changes */
2128 if (chandef.chan != wdev->preset_chandef.chan) {
2129 result = -EBUSY;
2130 break;
2131 }
2132 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2133 if (result)
2134 break;
2135 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002136 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002137 result = 0;
2138 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002139 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002140 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002141 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002142 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002143 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002144 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002145 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002146 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002147 }
Johannes Bergf444de02010-05-05 15:25:02 +02002148
2149 return result;
2150}
2151
2152static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2153{
Johannes Berg4c476992010-10-04 21:36:35 +02002154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2155 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002156
Jouni Malinene16821b2014-04-28 11:22:08 +03002157 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002158}
2159
Bill Jordane8347eb2010-10-01 13:54:28 -04002160static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2161{
Johannes Berg43b19952010-10-07 13:10:30 +02002162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2163 struct net_device *dev = info->user_ptr[1];
2164 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002165 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002166
2167 if (!info->attrs[NL80211_ATTR_MAC])
2168 return -EINVAL;
2169
Johannes Berg43b19952010-10-07 13:10:30 +02002170 if (netif_running(dev))
2171 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002172
Johannes Berg43b19952010-10-07 13:10:30 +02002173 if (!rdev->ops->set_wds_peer)
2174 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002175
Johannes Berg43b19952010-10-07 13:10:30 +02002176 if (wdev->iftype != NL80211_IFTYPE_WDS)
2177 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002178
2179 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002180 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002181}
2182
Johannes Berg55682962007-09-20 13:09:35 -04002183static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2184{
2185 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002186 struct net_device *netdev = NULL;
2187 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002188 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002189 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002190 u32 changed;
2191 u8 retry_short = 0, retry_long = 0;
2192 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002193 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002194
Johannes Berg5fe231e2013-05-08 21:45:15 +02002195 ASSERT_RTNL();
2196
Johannes Bergf444de02010-05-05 15:25:02 +02002197 /*
2198 * Try to find the wiphy and netdev. Normally this
2199 * function shouldn't need the netdev, but this is
2200 * done for backward compatibility -- previously
2201 * setting the channel was done per wiphy, but now
2202 * it is per netdev. Previous userland like hostapd
2203 * also passed a netdev to set_wiphy, so that it is
2204 * possible to let that go to the right netdev!
2205 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002206
Johannes Bergf444de02010-05-05 15:25:02 +02002207 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2208 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2209
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002211 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002212 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002213 else
Johannes Bergf444de02010-05-05 15:25:02 +02002214 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002215 }
2216
Johannes Bergf444de02010-05-05 15:25:02 +02002217 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002218 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2219 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002220 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002221 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002222 wdev = NULL;
2223 netdev = NULL;
2224 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002225 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002226 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002227
2228 /*
2229 * end workaround code, by now the rdev is available
2230 * and locked, and wdev may or may not be NULL.
2231 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002232
2233 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002234 result = cfg80211_dev_rename(
2235 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002236
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002237 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002239
Jouni Malinen31888482008-10-30 16:59:24 +02002240 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2241 struct ieee80211_txq_params txq_params;
2242 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2243
Ying Xue7f2b8562014-01-15 10:23:45 +08002244 if (!rdev->ops->set_txq_params)
2245 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002246
Ying Xue7f2b8562014-01-15 10:23:45 +08002247 if (!netdev)
2248 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002249
Johannes Berg133a3ff2011-11-03 14:50:13 +01002250 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002251 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2252 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002253
Ying Xue7f2b8562014-01-15 10:23:45 +08002254 if (!netif_running(netdev))
2255 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002256
Jouni Malinen31888482008-10-30 16:59:24 +02002257 nla_for_each_nested(nl_txq_params,
2258 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2259 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002260 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2261 nla_data(nl_txq_params),
2262 nla_len(nl_txq_params),
2263 txq_params_policy);
2264 if (result)
2265 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002266 result = parse_txq_params(tb, &txq_params);
2267 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002268 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002269
Hila Gonene35e4d22012-06-27 17:19:42 +03002270 result = rdev_set_txq_params(rdev, netdev,
2271 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002272 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002273 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002274 }
2275 }
2276
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002277 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002278 result = __nl80211_set_channel(
2279 rdev,
2280 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2281 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002282 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002283 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002284 }
2285
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002286 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002287 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002288 enum nl80211_tx_power_setting type;
2289 int idx, mbm = 0;
2290
Johannes Bergc8442112012-10-24 10:17:18 +02002291 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2292 txp_wdev = NULL;
2293
Ying Xue7f2b8562014-01-15 10:23:45 +08002294 if (!rdev->ops->set_tx_power)
2295 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002296
2297 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2298 type = nla_get_u32(info->attrs[idx]);
2299
2300 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002301 (type != NL80211_TX_POWER_AUTOMATIC))
2302 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002303
2304 if (type != NL80211_TX_POWER_AUTOMATIC) {
2305 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2306 mbm = nla_get_u32(info->attrs[idx]);
2307 }
2308
Johannes Bergc8442112012-10-24 10:17:18 +02002309 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002310 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002311 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002312 }
2313
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002314 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2315 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2316 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002317
Bruno Randolf7f531e02010-12-16 11:30:22 +09002318 if ((!rdev->wiphy.available_antennas_tx &&
2319 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002320 !rdev->ops->set_antenna)
2321 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002322
2323 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2324 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2325
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002326 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002327 * available antenna masks, except for the "all" mask */
2328 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2330 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002331
Bruno Randolf7f531e02010-12-16 11:30:22 +09002332 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2333 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002334
Hila Gonene35e4d22012-06-27 17:19:42 +03002335 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002336 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002337 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002338 }
2339
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002340 changed = 0;
2341
2342 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2343 retry_short = nla_get_u8(
2344 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002345 if (retry_short == 0)
2346 return -EINVAL;
2347
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002348 changed |= WIPHY_PARAM_RETRY_SHORT;
2349 }
2350
2351 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2352 retry_long = nla_get_u8(
2353 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002354 if (retry_long == 0)
2355 return -EINVAL;
2356
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002357 changed |= WIPHY_PARAM_RETRY_LONG;
2358 }
2359
2360 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2361 frag_threshold = nla_get_u32(
2362 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002363 if (frag_threshold < 256)
2364 return -EINVAL;
2365
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002366 if (frag_threshold != (u32) -1) {
2367 /*
2368 * Fragments (apart from the last one) are required to
2369 * have even length. Make the fragmentation code
2370 * simpler by stripping LSB should someone try to use
2371 * odd threshold value.
2372 */
2373 frag_threshold &= ~0x1;
2374 }
2375 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2376 }
2377
2378 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2379 rts_threshold = nla_get_u32(
2380 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2381 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2382 }
2383
Lukáš Turek81077e82009-12-21 22:50:47 +01002384 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002385 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2386 return -EINVAL;
2387
Lukáš Turek81077e82009-12-21 22:50:47 +01002388 coverage_class = nla_get_u8(
2389 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2390 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2391 }
2392
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002393 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2394 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2395 return -EOPNOTSUPP;
2396
2397 changed |= WIPHY_PARAM_DYN_ACK;
2398 }
2399
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002400 if (changed) {
2401 u8 old_retry_short, old_retry_long;
2402 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002403 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002404
Ying Xue7f2b8562014-01-15 10:23:45 +08002405 if (!rdev->ops->set_wiphy_params)
2406 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002407
2408 old_retry_short = rdev->wiphy.retry_short;
2409 old_retry_long = rdev->wiphy.retry_long;
2410 old_frag_threshold = rdev->wiphy.frag_threshold;
2411 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002412 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002413
2414 if (changed & WIPHY_PARAM_RETRY_SHORT)
2415 rdev->wiphy.retry_short = retry_short;
2416 if (changed & WIPHY_PARAM_RETRY_LONG)
2417 rdev->wiphy.retry_long = retry_long;
2418 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2419 rdev->wiphy.frag_threshold = frag_threshold;
2420 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2421 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002422 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2423 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002424
Hila Gonene35e4d22012-06-27 17:19:42 +03002425 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002426 if (result) {
2427 rdev->wiphy.retry_short = old_retry_short;
2428 rdev->wiphy.retry_long = old_retry_long;
2429 rdev->wiphy.frag_threshold = old_frag_threshold;
2430 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002431 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002432 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002433 }
2434 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002435 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002436}
2437
Johannes Berg71bbc992012-06-15 15:30:18 +02002438static inline u64 wdev_id(struct wireless_dev *wdev)
2439{
2440 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002441 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002442}
Johannes Berg55682962007-09-20 13:09:35 -04002443
Johannes Berg683b6d32012-11-08 21:25:48 +01002444static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002445 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002446{
Johannes Berg601555c2014-11-27 17:26:56 +01002447 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2448 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002449
Johannes Berg683b6d32012-11-08 21:25:48 +01002450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2451 chandef->chan->center_freq))
2452 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002453 switch (chandef->width) {
2454 case NL80211_CHAN_WIDTH_20_NOHT:
2455 case NL80211_CHAN_WIDTH_20:
2456 case NL80211_CHAN_WIDTH_40:
2457 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2458 cfg80211_get_chandef_type(chandef)))
2459 return -ENOBUFS;
2460 break;
2461 default:
2462 break;
2463 }
2464 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2465 return -ENOBUFS;
2466 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2467 return -ENOBUFS;
2468 if (chandef->center_freq2 &&
2469 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002470 return -ENOBUFS;
2471 return 0;
2472}
2473
Eric W. Biederman15e47302012-09-07 20:12:54 +00002474static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002475 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002476 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002477{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002478 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002479 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002480 void *hdr;
2481
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002482 if (removal)
2483 cmd = NL80211_CMD_DEL_INTERFACE;
2484
2485 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002486 if (!hdr)
2487 return -1;
2488
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002489 if (dev &&
2490 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002491 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002492 goto nla_put_failure;
2493
2494 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2495 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002496 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2497 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002498 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002499 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2500 rdev->devlist_generation ^
2501 (cfg80211_rdev_list_generation << 2)))
2502 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002503
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002504 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002505 int ret;
2506 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002507
Johannes Berg683b6d32012-11-08 21:25:48 +01002508 ret = rdev_get_channel(rdev, wdev, &chandef);
2509 if (ret == 0) {
2510 if (nl80211_send_chandef(msg, &chandef))
2511 goto nla_put_failure;
2512 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002513 }
2514
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002515 if (rdev->ops->get_tx_power) {
2516 int dbm, ret;
2517
2518 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2519 if (ret == 0 &&
2520 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2521 DBM_TO_MBM(dbm)))
2522 goto nla_put_failure;
2523 }
2524
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002525 if (wdev->ssid_len) {
2526 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2527 goto nla_put_failure;
2528 }
2529
Johannes Berg053c0952015-01-16 22:09:00 +01002530 genlmsg_end(msg, hdr);
2531 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002532
2533 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002534 genlmsg_cancel(msg, hdr);
2535 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002536}
2537
2538static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2539{
2540 int wp_idx = 0;
2541 int if_idx = 0;
2542 int wp_start = cb->args[0];
2543 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002544 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002545 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002546 struct wireless_dev *wdev;
2547
Johannes Berg5fe231e2013-05-08 21:45:15 +02002548 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002549 if (!cb->args[2]) {
2550 struct nl80211_dump_wiphy_state state = {
2551 .filter_wiphy = -1,
2552 };
2553 int ret;
2554
2555 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2556 if (ret)
2557 return ret;
2558
2559 filter_wiphy = state.filter_wiphy;
2560
2561 /*
2562 * if filtering, set cb->args[2] to +1 since 0 is the default
2563 * value needed to determine that parsing is necessary.
2564 */
2565 if (filter_wiphy >= 0)
2566 cb->args[2] = filter_wiphy + 1;
2567 else
2568 cb->args[2] = -1;
2569 } else if (cb->args[2] > 0) {
2570 filter_wiphy = cb->args[2] - 1;
2571 }
2572
Johannes Bergf5ea9122009-08-07 16:17:38 +02002573 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2574 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002575 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002576 if (wp_idx < wp_start) {
2577 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002578 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002579 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002580
2581 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2582 continue;
2583
Johannes Berg55682962007-09-20 13:09:35 -04002584 if_idx = 0;
2585
Johannes Berg53873f12016-05-03 16:52:04 +03002586 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002587 if (if_idx < if_start) {
2588 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002589 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002590 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002591 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002592 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002593 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002594 goto out;
2595 }
2596 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002597 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002598
2599 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002600 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002601 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002602 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002603
2604 cb->args[0] = wp_idx;
2605 cb->args[1] = if_idx;
2606
2607 return skb->len;
2608}
2609
2610static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2611{
2612 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002614 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002615
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002616 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002617 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002618 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002619
Eric W. Biederman15e47302012-09-07 20:12:54 +00002620 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002621 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002622 nlmsg_free(msg);
2623 return -ENOBUFS;
2624 }
Johannes Berg55682962007-09-20 13:09:35 -04002625
Johannes Berg134e6372009-07-10 09:51:34 +00002626 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002627}
2628
Michael Wu66f7ac52008-01-31 19:48:22 +01002629static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2630 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2631 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2632 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2633 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2634 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002635 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002636};
2637
2638static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2639{
2640 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2641 int flag;
2642
2643 *mntrflags = 0;
2644
2645 if (!nla)
2646 return -EINVAL;
2647
2648 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2649 nla, mntr_flags_policy))
2650 return -EINVAL;
2651
2652 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2653 if (flags[flag])
2654 *mntrflags |= (1<<flag);
2655
2656 return 0;
2657}
2658
Johannes Berg9bc383d2009-11-19 11:55:19 +01002659static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002660 struct net_device *netdev, u8 use_4addr,
2661 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002662{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002663 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002664 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002665 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002666 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002667 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002668
2669 switch (iftype) {
2670 case NL80211_IFTYPE_AP_VLAN:
2671 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2672 return 0;
2673 break;
2674 case NL80211_IFTYPE_STATION:
2675 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2676 return 0;
2677 break;
2678 default:
2679 break;
2680 }
2681
2682 return -EOPNOTSUPP;
2683}
2684
Johannes Berg55682962007-09-20 13:09:35 -04002685static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2686{
Johannes Berg4c476992010-10-04 21:36:35 +02002687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002688 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002689 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002690 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002691 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002692 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002693 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002694
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002695 memset(&params, 0, sizeof(params));
2696
Johannes Berg04a773a2009-04-19 21:24:32 +02002697 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002698
Johannes Berg723b0382008-09-16 20:22:09 +02002699 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002700 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002701 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002702 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002703 if (ntype > NL80211_IFTYPE_MAX)
2704 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002705 }
2706
Johannes Berg92ffe052008-09-16 20:39:36 +02002707 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002708 struct wireless_dev *wdev = dev->ieee80211_ptr;
2709
Johannes Berg4c476992010-10-04 21:36:35 +02002710 if (ntype != NL80211_IFTYPE_MESH_POINT)
2711 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002712 if (netif_running(dev))
2713 return -EBUSY;
2714
2715 wdev_lock(wdev);
2716 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2717 IEEE80211_MAX_MESH_ID_LEN);
2718 wdev->mesh_id_up_len =
2719 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2720 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2721 wdev->mesh_id_up_len);
2722 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002723 }
2724
Felix Fietkau8b787642009-11-10 18:53:10 +01002725 if (info->attrs[NL80211_ATTR_4ADDR]) {
2726 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2727 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002728 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002729 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002730 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002731 } else {
2732 params.use_4addr = -1;
2733 }
2734
Johannes Berg92ffe052008-09-16 20:39:36 +02002735 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002736 if (ntype != NL80211_IFTYPE_MONITOR)
2737 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002738 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2739 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002740 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002741 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002742
2743 flags = &_flags;
2744 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002745 }
Johannes Berg3b858752009-03-12 09:55:09 +01002746
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002747 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2748 const u8 *mumimo_groups;
2749 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2750
2751 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2752 return -EOPNOTSUPP;
2753
2754 mumimo_groups =
2755 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2756
2757 /* bits 0 and 63 are reserved and must be zero */
2758 if ((mumimo_groups[0] & BIT(7)) ||
2759 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2760 return -EINVAL;
2761
2762 memcpy(params.vht_mumimo_groups, mumimo_groups,
2763 VHT_MUMIMO_GROUPS_DATA_LEN);
2764 change = true;
2765 }
2766
2767 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2768 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2769
2770 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2771 return -EOPNOTSUPP;
2772
2773 nla_memcpy(params.macaddr,
2774 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2775 ETH_ALEN);
2776 change = true;
2777 }
2778
Luciano Coelho18003292013-08-29 13:26:57 +03002779 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002780 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2781 return -EOPNOTSUPP;
2782
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002783 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002784 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002785 else
2786 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002787
Johannes Berg9bc383d2009-11-19 11:55:19 +01002788 if (!err && params.use_4addr != -1)
2789 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2790
Johannes Berg55682962007-09-20 13:09:35 -04002791 return err;
2792}
2793
2794static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2795{
Johannes Berg4c476992010-10-04 21:36:35 +02002796 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002797 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002798 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002799 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002800 int err;
2801 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002802 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002803
Johannes Berg78f22b62014-03-24 17:57:27 +01002804 /* to avoid failing a new interface creation due to pending removal */
2805 cfg80211_destroy_ifaces(rdev);
2806
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002807 memset(&params, 0, sizeof(params));
2808
Johannes Berg55682962007-09-20 13:09:35 -04002809 if (!info->attrs[NL80211_ATTR_IFNAME])
2810 return -EINVAL;
2811
2812 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2813 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2814 if (type > NL80211_IFTYPE_MAX)
2815 return -EINVAL;
2816 }
2817
Johannes Berg79c97e92009-07-07 03:56:12 +02002818 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002819 !(rdev->wiphy.interface_modes & (1 << type)))
2820 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002821
Ben Greeare8f479b2014-10-22 12:23:05 -07002822 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2823 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2824 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002825 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2826 ETH_ALEN);
2827 if (!is_valid_ether_addr(params.macaddr))
2828 return -EADDRNOTAVAIL;
2829 }
2830
Johannes Berg9bc383d2009-11-19 11:55:19 +01002831 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002832 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002833 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002834 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002835 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002836 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002837
Michael Wu66f7ac52008-01-31 19:48:22 +01002838 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2839 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2840 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002841
Luciano Coelho18003292013-08-29 13:26:57 +03002842 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002843 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2844 return -EOPNOTSUPP;
2845
Johannes Berga18c7192015-02-24 10:56:42 +01002846 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2847 if (!msg)
2848 return -ENOMEM;
2849
Hila Gonene35e4d22012-06-27 17:19:42 +03002850 wdev = rdev_add_virtual_intf(rdev,
2851 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002852 NET_NAME_USER, type, err ? NULL : &flags,
2853 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002854 if (WARN_ON(!wdev)) {
2855 nlmsg_free(msg);
2856 return -EPROTO;
2857 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002858 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002859 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002860 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002861
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002862 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002863 wdev->owner_nlportid = info->snd_portid;
2864
Johannes Berg98104fde2012-06-16 00:19:54 +02002865 switch (type) {
2866 case NL80211_IFTYPE_MESH_POINT:
2867 if (!info->attrs[NL80211_ATTR_MESH_ID])
2868 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002869 wdev_lock(wdev);
2870 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2871 IEEE80211_MAX_MESH_ID_LEN);
2872 wdev->mesh_id_up_len =
2873 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2874 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2875 wdev->mesh_id_up_len);
2876 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002877 break;
2878 case NL80211_IFTYPE_P2P_DEVICE:
2879 /*
2880 * P2P Device doesn't have a netdev, so doesn't go
2881 * through the netdev notifier and must be added here
2882 */
2883 mutex_init(&wdev->mtx);
2884 INIT_LIST_HEAD(&wdev->event_list);
2885 spin_lock_init(&wdev->event_lock);
2886 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2887 spin_lock_init(&wdev->mgmt_registrations_lock);
2888
Johannes Berg98104fde2012-06-16 00:19:54 +02002889 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002890 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002891 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002892 break;
2893 default:
2894 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002895 }
2896
Eric W. Biederman15e47302012-09-07 20:12:54 +00002897 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002898 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002899 nlmsg_free(msg);
2900 return -ENOBUFS;
2901 }
2902
Denis Kenzior896ff062016-08-03 16:58:33 -05002903 /*
2904 * For wdevs which have no associated netdev object (e.g. of type
2905 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2906 * For all other types, the event will be generated from the
2907 * netdev notifier
2908 */
2909 if (!wdev->netdev)
2910 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002911
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002912 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002913}
2914
2915static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2916{
Johannes Berg4c476992010-10-04 21:36:35 +02002917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002918 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002919
Johannes Berg4c476992010-10-04 21:36:35 +02002920 if (!rdev->ops->del_virtual_intf)
2921 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002922
Johannes Berg84efbb82012-06-16 00:00:26 +02002923 /*
2924 * If we remove a wireless device without a netdev then clear
2925 * user_ptr[1] so that nl80211_post_doit won't dereference it
2926 * to check if it needs to do dev_put(). Otherwise it crashes
2927 * since the wdev has been freed, unlike with a netdev where
2928 * we need the dev_put() for the netdev to really be freed.
2929 */
2930 if (!wdev->netdev)
2931 info->user_ptr[1] = NULL;
2932
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002933 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002934}
2935
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002936static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2937{
2938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2939 struct net_device *dev = info->user_ptr[1];
2940 u16 noack_map;
2941
2942 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2943 return -EINVAL;
2944
2945 if (!rdev->ops->set_noack_map)
2946 return -EOPNOTSUPP;
2947
2948 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2949
Hila Gonene35e4d22012-06-27 17:19:42 +03002950 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002951}
2952
Johannes Berg41ade002007-12-19 02:03:29 +01002953struct get_key_cookie {
2954 struct sk_buff *msg;
2955 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002956 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002957};
2958
2959static void get_key_callback(void *c, struct key_params *params)
2960{
Johannes Bergb9454e82009-07-08 13:29:08 +02002961 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002962 struct get_key_cookie *cookie = c;
2963
David S. Miller9360ffd2012-03-29 04:41:26 -04002964 if ((params->key &&
2965 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2966 params->key_len, params->key)) ||
2967 (params->seq &&
2968 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2969 params->seq_len, params->seq)) ||
2970 (params->cipher &&
2971 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2972 params->cipher)))
2973 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002974
Johannes Bergb9454e82009-07-08 13:29:08 +02002975 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2976 if (!key)
2977 goto nla_put_failure;
2978
David S. Miller9360ffd2012-03-29 04:41:26 -04002979 if ((params->key &&
2980 nla_put(cookie->msg, NL80211_KEY_DATA,
2981 params->key_len, params->key)) ||
2982 (params->seq &&
2983 nla_put(cookie->msg, NL80211_KEY_SEQ,
2984 params->seq_len, params->seq)) ||
2985 (params->cipher &&
2986 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2987 params->cipher)))
2988 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002989
David S. Miller9360ffd2012-03-29 04:41:26 -04002990 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2991 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002992
2993 nla_nest_end(cookie->msg, key);
2994
Johannes Berg41ade002007-12-19 02:03:29 +01002995 return;
2996 nla_put_failure:
2997 cookie->error = 1;
2998}
2999
3000static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3001{
Johannes Berg4c476992010-10-04 21:36:35 +02003002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003003 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003004 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003005 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003006 const u8 *mac_addr = NULL;
3007 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003008 struct get_key_cookie cookie = {
3009 .error = 0,
3010 };
3011 void *hdr;
3012 struct sk_buff *msg;
3013
3014 if (info->attrs[NL80211_ATTR_KEY_IDX])
3015 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3016
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003017 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003018 return -EINVAL;
3019
3020 if (info->attrs[NL80211_ATTR_MAC])
3021 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3022
Johannes Berge31b8212010-10-05 19:39:30 +02003023 pairwise = !!mac_addr;
3024 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3025 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003026
Johannes Berge31b8212010-10-05 19:39:30 +02003027 if (kt >= NUM_NL80211_KEYTYPES)
3028 return -EINVAL;
3029 if (kt != NL80211_KEYTYPE_GROUP &&
3030 kt != NL80211_KEYTYPE_PAIRWISE)
3031 return -EINVAL;
3032 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3033 }
3034
Johannes Berg4c476992010-10-04 21:36:35 +02003035 if (!rdev->ops->get_key)
3036 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003037
Johannes Berg0fa7b392015-01-23 11:10:12 +01003038 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3039 return -ENOENT;
3040
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003041 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003042 if (!msg)
3043 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003044
Eric W. Biederman15e47302012-09-07 20:12:54 +00003045 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003046 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003047 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003048 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003049
3050 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003051 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003052
David S. Miller9360ffd2012-03-29 04:41:26 -04003053 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3054 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3055 goto nla_put_failure;
3056 if (mac_addr &&
3057 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3058 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003059
Hila Gonene35e4d22012-06-27 17:19:42 +03003060 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3061 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003062
3063 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003064 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003065
3066 if (cookie.error)
3067 goto nla_put_failure;
3068
3069 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003070 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003071
3072 nla_put_failure:
3073 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003074 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003075 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003076 return err;
3077}
3078
3079static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3080{
Johannes Berg4c476992010-10-04 21:36:35 +02003081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003082 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003083 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003084 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003085
Johannes Bergb9454e82009-07-08 13:29:08 +02003086 err = nl80211_parse_key(info, &key);
3087 if (err)
3088 return err;
3089
3090 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003091 return -EINVAL;
3092
Johannes Bergb9454e82009-07-08 13:29:08 +02003093 /* only support setting default key */
3094 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003095 return -EINVAL;
3096
Johannes Bergfffd0932009-07-08 14:22:54 +02003097 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003098
3099 if (key.def) {
3100 if (!rdev->ops->set_default_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_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003110 key.def_uni, key.def_multi);
3111
3112 if (err)
3113 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003114
Johannes Berg3d23e342009-09-29 23:27:28 +02003115#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003116 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003117#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003118 } else {
3119 if (key.def_uni || !key.def_multi) {
3120 err = -EINVAL;
3121 goto out;
3122 }
3123
3124 if (!rdev->ops->set_default_mgmt_key) {
3125 err = -EOPNOTSUPP;
3126 goto out;
3127 }
3128
3129 err = nl80211_key_allowed(dev->ieee80211_ptr);
3130 if (err)
3131 goto out;
3132
Hila Gonene35e4d22012-06-27 17:19:42 +03003133 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003134 if (err)
3135 goto out;
3136
3137#ifdef CONFIG_CFG80211_WEXT
3138 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3139#endif
3140 }
3141
3142 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003143 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003144
Johannes Berg41ade002007-12-19 02:03:29 +01003145 return err;
3146}
3147
3148static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3149{
Johannes Berg4c476992010-10-04 21:36:35 +02003150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003151 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003152 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003153 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003154 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003155
Johannes Bergb9454e82009-07-08 13:29:08 +02003156 err = nl80211_parse_key(info, &key);
3157 if (err)
3158 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003159
Johannes Bergb9454e82009-07-08 13:29:08 +02003160 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003161 return -EINVAL;
3162
Johannes Berg41ade002007-12-19 02:03:29 +01003163 if (info->attrs[NL80211_ATTR_MAC])
3164 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3165
Johannes Berge31b8212010-10-05 19:39:30 +02003166 if (key.type == -1) {
3167 if (mac_addr)
3168 key.type = NL80211_KEYTYPE_PAIRWISE;
3169 else
3170 key.type = NL80211_KEYTYPE_GROUP;
3171 }
3172
3173 /* for now */
3174 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3175 key.type != NL80211_KEYTYPE_GROUP)
3176 return -EINVAL;
3177
Johannes Berg4c476992010-10-04 21:36:35 +02003178 if (!rdev->ops->add_key)
3179 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003180
Johannes Berge31b8212010-10-05 19:39:30 +02003181 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3182 key.type == NL80211_KEYTYPE_PAIRWISE,
3183 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003184 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003185
3186 wdev_lock(dev->ieee80211_ptr);
3187 err = nl80211_key_allowed(dev->ieee80211_ptr);
3188 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003189 err = rdev_add_key(rdev, dev, key.idx,
3190 key.type == NL80211_KEYTYPE_PAIRWISE,
3191 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003192 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003193
Johannes Berg41ade002007-12-19 02:03:29 +01003194 return err;
3195}
3196
3197static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3198{
Johannes Berg4c476992010-10-04 21:36:35 +02003199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003200 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003201 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003202 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003203 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003204
Johannes Bergb9454e82009-07-08 13:29:08 +02003205 err = nl80211_parse_key(info, &key);
3206 if (err)
3207 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003208
3209 if (info->attrs[NL80211_ATTR_MAC])
3210 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3211
Johannes Berge31b8212010-10-05 19:39:30 +02003212 if (key.type == -1) {
3213 if (mac_addr)
3214 key.type = NL80211_KEYTYPE_PAIRWISE;
3215 else
3216 key.type = NL80211_KEYTYPE_GROUP;
3217 }
3218
3219 /* for now */
3220 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3221 key.type != NL80211_KEYTYPE_GROUP)
3222 return -EINVAL;
3223
Johannes Berg4c476992010-10-04 21:36:35 +02003224 if (!rdev->ops->del_key)
3225 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003226
Johannes Bergfffd0932009-07-08 14:22:54 +02003227 wdev_lock(dev->ieee80211_ptr);
3228 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003229
Johannes Berg0fa7b392015-01-23 11:10:12 +01003230 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003231 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3232 err = -ENOENT;
3233
Johannes Bergfffd0932009-07-08 14:22:54 +02003234 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003235 err = rdev_del_key(rdev, dev, key.idx,
3236 key.type == NL80211_KEYTYPE_PAIRWISE,
3237 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003238
Johannes Berg3d23e342009-09-29 23:27:28 +02003239#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003240 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003241 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003242 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003243 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003244 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3245 }
3246#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003247 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003248
Johannes Berg41ade002007-12-19 02:03:29 +01003249 return err;
3250}
3251
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303252/* This function returns an error or the number of nested attributes */
3253static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3254{
3255 struct nlattr *attr;
3256 int n_entries = 0, tmp;
3257
3258 nla_for_each_nested(attr, nl_attr, tmp) {
3259 if (nla_len(attr) != ETH_ALEN)
3260 return -EINVAL;
3261
3262 n_entries++;
3263 }
3264
3265 return n_entries;
3266}
3267
3268/*
3269 * This function parses ACL information and allocates memory for ACL data.
3270 * On successful return, the calling function is responsible to free the
3271 * ACL buffer returned by this function.
3272 */
3273static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3274 struct genl_info *info)
3275{
3276 enum nl80211_acl_policy acl_policy;
3277 struct nlattr *attr;
3278 struct cfg80211_acl_data *acl;
3279 int i = 0, n_entries, tmp;
3280
3281 if (!wiphy->max_acl_mac_addrs)
3282 return ERR_PTR(-EOPNOTSUPP);
3283
3284 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3285 return ERR_PTR(-EINVAL);
3286
3287 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3288 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3289 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3290 return ERR_PTR(-EINVAL);
3291
3292 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3293 return ERR_PTR(-EINVAL);
3294
3295 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3296 if (n_entries < 0)
3297 return ERR_PTR(n_entries);
3298
3299 if (n_entries > wiphy->max_acl_mac_addrs)
3300 return ERR_PTR(-ENOTSUPP);
3301
3302 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3303 GFP_KERNEL);
3304 if (!acl)
3305 return ERR_PTR(-ENOMEM);
3306
3307 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3308 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3309 i++;
3310 }
3311
3312 acl->n_acl_entries = n_entries;
3313 acl->acl_policy = acl_policy;
3314
3315 return acl;
3316}
3317
3318static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3319{
3320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3321 struct net_device *dev = info->user_ptr[1];
3322 struct cfg80211_acl_data *acl;
3323 int err;
3324
3325 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3326 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3327 return -EOPNOTSUPP;
3328
3329 if (!dev->ieee80211_ptr->beacon_interval)
3330 return -EINVAL;
3331
3332 acl = parse_acl_data(&rdev->wiphy, info);
3333 if (IS_ERR(acl))
3334 return PTR_ERR(acl);
3335
3336 err = rdev_set_mac_acl(rdev, dev, acl);
3337
3338 kfree(acl);
3339
3340 return err;
3341}
3342
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003343static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003344 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003345{
Johannes Berg88600202012-02-13 15:17:18 +01003346 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003347
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003348 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3349 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3350 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3351 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003352 return -EINVAL;
3353
Johannes Berg88600202012-02-13 15:17:18 +01003354 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003355
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003356 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3357 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3358 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003359 if (!bcn->head_len)
3360 return -EINVAL;
3361 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003362 }
3363
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003364 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3365 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3366 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003367 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003368 }
3369
Johannes Berg4c476992010-10-04 21:36:35 +02003370 if (!haveinfo)
3371 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003372
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003373 if (attrs[NL80211_ATTR_IE]) {
3374 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3375 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003376 }
3377
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003378 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003379 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003380 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003381 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003382 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003383 }
3384
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003385 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003386 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003387 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003388 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003389 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003390 }
3391
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003392 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3393 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3394 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003395 }
3396
Johannes Berg88600202012-02-13 15:17:18 +01003397 return 0;
3398}
3399
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003400static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3401 struct cfg80211_ap_settings *params)
3402{
3403 struct wireless_dev *wdev;
3404 bool ret = false;
3405
Johannes Berg53873f12016-05-03 16:52:04 +03003406 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003407 if (wdev->iftype != NL80211_IFTYPE_AP &&
3408 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3409 continue;
3410
Johannes Berg683b6d32012-11-08 21:25:48 +01003411 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003412 continue;
3413
Johannes Berg683b6d32012-11-08 21:25:48 +01003414 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003415 ret = true;
3416 break;
3417 }
3418
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003419 return ret;
3420}
3421
Jouni Malinene39e5b52012-09-30 19:29:39 +03003422static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3423 enum nl80211_auth_type auth_type,
3424 enum nl80211_commands cmd)
3425{
3426 if (auth_type > NL80211_AUTHTYPE_MAX)
3427 return false;
3428
3429 switch (cmd) {
3430 case NL80211_CMD_AUTHENTICATE:
3431 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3432 auth_type == NL80211_AUTHTYPE_SAE)
3433 return false;
3434 return true;
3435 case NL80211_CMD_CONNECT:
3436 case NL80211_CMD_START_AP:
3437 /* SAE not supported yet */
3438 if (auth_type == NL80211_AUTHTYPE_SAE)
3439 return false;
3440 return true;
3441 default:
3442 return false;
3443 }
3444}
3445
Johannes Berg88600202012-02-13 15:17:18 +01003446static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3447{
3448 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3449 struct net_device *dev = info->user_ptr[1];
3450 struct wireless_dev *wdev = dev->ieee80211_ptr;
3451 struct cfg80211_ap_settings params;
3452 int err;
3453
3454 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3455 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3456 return -EOPNOTSUPP;
3457
3458 if (!rdev->ops->start_ap)
3459 return -EOPNOTSUPP;
3460
3461 if (wdev->beacon_interval)
3462 return -EALREADY;
3463
3464 memset(&params, 0, sizeof(params));
3465
3466 /* these are required for START_AP */
3467 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3468 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3469 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3470 return -EINVAL;
3471
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003472 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003473 if (err)
3474 return err;
3475
3476 params.beacon_interval =
3477 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3478 params.dtim_period =
3479 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3480
3481 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3482 if (err)
3483 return err;
3484
3485 /*
3486 * In theory, some of these attributes should be required here
3487 * but since they were not used when the command was originally
3488 * added, keep them optional for old user space programs to let
3489 * them continue to work with drivers that do not need the
3490 * additional information -- drivers must check!
3491 */
3492 if (info->attrs[NL80211_ATTR_SSID]) {
3493 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3494 params.ssid_len =
3495 nla_len(info->attrs[NL80211_ATTR_SSID]);
3496 if (params.ssid_len == 0 ||
3497 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3498 return -EINVAL;
3499 }
3500
3501 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3502 params.hidden_ssid = nla_get_u32(
3503 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3504 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3505 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3506 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3507 return -EINVAL;
3508 }
3509
3510 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3511
3512 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3513 params.auth_type = nla_get_u32(
3514 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003515 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3516 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003517 return -EINVAL;
3518 } else
3519 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3520
3521 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3522 NL80211_MAX_NR_CIPHER_SUITES);
3523 if (err)
3524 return err;
3525
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303526 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3527 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3528 return -EOPNOTSUPP;
3529 params.inactivity_timeout = nla_get_u16(
3530 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3531 }
3532
Johannes Berg53cabad2012-11-14 15:17:28 +01003533 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3534 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3535 return -EINVAL;
3536 params.p2p_ctwindow =
3537 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3538 if (params.p2p_ctwindow > 127)
3539 return -EINVAL;
3540 if (params.p2p_ctwindow != 0 &&
3541 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3542 return -EINVAL;
3543 }
3544
3545 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3546 u8 tmp;
3547
3548 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3549 return -EINVAL;
3550 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3551 if (tmp > 1)
3552 return -EINVAL;
3553 params.p2p_opp_ps = tmp;
3554 if (params.p2p_opp_ps != 0 &&
3555 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3556 return -EINVAL;
3557 }
3558
Johannes Bergaa430da2012-05-16 23:50:18 +02003559 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003560 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3561 if (err)
3562 return err;
3563 } else if (wdev->preset_chandef.chan) {
3564 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003565 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003566 return -EINVAL;
3567
Arik Nemtsov923b3522015-07-08 15:41:44 +03003568 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3569 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003570 return -EINVAL;
3571
Eliad Peller18998c32014-09-10 14:07:34 +03003572 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3573 params.smps_mode =
3574 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3575 switch (params.smps_mode) {
3576 case NL80211_SMPS_OFF:
3577 break;
3578 case NL80211_SMPS_STATIC:
3579 if (!(rdev->wiphy.features &
3580 NL80211_FEATURE_STATIC_SMPS))
3581 return -EINVAL;
3582 break;
3583 case NL80211_SMPS_DYNAMIC:
3584 if (!(rdev->wiphy.features &
3585 NL80211_FEATURE_DYNAMIC_SMPS))
3586 return -EINVAL;
3587 break;
3588 default:
3589 return -EINVAL;
3590 }
3591 } else {
3592 params.smps_mode = NL80211_SMPS_OFF;
3593 }
3594
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303595 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3596 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3597 return -EOPNOTSUPP;
3598
Ola Olsson4baf6be2015-10-29 07:04:58 +01003599 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3600 params.acl = parse_acl_data(&rdev->wiphy, info);
3601 if (IS_ERR(params.acl))
3602 return PTR_ERR(params.acl);
3603 }
3604
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003605 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003606 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003607 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003608 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003609 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003610 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003611 wdev->ssid_len = params.ssid_len;
3612 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003613 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003614 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303615
3616 kfree(params.acl);
3617
Johannes Berg56d18932011-05-09 18:41:15 +02003618 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003619}
3620
Johannes Berg88600202012-02-13 15:17:18 +01003621static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3622{
3623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3624 struct net_device *dev = info->user_ptr[1];
3625 struct wireless_dev *wdev = dev->ieee80211_ptr;
3626 struct cfg80211_beacon_data params;
3627 int err;
3628
3629 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3630 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3631 return -EOPNOTSUPP;
3632
3633 if (!rdev->ops->change_beacon)
3634 return -EOPNOTSUPP;
3635
3636 if (!wdev->beacon_interval)
3637 return -EINVAL;
3638
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003639 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003640 if (err)
3641 return err;
3642
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003643 wdev_lock(wdev);
3644 err = rdev_change_beacon(rdev, dev, &params);
3645 wdev_unlock(wdev);
3646
3647 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003648}
3649
3650static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003651{
Johannes Berg4c476992010-10-04 21:36:35 +02003652 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3653 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003654
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003655 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003656}
3657
Johannes Berg5727ef12007-12-19 02:03:34 +01003658static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3659 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3660 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3661 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003662 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003663 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003664 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003665};
3666
Johannes Bergeccb8e82009-05-11 21:57:56 +03003667static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003668 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003669 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003670{
3671 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003672 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003673 int flag;
3674
Johannes Bergeccb8e82009-05-11 21:57:56 +03003675 /*
3676 * Try parsing the new attribute first so userspace
3677 * can specify both for older kernels.
3678 */
3679 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3680 if (nla) {
3681 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003682
Johannes Bergeccb8e82009-05-11 21:57:56 +03003683 sta_flags = nla_data(nla);
3684 params->sta_flags_mask = sta_flags->mask;
3685 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003686 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003687 if ((params->sta_flags_mask |
3688 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3689 return -EINVAL;
3690 return 0;
3691 }
3692
3693 /* if present, parse the old attribute */
3694
3695 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003696 if (!nla)
3697 return 0;
3698
3699 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3700 nla, sta_flags_policy))
3701 return -EINVAL;
3702
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003703 /*
3704 * Only allow certain flags for interface types so that
3705 * other attributes are silently ignored. Remember that
3706 * this is backward compatibility code with old userspace
3707 * and shouldn't be hit in other cases anyway.
3708 */
3709 switch (iftype) {
3710 case NL80211_IFTYPE_AP:
3711 case NL80211_IFTYPE_AP_VLAN:
3712 case NL80211_IFTYPE_P2P_GO:
3713 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3714 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3715 BIT(NL80211_STA_FLAG_WME) |
3716 BIT(NL80211_STA_FLAG_MFP);
3717 break;
3718 case NL80211_IFTYPE_P2P_CLIENT:
3719 case NL80211_IFTYPE_STATION:
3720 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3721 BIT(NL80211_STA_FLAG_TDLS_PEER);
3722 break;
3723 case NL80211_IFTYPE_MESH_POINT:
3724 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3725 BIT(NL80211_STA_FLAG_MFP) |
3726 BIT(NL80211_STA_FLAG_AUTHORIZED);
3727 default:
3728 return -EINVAL;
3729 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003730
Johannes Berg3383b5a2012-05-10 20:14:43 +02003731 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3732 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003733 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003734
Johannes Berg3383b5a2012-05-10 20:14:43 +02003735 /* no longer support new API additions in old API */
3736 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3737 return -EINVAL;
3738 }
3739 }
3740
Johannes Berg5727ef12007-12-19 02:03:34 +01003741 return 0;
3742}
3743
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003744static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3745 int attr)
3746{
3747 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003748 u32 bitrate;
3749 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003750 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003751
3752 rate = nla_nest_start(msg, attr);
3753 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003754 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003755
3756 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3757 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003758 /* report 16-bit bitrate only if we can */
3759 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003760 if (bitrate > 0 &&
3761 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3762 return false;
3763 if (bitrate_compat > 0 &&
3764 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3765 return false;
3766
Johannes Bergb51f3be2015-01-15 16:14:02 +01003767 switch (info->bw) {
3768 case RATE_INFO_BW_5:
3769 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3770 break;
3771 case RATE_INFO_BW_10:
3772 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3773 break;
3774 default:
3775 WARN_ON(1);
3776 /* fall through */
3777 case RATE_INFO_BW_20:
3778 rate_flg = 0;
3779 break;
3780 case RATE_INFO_BW_40:
3781 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3782 break;
3783 case RATE_INFO_BW_80:
3784 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3785 break;
3786 case RATE_INFO_BW_160:
3787 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3788 break;
3789 }
3790
3791 if (rate_flg && nla_put_flag(msg, rate_flg))
3792 return false;
3793
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003794 if (info->flags & RATE_INFO_FLAGS_MCS) {
3795 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3796 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003797 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3798 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3799 return false;
3800 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3801 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3802 return false;
3803 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3804 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003805 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3806 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3807 return false;
3808 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003809
3810 nla_nest_end(msg, rate);
3811 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003812}
3813
Felix Fietkau119363c2013-04-22 16:29:30 +02003814static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3815 int id)
3816{
3817 void *attr;
3818 int i = 0;
3819
3820 if (!mask)
3821 return true;
3822
3823 attr = nla_nest_start(msg, id);
3824 if (!attr)
3825 return false;
3826
3827 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3828 if (!(mask & BIT(i)))
3829 continue;
3830
3831 if (nla_put_u8(msg, i, signal[i]))
3832 return false;
3833 }
3834
3835 nla_nest_end(msg, attr);
3836
3837 return true;
3838}
3839
Johannes Bergcf5ead82014-11-14 17:14:00 +01003840static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3841 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003842 struct cfg80211_registered_device *rdev,
3843 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003844 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003845{
3846 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003847 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003848
Johannes Bergcf5ead82014-11-14 17:14:00 +01003849 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003850 if (!hdr)
3851 return -1;
3852
David S. Miller9360ffd2012-03-29 04:41:26 -04003853 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3854 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3855 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3856 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003857
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003858 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3859 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003860 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003861
3862#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003863 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303864 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003865 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3866 sinfo->memb)) \
3867 goto nla_put_failure; \
3868 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003869#define PUT_SINFO_U64(attr, memb) do { \
3870 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3871 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3872 sinfo->memb, NL80211_STA_INFO_PAD)) \
3873 goto nla_put_failure; \
3874 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003875
3876 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3877 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3878
3879 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3880 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003881 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003882 (u32)sinfo->rx_bytes))
3883 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003884
3885 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3886 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003887 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3888 (u32)sinfo->tx_bytes))
3889 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003890
Johannes Bergd686b922016-04-26 09:54:11 +02003891 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3892 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003893 PUT_SINFO(LLID, llid, u16);
3894 PUT_SINFO(PLID, plid, u16);
3895 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003896 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003897
John W. Linville66266b32012-03-15 13:25:41 -04003898 switch (rdev->wiphy.signal_type) {
3899 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003900 PUT_SINFO(SIGNAL, signal, u8);
3901 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003902 break;
3903 default:
3904 break;
3905 }
Johannes Berg319090b2014-11-17 14:08:11 +01003906 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003907 if (!nl80211_put_signal(msg, sinfo->chains,
3908 sinfo->chain_signal,
3909 NL80211_STA_INFO_CHAIN_SIGNAL))
3910 goto nla_put_failure;
3911 }
Johannes Berg319090b2014-11-17 14:08:11 +01003912 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003913 if (!nl80211_put_signal(msg, sinfo->chains,
3914 sinfo->chain_signal_avg,
3915 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3916 goto nla_put_failure;
3917 }
Johannes Berg319090b2014-11-17 14:08:11 +01003918 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003919 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3920 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003921 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003922 }
Johannes Berg319090b2014-11-17 14:08:11 +01003923 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003924 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3925 NL80211_STA_INFO_RX_BITRATE))
3926 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003927 }
Johannes Berg319090b2014-11-17 14:08:11 +01003928
3929 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3930 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3931 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3932 PUT_SINFO(TX_FAILED, tx_failed, u32);
3933 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3934 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3935 PUT_SINFO(LOCAL_PM, local_pm, u32);
3936 PUT_SINFO(PEER_PM, peer_pm, u32);
3937 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3938
3939 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003940 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3941 if (!bss_param)
3942 goto nla_put_failure;
3943
David S. Miller9360ffd2012-03-29 04:41:26 -04003944 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3945 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3946 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3947 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3948 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3949 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3950 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3951 sinfo->bss_param.dtim_period) ||
3952 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3953 sinfo->bss_param.beacon_interval))
3954 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003955
3956 nla_nest_end(msg, bss_param);
3957 }
Johannes Berg319090b2014-11-17 14:08:11 +01003958 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003959 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3960 sizeof(struct nl80211_sta_flag_update),
3961 &sinfo->sta_flags))
3962 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003963
Johannes Bergd686b922016-04-26 09:54:11 +02003964 PUT_SINFO_U64(T_OFFSET, t_offset);
3965 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3966 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003967 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003968
3969#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003970#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003971
3972 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3973 struct nlattr *tidsattr;
3974 int tid;
3975
3976 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3977 if (!tidsattr)
3978 goto nla_put_failure;
3979
3980 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3981 struct cfg80211_tid_stats *tidstats;
3982 struct nlattr *tidattr;
3983
3984 tidstats = &sinfo->pertid[tid];
3985
3986 if (!tidstats->filled)
3987 continue;
3988
3989 tidattr = nla_nest_start(msg, tid + 1);
3990 if (!tidattr)
3991 goto nla_put_failure;
3992
Johannes Bergd686b922016-04-26 09:54:11 +02003993#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003994 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003995 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3996 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003997 goto nla_put_failure; \
3998 } while (0)
3999
Johannes Bergd686b922016-04-26 09:54:11 +02004000 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4001 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4002 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4003 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004004
Johannes Bergd686b922016-04-26 09:54:11 +02004005#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004006 nla_nest_end(msg, tidattr);
4007 }
4008
4009 nla_nest_end(msg, tidsattr);
4010 }
4011
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004012 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004013
Johannes Berg319090b2014-11-17 14:08:11 +01004014 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004015 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4016 sinfo->assoc_req_ies))
4017 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004018
Johannes Berg053c0952015-01-16 22:09:00 +01004019 genlmsg_end(msg, hdr);
4020 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004021
4022 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004023 genlmsg_cancel(msg, hdr);
4024 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004025}
4026
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004027static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004028 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004029{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004030 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004031 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004032 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004033 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004034 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004035 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004036
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004037 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004038 if (err)
4039 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004040
Johannes Berg97990a02013-04-19 01:02:55 +02004041 if (!wdev->netdev) {
4042 err = -EINVAL;
4043 goto out_err;
4044 }
4045
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004046 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004047 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004048 goto out_err;
4049 }
4050
Johannes Bergbba95fe2008-07-29 13:22:51 +02004051 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004052 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004053 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004054 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004055 if (err == -ENOENT)
4056 break;
4057 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004058 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004059
Johannes Bergcf5ead82014-11-14 17:14:00 +01004060 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004061 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004062 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004063 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004064 &sinfo) < 0)
4065 goto out;
4066
4067 sta_idx++;
4068 }
4069
Johannes Bergbba95fe2008-07-29 13:22:51 +02004070 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004071 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004072 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004073 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004074 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004075
4076 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004077}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004078
Johannes Berg5727ef12007-12-19 02:03:34 +01004079static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4080{
Johannes Berg4c476992010-10-04 21:36:35 +02004081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4082 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004083 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004084 struct sk_buff *msg;
4085 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004086 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004087
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004088 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004089
4090 if (!info->attrs[NL80211_ATTR_MAC])
4091 return -EINVAL;
4092
4093 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4094
Johannes Berg4c476992010-10-04 21:36:35 +02004095 if (!rdev->ops->get_station)
4096 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004097
Hila Gonene35e4d22012-06-27 17:19:42 +03004098 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004099 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004100 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004101
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004103 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004104 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004105
Johannes Bergcf5ead82014-11-14 17:14:00 +01004106 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4107 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004108 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004109 nlmsg_free(msg);
4110 return -ENOBUFS;
4111 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004112
Johannes Berg4c476992010-10-04 21:36:35 +02004113 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004114}
4115
Johannes Berg77ee7c82013-02-15 00:48:33 +01004116int cfg80211_check_station_change(struct wiphy *wiphy,
4117 struct station_parameters *params,
4118 enum cfg80211_station_type statype)
4119{
Ayala Bekere4208422015-10-23 11:20:06 +03004120 if (params->listen_interval != -1 &&
4121 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004122 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004123
Ayala Beker17b94242016-03-17 15:41:38 +02004124 if (params->support_p2p_ps != -1 &&
4125 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4126 return -EINVAL;
4127
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004128 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004129 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4130 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004131 return -EINVAL;
4132
4133 /* When you run into this, adjust the code below for the new flag */
4134 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4135
4136 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004137 case CFG80211_STA_MESH_PEER_KERNEL:
4138 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004139 /*
4140 * No ignoring the TDLS flag here -- the userspace mesh
4141 * code doesn't have the bug of including TDLS in the
4142 * mask everywhere.
4143 */
4144 if (params->sta_flags_mask &
4145 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4146 BIT(NL80211_STA_FLAG_MFP) |
4147 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4148 return -EINVAL;
4149 break;
4150 case CFG80211_STA_TDLS_PEER_SETUP:
4151 case CFG80211_STA_TDLS_PEER_ACTIVE:
4152 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4153 return -EINVAL;
4154 /* ignore since it can't change */
4155 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4156 break;
4157 default:
4158 /* disallow mesh-specific things */
4159 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4160 return -EINVAL;
4161 if (params->local_pm)
4162 return -EINVAL;
4163 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4164 return -EINVAL;
4165 }
4166
4167 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4168 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4169 /* TDLS can't be set, ... */
4170 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4171 return -EINVAL;
4172 /*
4173 * ... but don't bother the driver with it. This works around
4174 * a hostapd/wpa_supplicant issue -- it always includes the
4175 * TLDS_PEER flag in the mask even for AP mode.
4176 */
4177 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4178 }
4179
Ayala Beker47edb112015-09-21 15:49:53 +03004180 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4181 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004182 /* reject other things that can't change */
4183 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4184 return -EINVAL;
4185 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4186 return -EINVAL;
4187 if (params->supported_rates)
4188 return -EINVAL;
4189 if (params->ext_capab || params->ht_capa || params->vht_capa)
4190 return -EINVAL;
4191 }
4192
Ayala Beker47edb112015-09-21 15:49:53 +03004193 if (statype != CFG80211_STA_AP_CLIENT &&
4194 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004195 if (params->vlan)
4196 return -EINVAL;
4197 }
4198
4199 switch (statype) {
4200 case CFG80211_STA_AP_MLME_CLIENT:
4201 /* Use this only for authorizing/unauthorizing a station */
4202 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4203 return -EOPNOTSUPP;
4204 break;
4205 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004206 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004207 /* accept only the listed bits */
4208 if (params->sta_flags_mask &
4209 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4210 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4211 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4212 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4213 BIT(NL80211_STA_FLAG_WME) |
4214 BIT(NL80211_STA_FLAG_MFP)))
4215 return -EINVAL;
4216
4217 /* but authenticated/associated only if driver handles it */
4218 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4219 params->sta_flags_mask &
4220 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4221 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4222 return -EINVAL;
4223 break;
4224 case CFG80211_STA_IBSS:
4225 case CFG80211_STA_AP_STA:
4226 /* reject any changes other than AUTHORIZED */
4227 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4228 return -EINVAL;
4229 break;
4230 case CFG80211_STA_TDLS_PEER_SETUP:
4231 /* reject any changes other than AUTHORIZED or WME */
4232 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4233 BIT(NL80211_STA_FLAG_WME)))
4234 return -EINVAL;
4235 /* force (at least) rates when authorizing */
4236 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4237 !params->supported_rates)
4238 return -EINVAL;
4239 break;
4240 case CFG80211_STA_TDLS_PEER_ACTIVE:
4241 /* reject any changes */
4242 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004243 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004244 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4245 return -EINVAL;
4246 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004247 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004248 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4249 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004250 return -EINVAL;
4251 break;
4252 }
4253
4254 return 0;
4255}
4256EXPORT_SYMBOL(cfg80211_check_station_change);
4257
Johannes Berg5727ef12007-12-19 02:03:34 +01004258/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004259 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004260 */
Johannes Berg80b99892011-11-18 16:23:01 +01004261static struct net_device *get_vlan(struct genl_info *info,
4262 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004263{
Johannes Berg463d0182009-07-14 00:33:35 +02004264 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004265 struct net_device *v;
4266 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004267
Johannes Berg80b99892011-11-18 16:23:01 +01004268 if (!vlanattr)
4269 return NULL;
4270
4271 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4272 if (!v)
4273 return ERR_PTR(-ENODEV);
4274
4275 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4276 ret = -EINVAL;
4277 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004278 }
Johannes Berg80b99892011-11-18 16:23:01 +01004279
Johannes Berg77ee7c82013-02-15 00:48:33 +01004280 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4281 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4282 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4283 ret = -EINVAL;
4284 goto error;
4285 }
4286
Johannes Berg80b99892011-11-18 16:23:01 +01004287 if (!netif_running(v)) {
4288 ret = -ENETDOWN;
4289 goto error;
4290 }
4291
4292 return v;
4293 error:
4294 dev_put(v);
4295 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004296}
4297
Johannes Berg94e860f2014-01-20 23:58:15 +01004298static const struct nla_policy
4299nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004300 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4301 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4302};
4303
Johannes Bergff276692013-02-15 00:09:01 +01004304static int nl80211_parse_sta_wme(struct genl_info *info,
4305 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004306{
Jouni Malinendf881292013-02-14 21:10:54 +02004307 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4308 struct nlattr *nla;
4309 int err;
4310
Jouni Malinendf881292013-02-14 21:10:54 +02004311 /* parse WME attributes if present */
4312 if (!info->attrs[NL80211_ATTR_STA_WME])
4313 return 0;
4314
4315 nla = info->attrs[NL80211_ATTR_STA_WME];
4316 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4317 nl80211_sta_wme_policy);
4318 if (err)
4319 return err;
4320
4321 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4322 params->uapsd_queues = nla_get_u8(
4323 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4324 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4325 return -EINVAL;
4326
4327 if (tb[NL80211_STA_WME_MAX_SP])
4328 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4329
4330 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4331 return -EINVAL;
4332
4333 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4334
4335 return 0;
4336}
4337
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304338static int nl80211_parse_sta_channel_info(struct genl_info *info,
4339 struct station_parameters *params)
4340{
4341 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4342 params->supported_channels =
4343 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4344 params->supported_channels_len =
4345 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4346 /*
4347 * Need to include at least one (first channel, number of
4348 * channels) tuple for each subband, and must have proper
4349 * tuples for the rest of the data as well.
4350 */
4351 if (params->supported_channels_len < 2)
4352 return -EINVAL;
4353 if (params->supported_channels_len % 2)
4354 return -EINVAL;
4355 }
4356
4357 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4358 params->supported_oper_classes =
4359 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4360 params->supported_oper_classes_len =
4361 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4362 /*
4363 * The value of the Length field of the Supported Operating
4364 * Classes element is between 2 and 253.
4365 */
4366 if (params->supported_oper_classes_len < 2 ||
4367 params->supported_oper_classes_len > 253)
4368 return -EINVAL;
4369 }
4370 return 0;
4371}
4372
Johannes Bergff276692013-02-15 00:09:01 +01004373static int nl80211_set_station_tdls(struct genl_info *info,
4374 struct station_parameters *params)
4375{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304376 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004377 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004378 if (info->attrs[NL80211_ATTR_PEER_AID])
4379 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004380 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4381 params->ht_capa =
4382 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4383 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4384 params->vht_capa =
4385 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4386
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304387 err = nl80211_parse_sta_channel_info(info, params);
4388 if (err)
4389 return err;
4390
Johannes Bergff276692013-02-15 00:09:01 +01004391 return nl80211_parse_sta_wme(info, params);
4392}
4393
Johannes Berg5727ef12007-12-19 02:03:34 +01004394static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4395{
Johannes Berg4c476992010-10-04 21:36:35 +02004396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004397 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004398 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004399 u8 *mac_addr;
4400 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004401
4402 memset(&params, 0, sizeof(params));
4403
Johannes Berg77ee7c82013-02-15 00:48:33 +01004404 if (!rdev->ops->change_station)
4405 return -EOPNOTSUPP;
4406
Ayala Bekere4208422015-10-23 11:20:06 +03004407 /*
4408 * AID and listen_interval properties can be set only for unassociated
4409 * station. Include these parameters here and will check them in
4410 * cfg80211_check_station_change().
4411 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004412 if (info->attrs[NL80211_ATTR_STA_AID])
4413 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004414
4415 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4416 params.listen_interval =
4417 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4418 else
4419 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004420
Ayala Beker17b94242016-03-17 15:41:38 +02004421 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4422 u8 tmp;
4423
4424 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4425 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4426 return -EINVAL;
4427
4428 params.support_p2p_ps = tmp;
4429 } else {
4430 params.support_p2p_ps = -1;
4431 }
4432
Johannes Berg5727ef12007-12-19 02:03:34 +01004433 if (!info->attrs[NL80211_ATTR_MAC])
4434 return -EINVAL;
4435
4436 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4437
4438 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4439 params.supported_rates =
4440 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4441 params.supported_rates_len =
4442 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4443 }
4444
Jouni Malinen9d62a982013-02-14 21:10:13 +02004445 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4446 params.capability =
4447 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4448 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4449 }
4450
4451 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4452 params.ext_capab =
4453 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4454 params.ext_capab_len =
4455 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4456 }
4457
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004458 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004459 return -EINVAL;
4460
Johannes Bergf8bacc22013-02-14 23:27:01 +01004461 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004462 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004463 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4464 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4465 return -EINVAL;
4466 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004467
Johannes Bergf8bacc22013-02-14 23:27:01 +01004468 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004469 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004470 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4471 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4472 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004473 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4474 params.peer_aid = nla_get_u16(
4475 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4476 if (params.peer_aid > IEEE80211_MAX_AID)
4477 return -EINVAL;
4478 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004479 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4480 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004481
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004482 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4483 enum nl80211_mesh_power_mode pm = nla_get_u32(
4484 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4485
4486 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4487 pm > NL80211_MESH_POWER_MAX)
4488 return -EINVAL;
4489
4490 params.local_pm = pm;
4491 }
4492
Johannes Berg77ee7c82013-02-15 00:48:33 +01004493 /* Include parameters for TDLS peer (will check later) */
4494 err = nl80211_set_station_tdls(info, &params);
4495 if (err)
4496 return err;
4497
4498 params.vlan = get_vlan(info, rdev);
4499 if (IS_ERR(params.vlan))
4500 return PTR_ERR(params.vlan);
4501
Johannes Berga97f4422009-06-18 17:23:43 +02004502 switch (dev->ieee80211_ptr->iftype) {
4503 case NL80211_IFTYPE_AP:
4504 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004505 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004506 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004507 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004508 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004509 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004510 break;
4511 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004512 err = -EOPNOTSUPP;
4513 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004514 }
4515
Johannes Berg77ee7c82013-02-15 00:48:33 +01004516 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004517 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004518
Johannes Berg77ee7c82013-02-15 00:48:33 +01004519 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004520 if (params.vlan)
4521 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004522
Johannes Berg5727ef12007-12-19 02:03:34 +01004523 return err;
4524}
4525
4526static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4527{
Johannes Berg4c476992010-10-04 21:36:35 +02004528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004529 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004530 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004531 struct station_parameters params;
4532 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004533 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4534 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004535
4536 memset(&params, 0, sizeof(params));
4537
Johannes Berg984c3112013-02-14 23:43:25 +01004538 if (!rdev->ops->add_station)
4539 return -EOPNOTSUPP;
4540
Johannes Berg5727ef12007-12-19 02:03:34 +01004541 if (!info->attrs[NL80211_ATTR_MAC])
4542 return -EINVAL;
4543
Johannes Berg5727ef12007-12-19 02:03:34 +01004544 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4545 return -EINVAL;
4546
4547 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4548 return -EINVAL;
4549
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004550 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4551 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004552 return -EINVAL;
4553
Johannes Berg5727ef12007-12-19 02:03:34 +01004554 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4555 params.supported_rates =
4556 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4557 params.supported_rates_len =
4558 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4559 params.listen_interval =
4560 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004561
Ayala Beker17b94242016-03-17 15:41:38 +02004562 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4563 u8 tmp;
4564
4565 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4566 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4567 return -EINVAL;
4568
4569 params.support_p2p_ps = tmp;
4570 } else {
4571 /*
4572 * if not specified, assume it's supported for P2P GO interface,
4573 * and is NOT supported for AP interface
4574 */
4575 params.support_p2p_ps =
4576 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4577 }
4578
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004579 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004580 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004581 else
4582 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004583 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4584 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004585
Jouni Malinen9d62a982013-02-14 21:10:13 +02004586 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4587 params.capability =
4588 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4589 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4590 }
4591
4592 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4593 params.ext_capab =
4594 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4595 params.ext_capab_len =
4596 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4597 }
4598
Jouni Malinen36aedc92008-08-25 11:58:58 +03004599 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4600 params.ht_capa =
4601 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004602
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004603 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4604 params.vht_capa =
4605 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4606
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004607 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4608 params.opmode_notif_used = true;
4609 params.opmode_notif =
4610 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4611 }
4612
Johannes Bergf8bacc22013-02-14 23:27:01 +01004613 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004614 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004615 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4616 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4617 return -EINVAL;
4618 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004619
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304620 err = nl80211_parse_sta_channel_info(info, &params);
4621 if (err)
4622 return err;
4623
Johannes Bergff276692013-02-15 00:09:01 +01004624 err = nl80211_parse_sta_wme(info, &params);
4625 if (err)
4626 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004627
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004628 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004629 return -EINVAL;
4630
Johannes Berg496fcc22015-03-12 08:53:27 +02004631 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4632 * as userspace might just pass through the capabilities from the IEs
4633 * directly, rather than enforcing this restriction and returning an
4634 * error in this case.
4635 */
4636 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4637 params.ht_capa = NULL;
4638 params.vht_capa = NULL;
4639 }
4640
Johannes Berg77ee7c82013-02-15 00:48:33 +01004641 /* When you run into this, adjust the code below for the new flag */
4642 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4643
Johannes Bergbdd90d52011-12-14 12:20:27 +01004644 switch (dev->ieee80211_ptr->iftype) {
4645 case NL80211_IFTYPE_AP:
4646 case NL80211_IFTYPE_AP_VLAN:
4647 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004648 /* ignore WME attributes if iface/sta is not capable */
4649 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4650 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4651 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004652
Johannes Bergbdd90d52011-12-14 12:20:27 +01004653 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004654 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4655 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004656 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004657 /* but don't bother the driver with it */
4658 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004659
Johannes Bergd582cff2012-10-26 17:53:44 +02004660 /* allow authenticated/associated only if driver handles it */
4661 if (!(rdev->wiphy.features &
4662 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004663 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004664 return -EINVAL;
4665
Johannes Bergbda95eb2015-11-26 16:26:13 +01004666 /* Older userspace, or userspace wanting to be compatible with
4667 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4668 * and assoc flags in the mask, but assumes the station will be
4669 * added as associated anyway since this was the required driver
4670 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4671 * introduced.
4672 * In order to not bother drivers with this quirk in the API
4673 * set the flags in both the mask and set for new stations in
4674 * this case.
4675 */
4676 if (!(params.sta_flags_mask & auth_assoc)) {
4677 params.sta_flags_mask |= auth_assoc;
4678 params.sta_flags_set |= auth_assoc;
4679 }
4680
Johannes Bergbdd90d52011-12-14 12:20:27 +01004681 /* must be last in here for error handling */
4682 params.vlan = get_vlan(info, rdev);
4683 if (IS_ERR(params.vlan))
4684 return PTR_ERR(params.vlan);
4685 break;
4686 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004687 /* ignore uAPSD data */
4688 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4689
Johannes Bergd582cff2012-10-26 17:53:44 +02004690 /* associated is disallowed */
4691 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4692 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004693 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004694 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4695 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004696 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004697 break;
4698 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004699 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004700 /* ignore uAPSD data */
4701 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4702
Johannes Berg77ee7c82013-02-15 00:48:33 +01004703 /* these are disallowed */
4704 if (params.sta_flags_mask &
4705 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4706 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004707 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004708 /* Only TDLS peers can be added */
4709 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4710 return -EINVAL;
4711 /* Can only add if TDLS ... */
4712 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4713 return -EOPNOTSUPP;
4714 /* ... with external setup is supported */
4715 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4716 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004717 /*
4718 * Older wpa_supplicant versions always mark the TDLS peer
4719 * as authorized, but it shouldn't yet be.
4720 */
4721 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004722 break;
4723 default:
4724 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004725 }
4726
Johannes Bergbdd90d52011-12-14 12:20:27 +01004727 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004728
Hila Gonene35e4d22012-06-27 17:19:42 +03004729 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004730
Johannes Berg5727ef12007-12-19 02:03:34 +01004731 if (params.vlan)
4732 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004733 return err;
4734}
4735
4736static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4737{
Johannes Berg4c476992010-10-04 21:36:35 +02004738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4739 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004740 struct station_del_parameters params;
4741
4742 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004743
4744 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004745 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004746
Johannes Berge80cf852009-05-11 14:43:13 +02004747 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004748 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004749 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004750 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4751 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004752
Johannes Berg4c476992010-10-04 21:36:35 +02004753 if (!rdev->ops->del_station)
4754 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004755
Jouni Malinen98856862014-10-20 13:20:45 +03004756 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4757 params.subtype =
4758 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4759 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4760 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4761 return -EINVAL;
4762 } else {
4763 /* Default to Deauthentication frame */
4764 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4765 }
4766
4767 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4768 params.reason_code =
4769 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4770 if (params.reason_code == 0)
4771 return -EINVAL; /* 0 is reserved */
4772 } else {
4773 /* Default to reason code 2 */
4774 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4775 }
4776
Jouni Malinen89c771e2014-10-10 20:52:40 +03004777 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004778}
4779
Eric W. Biederman15e47302012-09-07 20:12:54 +00004780static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004781 int flags, struct net_device *dev,
4782 u8 *dst, u8 *next_hop,
4783 struct mpath_info *pinfo)
4784{
4785 void *hdr;
4786 struct nlattr *pinfoattr;
4787
Henning Rogge1ef4c852014-11-04 16:14:58 +01004788 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004789 if (!hdr)
4790 return -1;
4791
David S. Miller9360ffd2012-03-29 04:41:26 -04004792 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4793 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4794 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4795 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4796 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004797
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004798 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4799 if (!pinfoattr)
4800 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004801 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4802 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4803 pinfo->frame_qlen))
4804 goto nla_put_failure;
4805 if (((pinfo->filled & MPATH_INFO_SN) &&
4806 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4807 ((pinfo->filled & MPATH_INFO_METRIC) &&
4808 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4809 pinfo->metric)) ||
4810 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4811 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4812 pinfo->exptime)) ||
4813 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4814 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4815 pinfo->flags)) ||
4816 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4817 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4818 pinfo->discovery_timeout)) ||
4819 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4820 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4821 pinfo->discovery_retries)))
4822 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004823
4824 nla_nest_end(msg, pinfoattr);
4825
Johannes Berg053c0952015-01-16 22:09:00 +01004826 genlmsg_end(msg, hdr);
4827 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004828
4829 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004830 genlmsg_cancel(msg, hdr);
4831 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004832}
4833
4834static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004835 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004836{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004837 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004838 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004839 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004840 u8 dst[ETH_ALEN];
4841 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004842 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004843 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004844
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004845 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004846 if (err)
4847 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004848
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004849 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004850 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004851 goto out_err;
4852 }
4853
Johannes Berg97990a02013-04-19 01:02:55 +02004854 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004855 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004856 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004857 }
4858
Johannes Bergbba95fe2008-07-29 13:22:51 +02004859 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004860 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004861 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004862 if (err == -ENOENT)
4863 break;
4864 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004865 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004866
Eric W. Biederman15e47302012-09-07 20:12:54 +00004867 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004868 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004869 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004870 &pinfo) < 0)
4871 goto out;
4872
4873 path_idx++;
4874 }
4875
Johannes Bergbba95fe2008-07-29 13:22:51 +02004876 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004877 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004878 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004879 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004880 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004881 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004882}
4883
4884static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4885{
Johannes Berg4c476992010-10-04 21:36:35 +02004886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004887 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004888 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004889 struct mpath_info pinfo;
4890 struct sk_buff *msg;
4891 u8 *dst = NULL;
4892 u8 next_hop[ETH_ALEN];
4893
4894 memset(&pinfo, 0, sizeof(pinfo));
4895
4896 if (!info->attrs[NL80211_ATTR_MAC])
4897 return -EINVAL;
4898
4899 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4900
Johannes Berg4c476992010-10-04 21:36:35 +02004901 if (!rdev->ops->get_mpath)
4902 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004903
Johannes Berg4c476992010-10-04 21:36:35 +02004904 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4905 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004906
Hila Gonene35e4d22012-06-27 17:19:42 +03004907 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004908 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004909 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004910
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004911 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004912 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004913 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004914
Eric W. Biederman15e47302012-09-07 20:12:54 +00004915 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004916 dev, dst, next_hop, &pinfo) < 0) {
4917 nlmsg_free(msg);
4918 return -ENOBUFS;
4919 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004920
Johannes Berg4c476992010-10-04 21:36:35 +02004921 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004922}
4923
4924static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4925{
Johannes Berg4c476992010-10-04 21:36:35 +02004926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4927 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004928 u8 *dst = NULL;
4929 u8 *next_hop = NULL;
4930
4931 if (!info->attrs[NL80211_ATTR_MAC])
4932 return -EINVAL;
4933
4934 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4935 return -EINVAL;
4936
4937 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4938 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4939
Johannes Berg4c476992010-10-04 21:36:35 +02004940 if (!rdev->ops->change_mpath)
4941 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004942
Johannes Berg4c476992010-10-04 21:36:35 +02004943 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4944 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004945
Hila Gonene35e4d22012-06-27 17:19:42 +03004946 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004947}
Johannes Berg4c476992010-10-04 21:36:35 +02004948
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004949static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4950{
Johannes Berg4c476992010-10-04 21:36:35 +02004951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4952 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004953 u8 *dst = NULL;
4954 u8 *next_hop = NULL;
4955
4956 if (!info->attrs[NL80211_ATTR_MAC])
4957 return -EINVAL;
4958
4959 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4960 return -EINVAL;
4961
4962 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4963 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4964
Johannes Berg4c476992010-10-04 21:36:35 +02004965 if (!rdev->ops->add_mpath)
4966 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004967
Johannes Berg4c476992010-10-04 21:36:35 +02004968 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4969 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004970
Hila Gonene35e4d22012-06-27 17:19:42 +03004971 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004972}
4973
4974static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4975{
Johannes Berg4c476992010-10-04 21:36:35 +02004976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4977 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004978 u8 *dst = NULL;
4979
4980 if (info->attrs[NL80211_ATTR_MAC])
4981 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4982
Johannes Berg4c476992010-10-04 21:36:35 +02004983 if (!rdev->ops->del_mpath)
4984 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004985
Hila Gonene35e4d22012-06-27 17:19:42 +03004986 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004987}
4988
Henning Rogge66be7d22014-09-12 08:58:49 +02004989static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4990{
4991 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4992 int err;
4993 struct net_device *dev = info->user_ptr[1];
4994 struct mpath_info pinfo;
4995 struct sk_buff *msg;
4996 u8 *dst = NULL;
4997 u8 mpp[ETH_ALEN];
4998
4999 memset(&pinfo, 0, sizeof(pinfo));
5000
5001 if (!info->attrs[NL80211_ATTR_MAC])
5002 return -EINVAL;
5003
5004 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5005
5006 if (!rdev->ops->get_mpp)
5007 return -EOPNOTSUPP;
5008
5009 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5010 return -EOPNOTSUPP;
5011
5012 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5013 if (err)
5014 return err;
5015
5016 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5017 if (!msg)
5018 return -ENOMEM;
5019
5020 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5021 dev, dst, mpp, &pinfo) < 0) {
5022 nlmsg_free(msg);
5023 return -ENOBUFS;
5024 }
5025
5026 return genlmsg_reply(msg, info);
5027}
5028
5029static int nl80211_dump_mpp(struct sk_buff *skb,
5030 struct netlink_callback *cb)
5031{
5032 struct mpath_info pinfo;
5033 struct cfg80211_registered_device *rdev;
5034 struct wireless_dev *wdev;
5035 u8 dst[ETH_ALEN];
5036 u8 mpp[ETH_ALEN];
5037 int path_idx = cb->args[2];
5038 int err;
5039
5040 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5041 if (err)
5042 return err;
5043
5044 if (!rdev->ops->dump_mpp) {
5045 err = -EOPNOTSUPP;
5046 goto out_err;
5047 }
5048
5049 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5050 err = -EOPNOTSUPP;
5051 goto out_err;
5052 }
5053
5054 while (1) {
5055 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5056 mpp, &pinfo);
5057 if (err == -ENOENT)
5058 break;
5059 if (err)
5060 goto out_err;
5061
5062 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5063 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5064 wdev->netdev, dst, mpp,
5065 &pinfo) < 0)
5066 goto out;
5067
5068 path_idx++;
5069 }
5070
5071 out:
5072 cb->args[2] = path_idx;
5073 err = skb->len;
5074 out_err:
5075 nl80211_finish_wdev_dump(rdev);
5076 return err;
5077}
5078
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005079static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5080{
Johannes Berg4c476992010-10-04 21:36:35 +02005081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5082 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005083 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005084 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005085 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005086
5087 memset(&params, 0, sizeof(params));
5088 /* default to not changing parameters */
5089 params.use_cts_prot = -1;
5090 params.use_short_preamble = -1;
5091 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005092 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005093 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005094 params.p2p_ctwindow = -1;
5095 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005096
5097 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5098 params.use_cts_prot =
5099 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5100 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5101 params.use_short_preamble =
5102 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5103 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5104 params.use_short_slot_time =
5105 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005106 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5107 params.basic_rates =
5108 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5109 params.basic_rates_len =
5110 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5111 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005112 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5113 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005114 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5115 params.ht_opmode =
5116 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005117
Johannes Berg53cabad2012-11-14 15:17:28 +01005118 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5119 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5120 return -EINVAL;
5121 params.p2p_ctwindow =
5122 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5123 if (params.p2p_ctwindow < 0)
5124 return -EINVAL;
5125 if (params.p2p_ctwindow != 0 &&
5126 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5127 return -EINVAL;
5128 }
5129
5130 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5131 u8 tmp;
5132
5133 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5134 return -EINVAL;
5135 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5136 if (tmp > 1)
5137 return -EINVAL;
5138 params.p2p_opp_ps = tmp;
5139 if (params.p2p_opp_ps &&
5140 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5141 return -EINVAL;
5142 }
5143
Johannes Berg4c476992010-10-04 21:36:35 +02005144 if (!rdev->ops->change_bss)
5145 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005146
Johannes Berg074ac8d2010-09-16 14:58:22 +02005147 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005148 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5149 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005150
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005151 wdev_lock(wdev);
5152 err = rdev_change_bss(rdev, dev, &params);
5153 wdev_unlock(wdev);
5154
5155 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005156}
5157
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005158static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5159{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005160 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005161 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005162 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005163 u32 owner_nlportid;
5164
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005165 /*
5166 * You should only get this when cfg80211 hasn't yet initialized
5167 * completely when built-in to the kernel right between the time
5168 * window between nl80211_init() and regulatory_init(), if that is
5169 * even possible.
5170 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005171 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005172 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005173
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005174 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5175 user_reg_hint_type =
5176 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5177 else
5178 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5179
5180 switch (user_reg_hint_type) {
5181 case NL80211_USER_REG_HINT_USER:
5182 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005183 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5184 return -EINVAL;
5185
5186 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5187 return regulatory_hint_user(data, user_reg_hint_type);
5188 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005189 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5190 owner_nlportid = info->snd_portid;
5191 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5192 } else {
5193 owner_nlportid = 0;
5194 is_indoor = true;
5195 }
5196
5197 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005198 default:
5199 return -EINVAL;
5200 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005201}
5202
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005203static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005204 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005205{
Johannes Berg4c476992010-10-04 21:36:35 +02005206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005207 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005208 struct wireless_dev *wdev = dev->ieee80211_ptr;
5209 struct mesh_config cur_params;
5210 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005211 void *hdr;
5212 struct nlattr *pinfoattr;
5213 struct sk_buff *msg;
5214
Johannes Berg29cbe682010-12-03 09:20:44 +01005215 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5216 return -EOPNOTSUPP;
5217
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005218 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005219 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005220
Johannes Berg29cbe682010-12-03 09:20:44 +01005221 wdev_lock(wdev);
5222 /* If not connected, get default parameters */
5223 if (!wdev->mesh_id_len)
5224 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5225 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005226 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005227 wdev_unlock(wdev);
5228
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005229 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005230 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005231
5232 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005233 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005234 if (!msg)
5235 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005236 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005237 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005238 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005239 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005240 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005241 if (!pinfoattr)
5242 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005243 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5244 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5245 cur_params.dot11MeshRetryTimeout) ||
5246 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5247 cur_params.dot11MeshConfirmTimeout) ||
5248 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5249 cur_params.dot11MeshHoldingTimeout) ||
5250 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5251 cur_params.dot11MeshMaxPeerLinks) ||
5252 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5253 cur_params.dot11MeshMaxRetries) ||
5254 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5255 cur_params.dot11MeshTTL) ||
5256 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5257 cur_params.element_ttl) ||
5258 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5259 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005260 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5261 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005262 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5263 cur_params.dot11MeshHWMPmaxPREQretries) ||
5264 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5265 cur_params.path_refresh_time) ||
5266 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5267 cur_params.min_discovery_timeout) ||
5268 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5269 cur_params.dot11MeshHWMPactivePathTimeout) ||
5270 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5271 cur_params.dot11MeshHWMPpreqMinInterval) ||
5272 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5273 cur_params.dot11MeshHWMPperrMinInterval) ||
5274 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5275 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5276 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5277 cur_params.dot11MeshHWMPRootMode) ||
5278 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5279 cur_params.dot11MeshHWMPRannInterval) ||
5280 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5281 cur_params.dot11MeshGateAnnouncementProtocol) ||
5282 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5283 cur_params.dot11MeshForwarding) ||
5284 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005285 cur_params.rssi_threshold) ||
5286 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005287 cur_params.ht_opmode) ||
5288 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5289 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5290 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005291 cur_params.dot11MeshHWMProotInterval) ||
5292 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005293 cur_params.dot11MeshHWMPconfirmationInterval) ||
5294 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5295 cur_params.power_mode) ||
5296 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005297 cur_params.dot11MeshAwakeWindowDuration) ||
5298 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5299 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005300 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005301 nla_nest_end(msg, pinfoattr);
5302 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005303 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005304
Johannes Berg3b858752009-03-12 09:55:09 +01005305 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005306 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005307 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005308 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005309 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005310}
5311
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005312static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005313 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5314 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5315 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5316 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5317 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5318 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005319 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005320 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005321 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005322 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5323 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5324 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5325 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5326 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005327 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005328 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005329 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005330 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005331 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005332 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005333 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5334 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005335 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5336 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005337 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005338 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5339 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005340 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005341};
5342
Javier Cardonac80d5452010-12-16 17:37:49 -08005343static const struct nla_policy
5344 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005345 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005346 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5347 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005348 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005349 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005350 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005351 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005352 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005353 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005354};
5355
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005356static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5357{
5358 u8 val = nla_get_u8(nla);
5359 if (val < min || val > max)
5360 return -EINVAL;
5361 *out = val;
5362 return 0;
5363}
5364
5365static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5366{
5367 u8 val = nla_get_u8(nla);
5368 if (val < min || val > max)
5369 return -EINVAL;
5370 *out = val;
5371 return 0;
5372}
5373
5374static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5375{
5376 u16 val = nla_get_u16(nla);
5377 if (val < min || val > max)
5378 return -EINVAL;
5379 *out = val;
5380 return 0;
5381}
5382
5383static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5384{
5385 u32 val = nla_get_u32(nla);
5386 if (val < min || val > max)
5387 return -EINVAL;
5388 *out = val;
5389 return 0;
5390}
5391
5392static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5393{
5394 s32 val = nla_get_s32(nla);
5395 if (val < min || val > max)
5396 return -EINVAL;
5397 *out = val;
5398 return 0;
5399}
5400
Johannes Bergff9a71a2016-08-11 14:59:53 +02005401static int nl80211_check_power_mode(const struct nlattr *nla,
5402 enum nl80211_mesh_power_mode min,
5403 enum nl80211_mesh_power_mode max,
5404 enum nl80211_mesh_power_mode *out)
5405{
5406 u32 val = nla_get_u32(nla);
5407 if (val < min || val > max)
5408 return -EINVAL;
5409 *out = val;
5410 return 0;
5411}
5412
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005413static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005414 struct mesh_config *cfg,
5415 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005416{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005417 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005418 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005419 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005420
Marco Porschea54fba2013-01-07 16:04:48 +01005421#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5422do { \
5423 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005424 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005425 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005426 mask |= (1 << (attr - 1)); \
5427 } \
5428} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005429
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005430 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005431 return -EINVAL;
5432 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005433 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005434 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005435 return -EINVAL;
5436
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005437 /* This makes sure that there aren't more than 32 mesh config
5438 * parameters (otherwise our bitfield scheme would not work.) */
5439 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5440
5441 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005442 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005443 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005444 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005445 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005446 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005447 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005448 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005449 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005450 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005451 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005452 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005453 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005454 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005455 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005456 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005457 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005458 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005459 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005460 mask, NL80211_MESHCONF_ELEMENT_TTL,
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, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005463 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005464 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005465 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5466 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005467 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005468 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005469 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005470 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005471 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005472 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005473 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005474 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005475 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005476 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005477 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005478 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5479 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005480 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005481 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005482 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005483 1, 65535, mask,
5484 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005485 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005486 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005487 1, 65535, mask,
5488 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005489 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005490 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005491 dot11MeshHWMPnetDiameterTraversalTime,
5492 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005493 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005494 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005495 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5496 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005497 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005498 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5499 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005500 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005501 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005502 dot11MeshGateAnnouncementProtocol, 0, 1,
5503 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005504 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005505 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005506 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005507 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005508 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005509 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005510 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005511 /*
5512 * Check HT operation mode based on
5513 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5514 */
5515 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5516 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5517
5518 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5519 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5520 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5521 return -EINVAL;
5522
5523 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5524 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5525 return -EINVAL;
5526
5527 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5528 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5529 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5530 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5531 return -EINVAL;
5532 break;
5533 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5534 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5535 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5536 return -EINVAL;
5537 break;
5538 }
5539 cfg->ht_opmode = ht_opmode;
5540 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005541 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005542 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005543 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005544 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005545 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005546 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005547 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005548 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005549 dot11MeshHWMPconfirmationInterval,
5550 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005551 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005552 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005553 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5554 NL80211_MESH_POWER_ACTIVE,
5555 NL80211_MESH_POWER_MAX,
5556 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005557 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005558 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5559 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005560 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005561 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005562 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005563 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005564 if (mask_out)
5565 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005566
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005567 return 0;
5568
5569#undef FILL_IN_MESH_PARAM_IF_SET
5570}
5571
Javier Cardonac80d5452010-12-16 17:37:49 -08005572static int nl80211_parse_mesh_setup(struct genl_info *info,
5573 struct mesh_setup *setup)
5574{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005576 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5577
5578 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5579 return -EINVAL;
5580 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5581 info->attrs[NL80211_ATTR_MESH_SETUP],
5582 nl80211_mesh_setup_params_policy))
5583 return -EINVAL;
5584
Javier Cardonad299a1f2012-03-31 11:31:33 -07005585 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5586 setup->sync_method =
5587 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5588 IEEE80211_SYNC_METHOD_VENDOR :
5589 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5590
Javier Cardonac80d5452010-12-16 17:37:49 -08005591 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5592 setup->path_sel_proto =
5593 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5594 IEEE80211_PATH_PROTOCOL_VENDOR :
5595 IEEE80211_PATH_PROTOCOL_HWMP;
5596
5597 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5598 setup->path_metric =
5599 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5600 IEEE80211_PATH_METRIC_VENDOR :
5601 IEEE80211_PATH_METRIC_AIRTIME;
5602
Javier Cardona581a8b02011-04-07 15:08:27 -07005603 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005604 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005605 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005606 if (!is_valid_ie_attr(ieattr))
5607 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005608 setup->ie = nla_data(ieattr);
5609 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005610 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005611 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5612 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5613 return -EINVAL;
5614 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005615 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5616 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005617 if (setup->is_secure)
5618 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005619
Colleen Twitty6e16d902013-05-08 11:45:59 -07005620 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5621 if (!setup->user_mpm)
5622 return -EINVAL;
5623 setup->auth_id =
5624 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5625 }
5626
Javier Cardonac80d5452010-12-16 17:37:49 -08005627 return 0;
5628}
5629
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005630static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005631 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005632{
5633 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5634 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005635 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005636 struct mesh_config cfg;
5637 u32 mask;
5638 int err;
5639
Johannes Berg29cbe682010-12-03 09:20:44 +01005640 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5641 return -EOPNOTSUPP;
5642
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005643 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005644 return -EOPNOTSUPP;
5645
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005646 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005647 if (err)
5648 return err;
5649
Johannes Berg29cbe682010-12-03 09:20:44 +01005650 wdev_lock(wdev);
5651 if (!wdev->mesh_id_len)
5652 err = -ENOLINK;
5653
5654 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005655 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005656
5657 wdev_unlock(wdev);
5658
5659 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005660}
5661
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005662static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5663 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005664{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005665 struct nlattr *nl_reg_rules;
5666 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005667
Johannes Berg458f4f92012-12-06 15:47:38 +01005668 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5669 (regdom->dfs_region &&
5670 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005671 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005672
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005673 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5674 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005675 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005676
Johannes Berg458f4f92012-12-06 15:47:38 +01005677 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005678 struct nlattr *nl_reg_rule;
5679 const struct ieee80211_reg_rule *reg_rule;
5680 const struct ieee80211_freq_range *freq_range;
5681 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005682 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005683
Johannes Berg458f4f92012-12-06 15:47:38 +01005684 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005685 freq_range = &reg_rule->freq_range;
5686 power_rule = &reg_rule->power_rule;
5687
5688 nl_reg_rule = nla_nest_start(msg, i);
5689 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005690 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005691
Janusz Dziedzic97524822014-01-30 09:52:20 +01005692 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5693 if (!max_bandwidth_khz)
5694 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5695 reg_rule);
5696
David S. Miller9360ffd2012-03-29 04:41:26 -04005697 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5698 reg_rule->flags) ||
5699 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5700 freq_range->start_freq_khz) ||
5701 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5702 freq_range->end_freq_khz) ||
5703 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005704 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005705 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5706 power_rule->max_antenna_gain) ||
5707 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005708 power_rule->max_eirp) ||
5709 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5710 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005711 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005712
5713 nla_nest_end(msg, nl_reg_rule);
5714 }
5715
5716 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005717 return 0;
5718
5719nla_put_failure:
5720 return -EMSGSIZE;
5721}
5722
5723static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5724{
5725 const struct ieee80211_regdomain *regdom = NULL;
5726 struct cfg80211_registered_device *rdev;
5727 struct wiphy *wiphy = NULL;
5728 struct sk_buff *msg;
5729 void *hdr;
5730
5731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5732 if (!msg)
5733 return -ENOBUFS;
5734
5735 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5736 NL80211_CMD_GET_REG);
5737 if (!hdr)
5738 goto put_failure;
5739
5740 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005741 bool self_managed;
5742
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005743 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5744 if (IS_ERR(rdev)) {
5745 nlmsg_free(msg);
5746 return PTR_ERR(rdev);
5747 }
5748
5749 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005750 self_managed = wiphy->regulatory_flags &
5751 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005752 regdom = get_wiphy_regdom(wiphy);
5753
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005754 /* a self-managed-reg device must have a private regdom */
5755 if (WARN_ON(!regdom && self_managed)) {
5756 nlmsg_free(msg);
5757 return -EINVAL;
5758 }
5759
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005760 if (regdom &&
5761 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5762 goto nla_put_failure;
5763 }
5764
5765 if (!wiphy && reg_last_request_cell_base() &&
5766 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5767 NL80211_USER_REG_HINT_CELL_BASE))
5768 goto nla_put_failure;
5769
5770 rcu_read_lock();
5771
5772 if (!regdom)
5773 regdom = rcu_dereference(cfg80211_regdomain);
5774
5775 if (nl80211_put_regdom(regdom, msg))
5776 goto nla_put_failure_rcu;
5777
5778 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005779
5780 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005781 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005782
Johannes Berg458f4f92012-12-06 15:47:38 +01005783nla_put_failure_rcu:
5784 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005785nla_put_failure:
5786 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005787put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005788 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005789 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005790}
5791
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005792static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5793 u32 seq, int flags, struct wiphy *wiphy,
5794 const struct ieee80211_regdomain *regdom)
5795{
5796 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5797 NL80211_CMD_GET_REG);
5798
5799 if (!hdr)
5800 return -1;
5801
5802 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5803
5804 if (nl80211_put_regdom(regdom, msg))
5805 goto nla_put_failure;
5806
5807 if (!wiphy && reg_last_request_cell_base() &&
5808 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5809 NL80211_USER_REG_HINT_CELL_BASE))
5810 goto nla_put_failure;
5811
5812 if (wiphy &&
5813 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5814 goto nla_put_failure;
5815
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005816 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5817 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5818 goto nla_put_failure;
5819
Johannes Berg053c0952015-01-16 22:09:00 +01005820 genlmsg_end(msg, hdr);
5821 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005822
5823nla_put_failure:
5824 genlmsg_cancel(msg, hdr);
5825 return -EMSGSIZE;
5826}
5827
5828static int nl80211_get_reg_dump(struct sk_buff *skb,
5829 struct netlink_callback *cb)
5830{
5831 const struct ieee80211_regdomain *regdom = NULL;
5832 struct cfg80211_registered_device *rdev;
5833 int err, reg_idx, start = cb->args[2];
5834
5835 rtnl_lock();
5836
5837 if (cfg80211_regdomain && start == 0) {
5838 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5839 NLM_F_MULTI, NULL,
5840 rtnl_dereference(cfg80211_regdomain));
5841 if (err < 0)
5842 goto out_err;
5843 }
5844
5845 /* the global regdom is idx 0 */
5846 reg_idx = 1;
5847 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5848 regdom = get_wiphy_regdom(&rdev->wiphy);
5849 if (!regdom)
5850 continue;
5851
5852 if (++reg_idx <= start)
5853 continue;
5854
5855 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5856 NLM_F_MULTI, &rdev->wiphy, regdom);
5857 if (err < 0) {
5858 reg_idx--;
5859 break;
5860 }
5861 }
5862
5863 cb->args[2] = reg_idx;
5864 err = skb->len;
5865out_err:
5866 rtnl_unlock();
5867 return err;
5868}
5869
Johannes Bergb6863032015-10-15 09:25:18 +02005870#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5871static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5872 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5873 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5874 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5875 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5876 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5877 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5878 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5879};
5880
5881static int parse_reg_rule(struct nlattr *tb[],
5882 struct ieee80211_reg_rule *reg_rule)
5883{
5884 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5885 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5886
5887 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5888 return -EINVAL;
5889 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5890 return -EINVAL;
5891 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5892 return -EINVAL;
5893 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5894 return -EINVAL;
5895 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5896 return -EINVAL;
5897
5898 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5899
5900 freq_range->start_freq_khz =
5901 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5902 freq_range->end_freq_khz =
5903 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5904 freq_range->max_bandwidth_khz =
5905 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5906
5907 power_rule->max_eirp =
5908 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5909
5910 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5911 power_rule->max_antenna_gain =
5912 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5913
5914 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5915 reg_rule->dfs_cac_ms =
5916 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5917
5918 return 0;
5919}
5920
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005921static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5922{
5923 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5924 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005925 char *alpha2;
5926 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005927 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005928 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005929 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005930
5931 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5932 return -EINVAL;
5933
5934 if (!info->attrs[NL80211_ATTR_REG_RULES])
5935 return -EINVAL;
5936
5937 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5938
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005939 if (info->attrs[NL80211_ATTR_DFS_REGION])
5940 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5941
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005942 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005943 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005944 num_rules++;
5945 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005946 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005947 }
5948
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005949 if (!reg_is_valid_request(alpha2))
5950 return -EINVAL;
5951
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005952 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005953 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005954
5955 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005956 if (!rd)
5957 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005958
5959 rd->n_reg_rules = num_rules;
5960 rd->alpha2[0] = alpha2[0];
5961 rd->alpha2[1] = alpha2[1];
5962
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005963 /*
5964 * Disable DFS master mode if the DFS region was
5965 * not supported or known on this kernel.
5966 */
5967 if (reg_supported_dfs_region(dfs_region))
5968 rd->dfs_region = dfs_region;
5969
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005970 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005971 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005972 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5973 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5974 reg_rule_policy);
5975 if (r)
5976 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005977 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5978 if (r)
5979 goto bad_reg;
5980
5981 rule_idx++;
5982
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005983 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5984 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005985 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005986 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005987 }
5988
Johannes Berg06627992016-06-09 10:40:09 +02005989 /* set_regdom takes ownership of rd */
5990 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02005991 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005992 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005993 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005994}
Johannes Bergb6863032015-10-15 09:25:18 +02005995#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005996
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005997static int validate_scan_freqs(struct nlattr *freqs)
5998{
5999 struct nlattr *attr1, *attr2;
6000 int n_channels = 0, tmp1, tmp2;
6001
6002 nla_for_each_nested(attr1, freqs, tmp1) {
6003 n_channels++;
6004 /*
6005 * Some hardware has a limited channel list for
6006 * scanning, and it is pretty much nonsensical
6007 * to scan for a channel twice, so disallow that
6008 * and don't require drivers to check that the
6009 * channel list they get isn't longer than what
6010 * they can scan, as long as they can scan all
6011 * the channels they registered at once.
6012 */
6013 nla_for_each_nested(attr2, freqs, tmp2)
6014 if (attr1 != attr2 &&
6015 nla_get_u32(attr1) == nla_get_u32(attr2))
6016 return 0;
6017 }
6018
6019 return n_channels;
6020}
6021
Johannes Berg57fbcce2016-04-12 15:56:15 +02006022static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006023{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006024 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006025}
6026
6027static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6028 struct cfg80211_bss_selection *bss_select)
6029{
6030 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6031 struct nlattr *nest;
6032 int err;
6033 bool found = false;
6034 int i;
6035
6036 /* only process one nested attribute */
6037 nest = nla_data(nla);
6038 if (!nla_ok(nest, nla_len(nest)))
6039 return -EINVAL;
6040
6041 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
6042 nla_len(nest), nl80211_bss_select_policy);
6043 if (err)
6044 return err;
6045
6046 /* only one attribute may be given */
6047 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6048 if (attr[i]) {
6049 if (found)
6050 return -EINVAL;
6051 found = true;
6052 }
6053 }
6054
6055 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6056
6057 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6058 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6059
6060 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6061 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6062 bss_select->param.band_pref =
6063 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6064 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6065 return -EINVAL;
6066 }
6067
6068 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6069 struct nl80211_bss_select_rssi_adjust *adj_param;
6070
6071 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6072 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6073 bss_select->param.adjust.band = adj_param->band;
6074 bss_select->param.adjust.delta = adj_param->delta;
6075 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6076 return -EINVAL;
6077 }
6078
6079 /* user-space did not provide behaviour attribute */
6080 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6081 return -EINVAL;
6082
6083 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6084 return -EINVAL;
6085
6086 return 0;
6087}
6088
Johannes Bergad2b26a2014-06-12 21:39:05 +02006089static int nl80211_parse_random_mac(struct nlattr **attrs,
6090 u8 *mac_addr, u8 *mac_addr_mask)
6091{
6092 int i;
6093
6094 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006095 eth_zero_addr(mac_addr);
6096 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006097 mac_addr[0] = 0x2;
6098 mac_addr_mask[0] = 0x3;
6099
6100 return 0;
6101 }
6102
6103 /* need both or none */
6104 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6105 return -EINVAL;
6106
6107 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6108 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6109
6110 /* don't allow or configure an mcast address */
6111 if (!is_multicast_ether_addr(mac_addr_mask) ||
6112 is_multicast_ether_addr(mac_addr))
6113 return -EINVAL;
6114
6115 /*
6116 * allow users to pass a MAC address that has bits set outside
6117 * of the mask, but don't bother drivers with having to deal
6118 * with such bits
6119 */
6120 for (i = 0; i < ETH_ALEN; i++)
6121 mac_addr[i] &= mac_addr_mask[i];
6122
6123 return 0;
6124}
6125
Johannes Berg2a519312009-02-10 21:25:55 +01006126static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6127{
Johannes Berg4c476992010-10-04 21:36:35 +02006128 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006129 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006130 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006131 struct nlattr *attr;
6132 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006133 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006134 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006135
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006136 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6137 return -EINVAL;
6138
Johannes Berg79c97e92009-07-07 03:56:12 +02006139 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006140
Johannes Berg4c476992010-10-04 21:36:35 +02006141 if (!rdev->ops->scan)
6142 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006143
Johannes Bergf9d15d12014-01-22 11:14:19 +02006144 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006145 err = -EBUSY;
6146 goto unlock;
6147 }
Johannes Berg2a519312009-02-10 21:25:55 +01006148
6149 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006150 n_channels = validate_scan_freqs(
6151 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006152 if (!n_channels) {
6153 err = -EINVAL;
6154 goto unlock;
6155 }
Johannes Berg2a519312009-02-10 21:25:55 +01006156 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006157 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006158 }
6159
6160 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6161 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6162 n_ssids++;
6163
Johannes Bergf9f47522013-03-19 15:04:07 +01006164 if (n_ssids > wiphy->max_scan_ssids) {
6165 err = -EINVAL;
6166 goto unlock;
6167 }
Johannes Berg2a519312009-02-10 21:25:55 +01006168
Jouni Malinen70692ad2009-02-16 19:39:13 +02006169 if (info->attrs[NL80211_ATTR_IE])
6170 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6171 else
6172 ie_len = 0;
6173
Johannes Bergf9f47522013-03-19 15:04:07 +01006174 if (ie_len > wiphy->max_scan_ie_len) {
6175 err = -EINVAL;
6176 goto unlock;
6177 }
Johannes Berg18a83652009-03-31 12:12:05 +02006178
Johannes Berg2a519312009-02-10 21:25:55 +01006179 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006180 + sizeof(*request->ssids) * n_ssids
6181 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006182 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006183 if (!request) {
6184 err = -ENOMEM;
6185 goto unlock;
6186 }
Johannes Berg2a519312009-02-10 21:25:55 +01006187
Johannes Berg2a519312009-02-10 21:25:55 +01006188 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006189 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006190 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006191 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006192 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006193 request->ie = (void *)(request->ssids + n_ssids);
6194 else
6195 request->ie = (void *)(request->channels + n_channels);
6196 }
Johannes Berg2a519312009-02-10 21:25:55 +01006197
Johannes Berg584991d2009-11-02 13:32:03 +01006198 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006199 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6200 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006201 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006202 struct ieee80211_channel *chan;
6203
6204 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6205
6206 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006207 err = -EINVAL;
6208 goto out_free;
6209 }
Johannes Berg584991d2009-11-02 13:32:03 +01006210
6211 /* ignore disabled channels */
6212 if (chan->flags & IEEE80211_CHAN_DISABLED)
6213 continue;
6214
6215 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006216 i++;
6217 }
6218 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006219 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006220
Johannes Berg2a519312009-02-10 21:25:55 +01006221 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006222 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006223 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006224
Johannes Berg2a519312009-02-10 21:25:55 +01006225 if (!wiphy->bands[band])
6226 continue;
6227 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006228 struct ieee80211_channel *chan;
6229
6230 chan = &wiphy->bands[band]->channels[j];
6231
6232 if (chan->flags & IEEE80211_CHAN_DISABLED)
6233 continue;
6234
6235 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006236 i++;
6237 }
6238 }
6239 }
6240
Johannes Berg584991d2009-11-02 13:32:03 +01006241 if (!i) {
6242 err = -EINVAL;
6243 goto out_free;
6244 }
6245
6246 request->n_channels = i;
6247
Johannes Berg2a519312009-02-10 21:25:55 +01006248 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006249 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006250 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006251 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006252 err = -EINVAL;
6253 goto out_free;
6254 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006255 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006256 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006257 i++;
6258 }
6259 }
6260
Jouni Malinen70692ad2009-02-16 19:39:13 +02006261 if (info->attrs[NL80211_ATTR_IE]) {
6262 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006263 memcpy((void *)request->ie,
6264 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006265 request->ie_len);
6266 }
6267
Johannes Berg57fbcce2016-04-12 15:56:15 +02006268 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006269 if (wiphy->bands[i])
6270 request->rates[i] =
6271 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006272
6273 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6274 nla_for_each_nested(attr,
6275 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6276 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006277 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006278
Johannes Berg57fbcce2016-04-12 15:56:15 +02006279 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006280 err = -EINVAL;
6281 goto out_free;
6282 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006283
6284 if (!wiphy->bands[band])
6285 continue;
6286
Johannes Berg34850ab2011-07-18 18:08:35 +02006287 err = ieee80211_get_ratemask(wiphy->bands[band],
6288 nla_data(attr),
6289 nla_len(attr),
6290 &request->rates[band]);
6291 if (err)
6292 goto out_free;
6293 }
6294 }
6295
Avraham Stern1d762502016-07-05 17:10:13 +03006296 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6297 if (!wiphy_ext_feature_isset(wiphy,
6298 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6299 err = -EOPNOTSUPP;
6300 goto out_free;
6301 }
6302
6303 request->duration =
6304 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6305 request->duration_mandatory =
6306 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6307 }
6308
Sam Leffler46856bb2012-10-11 21:03:32 -07006309 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006310 request->flags = nla_get_u32(
6311 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006312 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6313 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006314 err = -EOPNOTSUPP;
6315 goto out_free;
6316 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006317
6318 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6319 if (!(wiphy->features &
6320 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6321 err = -EOPNOTSUPP;
6322 goto out_free;
6323 }
6324
6325 if (wdev->current_bss) {
6326 err = -EOPNOTSUPP;
6327 goto out_free;
6328 }
6329
6330 err = nl80211_parse_random_mac(info->attrs,
6331 request->mac_addr,
6332 request->mac_addr_mask);
6333 if (err)
6334 goto out_free;
6335 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006336 }
Sam Lefflered4737712012-10-11 21:03:31 -07006337
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306338 request->no_cck =
6339 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6340
Jouni Malinen818965d2016-02-26 22:12:47 +02006341 if (info->attrs[NL80211_ATTR_MAC])
6342 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6343 ETH_ALEN);
6344 else
6345 eth_broadcast_addr(request->bssid);
6346
Johannes Bergfd014282012-06-18 19:17:03 +02006347 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006348 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006349 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006350
Johannes Berg79c97e92009-07-07 03:56:12 +02006351 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006352 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006353
Johannes Berg463d0182009-07-14 00:33:35 +02006354 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006355 nl80211_send_scan_start(rdev, wdev);
6356 if (wdev->netdev)
6357 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006358 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006359 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006360 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006361 kfree(request);
6362 }
Johannes Berg3b858752009-03-12 09:55:09 +01006363
Johannes Bergf9f47522013-03-19 15:04:07 +01006364 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006365 return err;
6366}
6367
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306368static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6369{
6370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6371 struct wireless_dev *wdev = info->user_ptr[1];
6372
6373 if (!rdev->ops->abort_scan)
6374 return -EOPNOTSUPP;
6375
6376 if (rdev->scan_msg)
6377 return 0;
6378
6379 if (!rdev->scan_req)
6380 return -ENOENT;
6381
6382 rdev_abort_scan(rdev, wdev);
6383 return 0;
6384}
6385
Avraham Stern3b06d272015-10-12 09:51:34 +03006386static int
6387nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6388 struct cfg80211_sched_scan_request *request,
6389 struct nlattr **attrs)
6390{
6391 int tmp, err, i = 0;
6392 struct nlattr *attr;
6393
6394 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6395 u32 interval;
6396
6397 /*
6398 * If scan plans are not specified,
6399 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6400 * case one scan plan will be set with the specified scan
6401 * interval and infinite number of iterations.
6402 */
6403 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6404 return -EINVAL;
6405
6406 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6407 if (!interval)
6408 return -EINVAL;
6409
6410 request->scan_plans[0].interval =
6411 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6412 if (!request->scan_plans[0].interval)
6413 return -EINVAL;
6414
6415 if (request->scan_plans[0].interval >
6416 wiphy->max_sched_scan_plan_interval)
6417 request->scan_plans[0].interval =
6418 wiphy->max_sched_scan_plan_interval;
6419
6420 return 0;
6421 }
6422
6423 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6424 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6425
6426 if (WARN_ON(i >= n_plans))
6427 return -EINVAL;
6428
6429 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6430 nla_data(attr), nla_len(attr),
6431 nl80211_plan_policy);
6432 if (err)
6433 return err;
6434
6435 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6436 return -EINVAL;
6437
6438 request->scan_plans[i].interval =
6439 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6440 if (!request->scan_plans[i].interval ||
6441 request->scan_plans[i].interval >
6442 wiphy->max_sched_scan_plan_interval)
6443 return -EINVAL;
6444
6445 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6446 request->scan_plans[i].iterations =
6447 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6448 if (!request->scan_plans[i].iterations ||
6449 (request->scan_plans[i].iterations >
6450 wiphy->max_sched_scan_plan_iterations))
6451 return -EINVAL;
6452 } else if (i < n_plans - 1) {
6453 /*
6454 * All scan plans but the last one must specify
6455 * a finite number of iterations
6456 */
6457 return -EINVAL;
6458 }
6459
6460 i++;
6461 }
6462
6463 /*
6464 * The last scan plan must not specify the number of
6465 * iterations, it is supposed to run infinitely
6466 */
6467 if (request->scan_plans[n_plans - 1].iterations)
6468 return -EINVAL;
6469
6470 return 0;
6471}
6472
Luciano Coelho256da022014-11-10 16:13:46 +02006473static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006474nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006475 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006476{
6477 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006478 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006479 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006480 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006481 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006482 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006483 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006484
Luciano Coelho256da022014-11-10 16:13:46 +02006485 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6486 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006487
Luciano Coelho256da022014-11-10 16:13:46 +02006488 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006489 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006490 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006491 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006492 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006493 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006494 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006495 }
6496
Luciano Coelho256da022014-11-10 16:13:46 +02006497 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6498 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006499 tmp)
6500 n_ssids++;
6501
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006502 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006503 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006504
Johannes Bergea73cbc2014-01-24 10:53:53 +01006505 /*
6506 * First, count the number of 'real' matchsets. Due to an issue with
6507 * the old implementation, matchsets containing only the RSSI attribute
6508 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6509 * RSSI for all matchsets, rather than their own matchset for reporting
6510 * all APs with a strong RSSI. This is needed to be compatible with
6511 * older userspace that treated a matchset with only the RSSI as the
6512 * global RSSI for all other matchsets - if there are other matchsets.
6513 */
Luciano Coelho256da022014-11-10 16:13:46 +02006514 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006515 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006516 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006517 tmp) {
6518 struct nlattr *rssi;
6519
6520 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6521 nla_data(attr), nla_len(attr),
6522 nl80211_match_policy);
6523 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006524 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006525 /* add other standalone attributes here */
6526 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6527 n_match_sets++;
6528 continue;
6529 }
6530 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6531 if (rssi)
6532 default_match_rssi = nla_get_s32(rssi);
6533 }
6534 }
6535
6536 /* However, if there's no other matchset, add the RSSI one */
6537 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6538 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006539
6540 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006541 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006542
Luciano Coelho256da022014-11-10 16:13:46 +02006543 if (attrs[NL80211_ATTR_IE])
6544 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006545 else
6546 ie_len = 0;
6547
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006548 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006549 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006550
Avraham Stern3b06d272015-10-12 09:51:34 +03006551 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6552 /*
6553 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6554 * each scan plan already specifies its own interval
6555 */
6556 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6557 return ERR_PTR(-EINVAL);
6558
6559 nla_for_each_nested(attr,
6560 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6561 n_plans++;
6562 } else {
6563 /*
6564 * The scan interval attribute is kept for backward
6565 * compatibility. If no scan plans are specified and sched scan
6566 * interval is specified, one scan plan will be set with this
6567 * scan interval and infinite number of iterations.
6568 */
6569 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6570 return ERR_PTR(-EINVAL);
6571
6572 n_plans = 1;
6573 }
6574
6575 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6576 return ERR_PTR(-EINVAL);
6577
Luciano Coelho807f8a82011-05-11 17:09:35 +03006578 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006579 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006580 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006581 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006582 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006583 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006584 if (!request)
6585 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006586
6587 if (n_ssids)
6588 request->ssids = (void *)&request->channels[n_channels];
6589 request->n_ssids = n_ssids;
6590 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006591 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006592 request->ie = (void *)(request->ssids + n_ssids);
6593 else
6594 request->ie = (void *)(request->channels + n_channels);
6595 }
6596
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006597 if (n_match_sets) {
6598 if (request->ie)
6599 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006600 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006601 request->match_sets =
6602 (void *)(request->ssids + n_ssids);
6603 else
6604 request->match_sets =
6605 (void *)(request->channels + n_channels);
6606 }
6607 request->n_match_sets = n_match_sets;
6608
Avraham Stern3b06d272015-10-12 09:51:34 +03006609 if (n_match_sets)
6610 request->scan_plans = (void *)(request->match_sets +
6611 n_match_sets);
6612 else if (request->ie)
6613 request->scan_plans = (void *)(request->ie + ie_len);
6614 else if (n_ssids)
6615 request->scan_plans = (void *)(request->ssids + n_ssids);
6616 else
6617 request->scan_plans = (void *)(request->channels + n_channels);
6618
6619 request->n_scan_plans = n_plans;
6620
Luciano Coelho807f8a82011-05-11 17:09:35 +03006621 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006622 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006623 /* user specified, bail out if channel not found */
6624 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006625 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006626 tmp) {
6627 struct ieee80211_channel *chan;
6628
6629 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6630
6631 if (!chan) {
6632 err = -EINVAL;
6633 goto out_free;
6634 }
6635
6636 /* ignore disabled channels */
6637 if (chan->flags & IEEE80211_CHAN_DISABLED)
6638 continue;
6639
6640 request->channels[i] = chan;
6641 i++;
6642 }
6643 } else {
6644 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006645 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006646 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006647
Luciano Coelho807f8a82011-05-11 17:09:35 +03006648 if (!wiphy->bands[band])
6649 continue;
6650 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6651 struct ieee80211_channel *chan;
6652
6653 chan = &wiphy->bands[band]->channels[j];
6654
6655 if (chan->flags & IEEE80211_CHAN_DISABLED)
6656 continue;
6657
6658 request->channels[i] = chan;
6659 i++;
6660 }
6661 }
6662 }
6663
6664 if (!i) {
6665 err = -EINVAL;
6666 goto out_free;
6667 }
6668
6669 request->n_channels = i;
6670
6671 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006672 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006673 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006674 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006675 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006676 err = -EINVAL;
6677 goto out_free;
6678 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006679 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006680 memcpy(request->ssids[i].ssid, nla_data(attr),
6681 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006682 i++;
6683 }
6684 }
6685
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006686 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006687 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006688 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006689 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006690 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006691 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006692
Johannes Bergae811e22014-01-24 10:17:47 +01006693 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6694 nla_data(attr), nla_len(attr),
6695 nl80211_match_policy);
6696 if (err)
6697 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006698 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006699 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006700 if (WARN_ON(i >= n_match_sets)) {
6701 /* this indicates a programming error,
6702 * the loop above should have verified
6703 * things properly
6704 */
6705 err = -EINVAL;
6706 goto out_free;
6707 }
6708
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006709 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6710 err = -EINVAL;
6711 goto out_free;
6712 }
6713 memcpy(request->match_sets[i].ssid.ssid,
6714 nla_data(ssid), nla_len(ssid));
6715 request->match_sets[i].ssid.ssid_len =
6716 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07006717 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01006718 request->match_sets[i].rssi_thold =
6719 default_match_rssi;
6720 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6721 if (rssi)
6722 request->match_sets[i].rssi_thold =
6723 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006724 }
6725 i++;
6726 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006727
6728 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006729 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006730 request->match_sets[0].rssi_thold = default_match_rssi;
6731
6732 request->min_rssi_thold = INT_MAX;
6733 for (i = 0; i < n_match_sets; i++)
6734 request->min_rssi_thold =
6735 min(request->match_sets[i].rssi_thold,
6736 request->min_rssi_thold);
6737 } else {
6738 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006739 }
6740
Johannes Berg9900e482014-02-04 21:01:25 +01006741 if (ie_len) {
6742 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006743 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006744 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006745 request->ie_len);
6746 }
6747
Luciano Coelho256da022014-11-10 16:13:46 +02006748 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006749 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006750 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006751 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6752 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006753 err = -EOPNOTSUPP;
6754 goto out_free;
6755 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006756
6757 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6758 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6759
6760 if (!wdev) /* must be net-detect */
6761 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6762
6763 if (!(wiphy->features & flg)) {
6764 err = -EOPNOTSUPP;
6765 goto out_free;
6766 }
6767
6768 if (wdev && wdev->current_bss) {
6769 err = -EOPNOTSUPP;
6770 goto out_free;
6771 }
6772
6773 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6774 request->mac_addr_mask);
6775 if (err)
6776 goto out_free;
6777 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006778 }
Sam Lefflered4737712012-10-11 21:03:31 -07006779
Luciano Coelho9c748932015-01-16 16:04:09 +02006780 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6781 request->delay =
6782 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6783
Avraham Stern3b06d272015-10-12 09:51:34 +03006784 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6785 if (err)
6786 goto out_free;
6787
Sam Leffler15d60302012-10-11 21:03:34 -07006788 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006789
Luciano Coelho256da022014-11-10 16:13:46 +02006790 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006791
6792out_free:
6793 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006794 return ERR_PTR(err);
6795}
6796
6797static int nl80211_start_sched_scan(struct sk_buff *skb,
6798 struct genl_info *info)
6799{
6800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6801 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006802 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006803 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006804 int err;
6805
6806 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6807 !rdev->ops->sched_scan_start)
6808 return -EOPNOTSUPP;
6809
6810 if (rdev->sched_scan_req)
6811 return -EINPROGRESS;
6812
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006813 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6814 info->attrs);
6815
6816 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006817 if (err)
6818 goto out_err;
6819
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006820 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006821 if (err)
6822 goto out_free;
6823
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006824 sched_scan_req->dev = dev;
6825 sched_scan_req->wiphy = &rdev->wiphy;
6826
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006827 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6828 sched_scan_req->owner_nlportid = info->snd_portid;
6829
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006830 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006831
6832 nl80211_send_sched_scan(rdev, dev,
6833 NL80211_CMD_START_SCHED_SCAN);
6834 return 0;
6835
6836out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006837 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006838out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006839 return err;
6840}
6841
6842static int nl80211_stop_sched_scan(struct sk_buff *skb,
6843 struct genl_info *info)
6844{
6845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6846
6847 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6848 !rdev->ops->sched_scan_stop)
6849 return -EOPNOTSUPP;
6850
Johannes Berg5fe231e2013-05-08 21:45:15 +02006851 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006852}
6853
Simon Wunderlich04f39042013-02-08 18:16:19 +01006854static int nl80211_start_radar_detection(struct sk_buff *skb,
6855 struct genl_info *info)
6856{
6857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6858 struct net_device *dev = info->user_ptr[1];
6859 struct wireless_dev *wdev = dev->ieee80211_ptr;
6860 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006861 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006862 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006863 int err;
6864
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006865 dfs_region = reg_get_dfs_region(wdev->wiphy);
6866 if (dfs_region == NL80211_DFS_UNSET)
6867 return -EINVAL;
6868
Simon Wunderlich04f39042013-02-08 18:16:19 +01006869 err = nl80211_parse_chandef(rdev, info, &chandef);
6870 if (err)
6871 return err;
6872
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006873 if (netif_carrier_ok(dev))
6874 return -EBUSY;
6875
Simon Wunderlich04f39042013-02-08 18:16:19 +01006876 if (wdev->cac_started)
6877 return -EBUSY;
6878
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006879 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006880 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006881 if (err < 0)
6882 return err;
6883
6884 if (err == 0)
6885 return -EINVAL;
6886
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006887 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006888 return -EINVAL;
6889
6890 if (!rdev->ops->start_radar_detection)
6891 return -EOPNOTSUPP;
6892
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006893 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6894 if (WARN_ON(!cac_time_ms))
6895 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6896
Ilan Peera1056b12015-10-22 22:27:46 +03006897 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006898 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006899 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006900 wdev->cac_started = true;
6901 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006902 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006903 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006904 return err;
6905}
6906
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006907static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6908{
6909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6910 struct net_device *dev = info->user_ptr[1];
6911 struct wireless_dev *wdev = dev->ieee80211_ptr;
6912 struct cfg80211_csa_settings params;
6913 /* csa_attrs is defined static to avoid waste of stack size - this
6914 * function is called under RTNL lock, so this should not be a problem.
6915 */
6916 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006917 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006918 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006919 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006920 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006921
6922 if (!rdev->ops->channel_switch ||
6923 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6924 return -EOPNOTSUPP;
6925
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006926 switch (dev->ieee80211_ptr->iftype) {
6927 case NL80211_IFTYPE_AP:
6928 case NL80211_IFTYPE_P2P_GO:
6929 need_new_beacon = true;
6930
6931 /* useless if AP is not running */
6932 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006933 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006934 break;
6935 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006936 if (!wdev->ssid_len)
6937 return -ENOTCONN;
6938 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006939 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006940 if (!wdev->mesh_id_len)
6941 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006942 break;
6943 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006944 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006945 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006946
6947 memset(&params, 0, sizeof(params));
6948
6949 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6950 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6951 return -EINVAL;
6952
6953 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006954 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006955 return -EINVAL;
6956
Luciano Coelho252e07c2014-10-08 09:48:34 +03006957 /* Even though the attribute is u32, the specification says
6958 * u8, so let's make sure we don't overflow.
6959 */
6960 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6961 if (cs_count > 255)
6962 return -EINVAL;
6963
6964 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006965
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006966 if (!need_new_beacon)
6967 goto skip_beacons;
6968
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006969 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6970 if (err)
6971 return err;
6972
6973 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6974 info->attrs[NL80211_ATTR_CSA_IES],
6975 nl80211_policy);
6976 if (err)
6977 return err;
6978
6979 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6980 if (err)
6981 return err;
6982
6983 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6984 return -EINVAL;
6985
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006986 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6987 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006988 return -EINVAL;
6989
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006990 params.n_counter_offsets_beacon = len / sizeof(u16);
6991 if (rdev->wiphy.max_num_csa_counters &&
6992 (params.n_counter_offsets_beacon >
6993 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006994 return -EINVAL;
6995
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006996 params.counter_offsets_beacon =
6997 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6998
6999 /* sanity checks - counters should fit and be the same */
7000 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7001 u16 offset = params.counter_offsets_beacon[i];
7002
7003 if (offset >= params.beacon_csa.tail_len)
7004 return -EINVAL;
7005
7006 if (params.beacon_csa.tail[offset] != params.count)
7007 return -EINVAL;
7008 }
7009
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007010 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007011 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7012 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007013 return -EINVAL;
7014
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007015 params.n_counter_offsets_presp = len / sizeof(u16);
7016 if (rdev->wiphy.max_num_csa_counters &&
7017 (params.n_counter_offsets_beacon >
7018 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007019 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007020
7021 params.counter_offsets_presp =
7022 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7023
7024 /* sanity checks - counters should fit and be the same */
7025 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7026 u16 offset = params.counter_offsets_presp[i];
7027
7028 if (offset >= params.beacon_csa.probe_resp_len)
7029 return -EINVAL;
7030
7031 if (params.beacon_csa.probe_resp[offset] !=
7032 params.count)
7033 return -EINVAL;
7034 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007035 }
7036
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007037skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007038 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7039 if (err)
7040 return err;
7041
Arik Nemtsov923b3522015-07-08 15:41:44 +03007042 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7043 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007044 return -EINVAL;
7045
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007046 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7047 &params.chandef,
7048 wdev->iftype);
7049 if (err < 0)
7050 return err;
7051
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007052 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007053 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007054
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007055 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7056 params.block_tx = true;
7057
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007058 wdev_lock(wdev);
7059 err = rdev_channel_switch(rdev, dev, &params);
7060 wdev_unlock(wdev);
7061
7062 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007063}
7064
Johannes Berg9720bb32011-06-21 09:45:33 +02007065static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7066 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007067 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007068 struct wireless_dev *wdev,
7069 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007070{
Johannes Berg48ab9052009-07-10 18:42:31 +02007071 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007072 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007073 void *hdr;
7074 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007075
7076 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007077
Eric W. Biederman15e47302012-09-07 20:12:54 +00007078 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007079 NL80211_CMD_NEW_SCAN_RESULTS);
7080 if (!hdr)
7081 return -1;
7082
Johannes Berg9720bb32011-06-21 09:45:33 +02007083 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7084
Johannes Berg97990a02013-04-19 01:02:55 +02007085 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7086 goto nla_put_failure;
7087 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007088 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7089 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007090 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7091 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007092 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007093
7094 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7095 if (!bss)
7096 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007097 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007098 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007099 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007100
7101 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007102 /* indicate whether we have probe response data or not */
7103 if (rcu_access_pointer(res->proberesp_ies) &&
7104 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7105 goto fail_unlock_rcu;
7106
7107 /* this pointer prefers to be pointed to probe response data
7108 * but is always valid
7109 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007110 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007111 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007112 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7113 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007114 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007115 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7116 ies->len, ies->data))
7117 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007118 }
Johannes Berg0e227082014-08-12 20:34:30 +02007119
7120 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007121 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007122 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007123 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7124 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007125 goto fail_unlock_rcu;
7126 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7127 ies->len, ies->data))
7128 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007129 }
7130 rcu_read_unlock();
7131
David S. Miller9360ffd2012-03-29 04:41:26 -04007132 if (res->beacon_interval &&
7133 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7134 goto nla_put_failure;
7135 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7136 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007137 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007138 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7139 jiffies_to_msecs(jiffies - intbss->ts)))
7140 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007141
Avraham Stern1d762502016-07-05 17:10:13 +03007142 if (intbss->parent_tsf &&
7143 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7144 intbss->parent_tsf, NL80211_BSS_PAD) ||
7145 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7146 intbss->parent_bssid)))
7147 goto nla_put_failure;
7148
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007149 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007150 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7151 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007152 goto nla_put_failure;
7153
Johannes Berg77965c92009-02-18 18:45:06 +01007154 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007155 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007156 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7157 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007158 break;
7159 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007160 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7161 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007162 break;
7163 default:
7164 break;
7165 }
7166
Johannes Berg48ab9052009-07-10 18:42:31 +02007167 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007168 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007169 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007170 if (intbss == wdev->current_bss &&
7171 nla_put_u32(msg, NL80211_BSS_STATUS,
7172 NL80211_BSS_STATUS_ASSOCIATED))
7173 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007174 break;
7175 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007176 if (intbss == wdev->current_bss &&
7177 nla_put_u32(msg, NL80211_BSS_STATUS,
7178 NL80211_BSS_STATUS_IBSS_JOINED))
7179 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007180 break;
7181 default:
7182 break;
7183 }
7184
Johannes Berg2a519312009-02-10 21:25:55 +01007185 nla_nest_end(msg, bss);
7186
Johannes Berg053c0952015-01-16 22:09:00 +01007187 genlmsg_end(msg, hdr);
7188 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007189
Johannes Berg8cef2c92013-02-05 16:54:31 +01007190 fail_unlock_rcu:
7191 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007192 nla_put_failure:
7193 genlmsg_cancel(msg, hdr);
7194 return -EMSGSIZE;
7195}
7196
Johannes Berg97990a02013-04-19 01:02:55 +02007197static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007198{
Johannes Berg48ab9052009-07-10 18:42:31 +02007199 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007200 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007201 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007202 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007203 int err;
7204
Johannes Berg97990a02013-04-19 01:02:55 +02007205 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007206 if (err)
7207 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007208
Johannes Berg48ab9052009-07-10 18:42:31 +02007209 wdev_lock(wdev);
7210 spin_lock_bh(&rdev->bss_lock);
7211 cfg80211_bss_expire(rdev);
7212
Johannes Berg9720bb32011-06-21 09:45:33 +02007213 cb->seq = rdev->bss_generation;
7214
Johannes Berg48ab9052009-07-10 18:42:31 +02007215 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007216 if (++idx <= start)
7217 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007218 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007219 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007220 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007221 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007222 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007223 }
7224 }
7225
Johannes Berg48ab9052009-07-10 18:42:31 +02007226 spin_unlock_bh(&rdev->bss_lock);
7227 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007228
Johannes Berg97990a02013-04-19 01:02:55 +02007229 cb->args[2] = idx;
7230 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007231
Johannes Berg67748892010-10-04 21:14:06 +02007232 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007233}
7234
Eric W. Biederman15e47302012-09-07 20:12:54 +00007235static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007236 int flags, struct net_device *dev,
7237 bool allow_radio_stats,
7238 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007239{
7240 void *hdr;
7241 struct nlattr *infoattr;
7242
Johannes Berg11f78ac2014-11-14 16:43:50 +01007243 /* skip radio stats if userspace didn't request them */
7244 if (!survey->channel && !allow_radio_stats)
7245 return 0;
7246
Eric W. Biederman15e47302012-09-07 20:12:54 +00007247 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007248 NL80211_CMD_NEW_SURVEY_RESULTS);
7249 if (!hdr)
7250 return -ENOMEM;
7251
David S. Miller9360ffd2012-03-29 04:41:26 -04007252 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7253 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007254
7255 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7256 if (!infoattr)
7257 goto nla_put_failure;
7258
Johannes Berg11f78ac2014-11-14 16:43:50 +01007259 if (survey->channel &&
7260 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007261 survey->channel->center_freq))
7262 goto nla_put_failure;
7263
7264 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7265 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7266 goto nla_put_failure;
7267 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7268 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7269 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007270 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007271 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7272 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007273 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007274 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007275 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7276 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007277 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007278 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007279 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7280 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007281 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007282 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007283 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7284 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007285 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007286 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007287 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7288 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007289 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007290 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007291 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7292 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007293 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007294
7295 nla_nest_end(msg, infoattr);
7296
Johannes Berg053c0952015-01-16 22:09:00 +01007297 genlmsg_end(msg, hdr);
7298 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007299
7300 nla_put_failure:
7301 genlmsg_cancel(msg, hdr);
7302 return -EMSGSIZE;
7303}
7304
Johannes Berg11f78ac2014-11-14 16:43:50 +01007305static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007306{
7307 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007308 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007309 struct wireless_dev *wdev;
7310 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007311 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007312 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007313
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007314 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007315 if (res)
7316 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007317
Johannes Berg11f78ac2014-11-14 16:43:50 +01007318 /* prepare_wdev_dump parsed the attributes */
7319 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7320
Johannes Berg97990a02013-04-19 01:02:55 +02007321 if (!wdev->netdev) {
7322 res = -EINVAL;
7323 goto out_err;
7324 }
7325
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007326 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007327 res = -EOPNOTSUPP;
7328 goto out_err;
7329 }
7330
7331 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007332 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007333 if (res == -ENOENT)
7334 break;
7335 if (res)
7336 goto out_err;
7337
Johannes Berg11f78ac2014-11-14 16:43:50 +01007338 /* don't send disabled channels, but do send non-channel data */
7339 if (survey.channel &&
7340 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007341 survey_idx++;
7342 continue;
7343 }
7344
Holger Schurig61fa7132009-11-11 12:25:40 +01007345 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007346 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007347 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007348 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007349 goto out;
7350 survey_idx++;
7351 }
7352
7353 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007354 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007355 res = skb->len;
7356 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007357 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007358 return res;
7359}
7360
Samuel Ortizb23aa672009-07-01 21:26:54 +02007361static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7362{
7363 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7364 NL80211_WPA_VERSION_2));
7365}
7366
Jouni Malinen636a5d32009-03-19 13:39:22 +02007367static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7368{
Johannes Berg4c476992010-10-04 21:36:35 +02007369 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7370 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007371 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007372 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7373 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007374 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007375 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007376 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007377
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007378 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7379 return -EINVAL;
7380
7381 if (!info->attrs[NL80211_ATTR_MAC])
7382 return -EINVAL;
7383
Jouni Malinen17780922009-03-27 20:52:47 +02007384 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7385 return -EINVAL;
7386
Johannes Berg19957bb2009-07-02 17:20:43 +02007387 if (!info->attrs[NL80211_ATTR_SSID])
7388 return -EINVAL;
7389
7390 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7391 return -EINVAL;
7392
Johannes Bergfffd0932009-07-08 14:22:54 +02007393 err = nl80211_parse_key(info, &key);
7394 if (err)
7395 return err;
7396
7397 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007398 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7399 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007400 if (!key.p.key || !key.p.key_len)
7401 return -EINVAL;
7402 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7403 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7404 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7405 key.p.key_len != WLAN_KEY_LEN_WEP104))
7406 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007407 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007408 return -EINVAL;
7409 } else {
7410 key.p.key_len = 0;
7411 key.p.key = NULL;
7412 }
7413
Johannes Bergafea0b72010-08-10 09:46:42 +02007414 if (key.idx >= 0) {
7415 int i;
7416 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007417
Johannes Bergafea0b72010-08-10 09:46:42 +02007418 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7419 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7420 ok = true;
7421 break;
7422 }
7423 }
Johannes Berg4c476992010-10-04 21:36:35 +02007424 if (!ok)
7425 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007426 }
7427
Johannes Berg4c476992010-10-04 21:36:35 +02007428 if (!rdev->ops->auth)
7429 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007430
Johannes Berg074ac8d2010-09-16 14:58:22 +02007431 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007432 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7433 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007434
Johannes Berg19957bb2009-07-02 17:20:43 +02007435 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007436 chan = nl80211_get_valid_chan(&rdev->wiphy,
7437 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7438 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007439 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007440
Johannes Berg19957bb2009-07-02 17:20:43 +02007441 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7442 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7443
7444 if (info->attrs[NL80211_ATTR_IE]) {
7445 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7446 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7447 }
7448
7449 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007450 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007451 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007452
Jouni Malinene39e5b52012-09-30 19:29:39 +03007453 if (auth_type == NL80211_AUTHTYPE_SAE &&
7454 !info->attrs[NL80211_ATTR_SAE_DATA])
7455 return -EINVAL;
7456
7457 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7458 if (auth_type != NL80211_AUTHTYPE_SAE)
7459 return -EINVAL;
7460 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7461 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7462 /* need to include at least Auth Transaction and Status Code */
7463 if (sae_data_len < 4)
7464 return -EINVAL;
7465 }
7466
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007467 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7468
Johannes Berg95de8172012-01-20 13:55:25 +01007469 /*
7470 * Since we no longer track auth state, ignore
7471 * requests to only change local state.
7472 */
7473 if (local_state_change)
7474 return 0;
7475
Johannes Berg91bf9b22013-05-15 17:44:01 +02007476 wdev_lock(dev->ieee80211_ptr);
7477 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7478 ssid, ssid_len, ie, ie_len,
7479 key.p.key, key.p.key_len, key.idx,
7480 sae_data, sae_data_len);
7481 wdev_unlock(dev->ieee80211_ptr);
7482 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007483}
7484
Johannes Bergc0692b82010-08-27 14:26:53 +03007485static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7486 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007487 struct cfg80211_crypto_settings *settings,
7488 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007489{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007490 memset(settings, 0, sizeof(*settings));
7491
Samuel Ortizb23aa672009-07-01 21:26:54 +02007492 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7493
Johannes Bergc0692b82010-08-27 14:26:53 +03007494 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7495 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007496
Johannes Bergc0692b82010-08-27 14:26:53 +03007497 proto = nla_get_u16(
7498 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7499 settings->control_port_ethertype = cpu_to_be16(proto);
7500 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7501 proto != ETH_P_PAE)
7502 return -EINVAL;
7503 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7504 settings->control_port_no_encrypt = true;
7505 } else
7506 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7507
Samuel Ortizb23aa672009-07-01 21:26:54 +02007508 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7509 void *data;
7510 int len, i;
7511
7512 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7513 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7514 settings->n_ciphers_pairwise = len / sizeof(u32);
7515
7516 if (len % sizeof(u32))
7517 return -EINVAL;
7518
Johannes Berg3dc27d22009-07-02 21:36:37 +02007519 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007520 return -EINVAL;
7521
7522 memcpy(settings->ciphers_pairwise, data, len);
7523
7524 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007525 if (!cfg80211_supported_cipher_suite(
7526 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007527 settings->ciphers_pairwise[i]))
7528 return -EINVAL;
7529 }
7530
7531 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7532 settings->cipher_group =
7533 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007534 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7535 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007536 return -EINVAL;
7537 }
7538
7539 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7540 settings->wpa_versions =
7541 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7542 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7543 return -EINVAL;
7544 }
7545
7546 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7547 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007548 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007549
7550 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7551 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7552 settings->n_akm_suites = len / sizeof(u32);
7553
7554 if (len % sizeof(u32))
7555 return -EINVAL;
7556
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007557 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7558 return -EINVAL;
7559
Samuel Ortizb23aa672009-07-01 21:26:54 +02007560 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007561 }
7562
7563 return 0;
7564}
7565
Jouni Malinen636a5d32009-03-19 13:39:22 +02007566static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7567{
Johannes Berg4c476992010-10-04 21:36:35 +02007568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7569 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007570 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007571 struct cfg80211_assoc_request req = {};
7572 const u8 *bssid, *ssid;
7573 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007574
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007575 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7576 return -EINVAL;
7577
7578 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007579 !info->attrs[NL80211_ATTR_SSID] ||
7580 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007581 return -EINVAL;
7582
Johannes Berg4c476992010-10-04 21:36:35 +02007583 if (!rdev->ops->assoc)
7584 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007585
Johannes Berg074ac8d2010-09-16 14:58:22 +02007586 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007587 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7588 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007589
Johannes Berg19957bb2009-07-02 17:20:43 +02007590 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007591
Jouni Malinen664834d2014-01-15 00:01:44 +02007592 chan = nl80211_get_valid_chan(&rdev->wiphy,
7593 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7594 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007595 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007596
Johannes Berg19957bb2009-07-02 17:20:43 +02007597 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7598 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007599
7600 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007601 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7602 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007603 }
7604
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007605 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007606 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007607 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007608 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007609 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007610 else if (mfp != NL80211_MFP_NO)
7611 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007612 }
7613
Johannes Berg3e5d7642009-07-07 14:37:26 +02007614 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007615 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007616
Ben Greear7e7c8922011-11-18 11:31:59 -08007617 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007618 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007619
7620 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007621 memcpy(&req.ht_capa_mask,
7622 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7623 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007624
7625 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007626 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007627 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007628 memcpy(&req.ht_capa,
7629 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7630 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007631 }
7632
Johannes Bergee2aca32013-02-21 17:36:01 +01007633 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007634 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007635
7636 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007637 memcpy(&req.vht_capa_mask,
7638 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7639 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007640
7641 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007642 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007643 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007644 memcpy(&req.vht_capa,
7645 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7646 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007647 }
7648
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007649 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007650 if (!((rdev->wiphy.features &
7651 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7652 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7653 !wiphy_ext_feature_isset(&rdev->wiphy,
7654 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007655 return -EINVAL;
7656 req.flags |= ASSOC_REQ_USE_RRM;
7657 }
7658
Johannes Bergf62fab72013-02-21 20:09:09 +01007659 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007660 if (!err) {
7661 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007662 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7663 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007664 wdev_unlock(dev->ieee80211_ptr);
7665 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007666
Jouni Malinen636a5d32009-03-19 13:39:22 +02007667 return err;
7668}
7669
7670static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7671{
Johannes Berg4c476992010-10-04 21:36:35 +02007672 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7673 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007674 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007675 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007676 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007677 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007678
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007679 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7680 return -EINVAL;
7681
7682 if (!info->attrs[NL80211_ATTR_MAC])
7683 return -EINVAL;
7684
7685 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7686 return -EINVAL;
7687
Johannes Berg4c476992010-10-04 21:36:35 +02007688 if (!rdev->ops->deauth)
7689 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007690
Johannes Berg074ac8d2010-09-16 14:58:22 +02007691 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007692 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7693 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007694
Johannes Berg19957bb2009-07-02 17:20:43 +02007695 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007696
Johannes Berg19957bb2009-07-02 17:20:43 +02007697 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7698 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007699 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007700 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007701 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007702
7703 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007704 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7705 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007706 }
7707
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007708 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7709
Johannes Berg91bf9b22013-05-15 17:44:01 +02007710 wdev_lock(dev->ieee80211_ptr);
7711 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7712 local_state_change);
7713 wdev_unlock(dev->ieee80211_ptr);
7714 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007715}
7716
7717static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7718{
Johannes Berg4c476992010-10-04 21:36:35 +02007719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7720 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007721 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007722 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007723 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007724 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007725
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007726 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7727 return -EINVAL;
7728
7729 if (!info->attrs[NL80211_ATTR_MAC])
7730 return -EINVAL;
7731
7732 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7733 return -EINVAL;
7734
Johannes Berg4c476992010-10-04 21:36:35 +02007735 if (!rdev->ops->disassoc)
7736 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007737
Johannes Berg074ac8d2010-09-16 14:58:22 +02007738 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007739 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7740 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007741
Johannes Berg19957bb2009-07-02 17:20:43 +02007742 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007743
Johannes Berg19957bb2009-07-02 17:20:43 +02007744 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7745 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007746 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007747 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007748 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007749
7750 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007751 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7752 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007753 }
7754
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007755 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7756
Johannes Berg91bf9b22013-05-15 17:44:01 +02007757 wdev_lock(dev->ieee80211_ptr);
7758 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7759 local_state_change);
7760 wdev_unlock(dev->ieee80211_ptr);
7761 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007762}
7763
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007764static bool
7765nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007766 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007767 int rateval)
7768{
7769 struct wiphy *wiphy = &rdev->wiphy;
7770 bool found = false;
7771 int band, i;
7772
Johannes Berg57fbcce2016-04-12 15:56:15 +02007773 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007774 struct ieee80211_supported_band *sband;
7775
7776 sband = wiphy->bands[band];
7777 if (!sband)
7778 continue;
7779
7780 for (i = 0; i < sband->n_bitrates; i++) {
7781 if (sband->bitrates[i].bitrate == rateval) {
7782 mcast_rate[band] = i + 1;
7783 found = true;
7784 break;
7785 }
7786 }
7787 }
7788
7789 return found;
7790}
7791
Johannes Berg04a773a2009-04-19 21:24:32 +02007792static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7793{
Johannes Berg4c476992010-10-04 21:36:35 +02007794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7795 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007796 struct cfg80211_ibss_params ibss;
7797 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007798 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007799 int err;
7800
Johannes Berg8e30bc52009-04-22 17:45:38 +02007801 memset(&ibss, 0, sizeof(ibss));
7802
Johannes Berg04a773a2009-04-19 21:24:32 +02007803 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7804 return -EINVAL;
7805
Johannes Berg683b6d32012-11-08 21:25:48 +01007806 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007807 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7808 return -EINVAL;
7809
Johannes Berg8e30bc52009-04-22 17:45:38 +02007810 ibss.beacon_interval = 100;
7811
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05307812 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02007813 ibss.beacon_interval =
7814 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05307815
7816 err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval);
7817 if (err)
7818 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02007819
Johannes Berg4c476992010-10-04 21:36:35 +02007820 if (!rdev->ops->join_ibss)
7821 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007822
Johannes Berg4c476992010-10-04 21:36:35 +02007823 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7824 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007825
Johannes Berg79c97e92009-07-07 03:56:12 +02007826 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007827
Johannes Berg39193492011-09-16 13:45:25 +02007828 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007829 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007830
7831 if (!is_valid_ether_addr(ibss.bssid))
7832 return -EINVAL;
7833 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007834 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7835 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7836
7837 if (info->attrs[NL80211_ATTR_IE]) {
7838 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7839 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7840 }
7841
Johannes Berg683b6d32012-11-08 21:25:48 +01007842 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7843 if (err)
7844 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007845
Ilan Peer174e0cd2014-02-23 09:13:01 +02007846 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7847 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007848 return -EINVAL;
7849
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007850 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007851 case NL80211_CHAN_WIDTH_5:
7852 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007853 case NL80211_CHAN_WIDTH_20_NOHT:
7854 break;
7855 case NL80211_CHAN_WIDTH_20:
7856 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007857 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7858 return -EINVAL;
7859 break;
7860 case NL80211_CHAN_WIDTH_80:
7861 case NL80211_CHAN_WIDTH_80P80:
7862 case NL80211_CHAN_WIDTH_160:
7863 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7864 return -EINVAL;
7865 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7866 NL80211_EXT_FEATURE_VHT_IBSS))
7867 return -EINVAL;
7868 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007869 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007870 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007871 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007872
Johannes Berg04a773a2009-04-19 21:24:32 +02007873 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007874 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007875
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007876 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7877 u8 *rates =
7878 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7879 int n_rates =
7880 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7881 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007882 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007883
Johannes Berg34850ab2011-07-18 18:08:35 +02007884 err = ieee80211_get_ratemask(sband, rates, n_rates,
7885 &ibss.basic_rates);
7886 if (err)
7887 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007888 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007889
Simon Wunderlich803768f2013-06-28 10:39:58 +02007890 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7891 memcpy(&ibss.ht_capa_mask,
7892 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7893 sizeof(ibss.ht_capa_mask));
7894
7895 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7896 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7897 return -EINVAL;
7898 memcpy(&ibss.ht_capa,
7899 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7900 sizeof(ibss.ht_capa));
7901 }
7902
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007903 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7904 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7905 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7906 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007907
Johannes Berg4c476992010-10-04 21:36:35 +02007908 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307909 bool no_ht = false;
7910
Johannes Berg4c476992010-10-04 21:36:35 +02007911 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307912 info->attrs[NL80211_ATTR_KEYS],
7913 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007914 if (IS_ERR(connkeys))
7915 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307916
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007917 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7918 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007919 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307920 return -EINVAL;
7921 }
Johannes Berg4c476992010-10-04 21:36:35 +02007922 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007923
Antonio Quartulli267335d2012-01-31 20:25:47 +01007924 ibss.control_port =
7925 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7926
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007927 ibss.userspace_handles_dfs =
7928 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7929
Johannes Berg4c476992010-10-04 21:36:35 +02007930 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007931 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007932 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007933 return err;
7934}
7935
7936static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7937{
Johannes Berg4c476992010-10-04 21:36:35 +02007938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7939 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007940
Johannes Berg4c476992010-10-04 21:36:35 +02007941 if (!rdev->ops->leave_ibss)
7942 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007943
Johannes Berg4c476992010-10-04 21:36:35 +02007944 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7945 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007946
Johannes Berg4c476992010-10-04 21:36:35 +02007947 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007948}
7949
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007950static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7951{
7952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7953 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007954 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007955 u32 nla_rate;
7956 int err;
7957
7958 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007959 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7960 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007961 return -EOPNOTSUPP;
7962
7963 if (!rdev->ops->set_mcast_rate)
7964 return -EOPNOTSUPP;
7965
7966 memset(mcast_rate, 0, sizeof(mcast_rate));
7967
7968 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7969 return -EINVAL;
7970
7971 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7972 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7973 return -EINVAL;
7974
Ilan Peera1056b12015-10-22 22:27:46 +03007975 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007976
7977 return err;
7978}
7979
Johannes Bergad7e7182013-11-13 13:37:47 +01007980static struct sk_buff *
7981__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007982 struct wireless_dev *wdev, int approxlen,
7983 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007984 enum nl80211_attrs attr,
7985 const struct nl80211_vendor_cmd_info *info,
7986 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007987{
7988 struct sk_buff *skb;
7989 void *hdr;
7990 struct nlattr *data;
7991
7992 skb = nlmsg_new(approxlen + 100, gfp);
7993 if (!skb)
7994 return NULL;
7995
7996 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7997 if (!hdr) {
7998 kfree_skb(skb);
7999 return NULL;
8000 }
8001
8002 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8003 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008004
8005 if (info) {
8006 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8007 info->vendor_id))
8008 goto nla_put_failure;
8009 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8010 info->subcmd))
8011 goto nla_put_failure;
8012 }
8013
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008014 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008015 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8016 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008017 goto nla_put_failure;
8018 if (wdev->netdev &&
8019 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8020 wdev->netdev->ifindex))
8021 goto nla_put_failure;
8022 }
8023
Johannes Bergad7e7182013-11-13 13:37:47 +01008024 data = nla_nest_start(skb, attr);
8025
8026 ((void **)skb->cb)[0] = rdev;
8027 ((void **)skb->cb)[1] = hdr;
8028 ((void **)skb->cb)[2] = data;
8029
8030 return skb;
8031
8032 nla_put_failure:
8033 kfree_skb(skb);
8034 return NULL;
8035}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008036
Johannes Berge03ad6e2014-01-01 17:22:30 +01008037struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008038 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008039 enum nl80211_commands cmd,
8040 enum nl80211_attrs attr,
8041 int vendor_event_idx,
8042 int approxlen, gfp_t gfp)
8043{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008044 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008045 const struct nl80211_vendor_cmd_info *info;
8046
8047 switch (cmd) {
8048 case NL80211_CMD_TESTMODE:
8049 if (WARN_ON(vendor_event_idx != -1))
8050 return NULL;
8051 info = NULL;
8052 break;
8053 case NL80211_CMD_VENDOR:
8054 if (WARN_ON(vendor_event_idx < 0 ||
8055 vendor_event_idx >= wiphy->n_vendor_events))
8056 return NULL;
8057 info = &wiphy->vendor_events[vendor_event_idx];
8058 break;
8059 default:
8060 WARN_ON(1);
8061 return NULL;
8062 }
8063
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008064 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008065 cmd, attr, info, gfp);
8066}
8067EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8068
8069void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8070{
8071 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8072 void *hdr = ((void **)skb->cb)[1];
8073 struct nlattr *data = ((void **)skb->cb)[2];
8074 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8075
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008076 /* clear CB data for netlink core to own from now on */
8077 memset(skb->cb, 0, sizeof(skb->cb));
8078
Johannes Berge03ad6e2014-01-01 17:22:30 +01008079 nla_nest_end(skb, data);
8080 genlmsg_end(skb, hdr);
8081
8082 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8083 mcgrp = NL80211_MCGRP_VENDOR;
8084
8085 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8086 mcgrp, gfp);
8087}
8088EXPORT_SYMBOL(__cfg80211_send_event_skb);
8089
Johannes Bergaff89a92009-07-01 21:26:51 +02008090#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008091static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8092{
Johannes Berg4c476992010-10-04 21:36:35 +02008093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008094 struct wireless_dev *wdev =
8095 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008096 int err;
8097
David Spinadelfc73f112013-07-31 18:04:15 +03008098 if (!rdev->ops->testmode_cmd)
8099 return -EOPNOTSUPP;
8100
8101 if (IS_ERR(wdev)) {
8102 err = PTR_ERR(wdev);
8103 if (err != -EINVAL)
8104 return err;
8105 wdev = NULL;
8106 } else if (wdev->wiphy != &rdev->wiphy) {
8107 return -EINVAL;
8108 }
8109
Johannes Bergaff89a92009-07-01 21:26:51 +02008110 if (!info->attrs[NL80211_ATTR_TESTDATA])
8111 return -EINVAL;
8112
Johannes Bergad7e7182013-11-13 13:37:47 +01008113 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008114 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008115 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8116 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008117 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008118
Johannes Bergaff89a92009-07-01 21:26:51 +02008119 return err;
8120}
8121
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008122static int nl80211_testmode_dump(struct sk_buff *skb,
8123 struct netlink_callback *cb)
8124{
Johannes Berg00918d32011-12-13 17:22:05 +01008125 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008126 int err;
8127 long phy_idx;
8128 void *data = NULL;
8129 int data_len = 0;
8130
Johannes Berg5fe231e2013-05-08 21:45:15 +02008131 rtnl_lock();
8132
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008133 if (cb->args[0]) {
8134 /*
8135 * 0 is a valid index, but not valid for args[0],
8136 * so we need to offset by 1.
8137 */
8138 phy_idx = cb->args[0] - 1;
8139 } else {
8140 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8141 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8142 nl80211_policy);
8143 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008144 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008145
Johannes Berg2bd7e352012-06-15 14:23:16 +02008146 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8147 nl80211_fam.attrbuf);
8148 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008149 err = PTR_ERR(rdev);
8150 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008151 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008152 phy_idx = rdev->wiphy_idx;
8153 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008154
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008155 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8156 cb->args[1] =
8157 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8158 }
8159
8160 if (cb->args[1]) {
8161 data = nla_data((void *)cb->args[1]);
8162 data_len = nla_len((void *)cb->args[1]);
8163 }
8164
Johannes Berg00918d32011-12-13 17:22:05 +01008165 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8166 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008167 err = -ENOENT;
8168 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008169 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008170
Johannes Berg00918d32011-12-13 17:22:05 +01008171 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008172 err = -EOPNOTSUPP;
8173 goto out_err;
8174 }
8175
8176 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008177 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008178 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8179 NL80211_CMD_TESTMODE);
8180 struct nlattr *tmdata;
8181
Dan Carpentercb35fba2013-08-14 14:50:01 +03008182 if (!hdr)
8183 break;
8184
David S. Miller9360ffd2012-03-29 04:41:26 -04008185 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008186 genlmsg_cancel(skb, hdr);
8187 break;
8188 }
8189
8190 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8191 if (!tmdata) {
8192 genlmsg_cancel(skb, hdr);
8193 break;
8194 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008195 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008196 nla_nest_end(skb, tmdata);
8197
8198 if (err == -ENOBUFS || err == -ENOENT) {
8199 genlmsg_cancel(skb, hdr);
8200 break;
8201 } else if (err) {
8202 genlmsg_cancel(skb, hdr);
8203 goto out_err;
8204 }
8205
8206 genlmsg_end(skb, hdr);
8207 }
8208
8209 err = skb->len;
8210 /* see above */
8211 cb->args[0] = phy_idx + 1;
8212 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008213 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008214 return err;
8215}
Johannes Bergaff89a92009-07-01 21:26:51 +02008216#endif
8217
Samuel Ortizb23aa672009-07-01 21:26:54 +02008218static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8219{
Johannes Berg4c476992010-10-04 21:36:35 +02008220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8221 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008222 struct cfg80211_connect_params connect;
8223 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008224 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008225 int err;
8226
8227 memset(&connect, 0, sizeof(connect));
8228
8229 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8230 return -EINVAL;
8231
8232 if (!info->attrs[NL80211_ATTR_SSID] ||
8233 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8234 return -EINVAL;
8235
8236 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8237 connect.auth_type =
8238 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008239 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8240 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008241 return -EINVAL;
8242 } else
8243 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8244
8245 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8246
Johannes Bergc0692b82010-08-27 14:26:53 +03008247 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008248 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008249 if (err)
8250 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008251
Johannes Berg074ac8d2010-09-16 14:58:22 +02008252 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008253 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8254 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008255
Johannes Berg79c97e92009-07-07 03:56:12 +02008256 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008257
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308258 connect.bg_scan_period = -1;
8259 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8260 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8261 connect.bg_scan_period =
8262 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8263 }
8264
Samuel Ortizb23aa672009-07-01 21:26:54 +02008265 if (info->attrs[NL80211_ATTR_MAC])
8266 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008267 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8268 connect.bssid_hint =
8269 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008270 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8271 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8272
8273 if (info->attrs[NL80211_ATTR_IE]) {
8274 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8275 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8276 }
8277
Jouni Malinencee00a92013-01-15 17:15:57 +02008278 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8279 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8280 if (connect.mfp != NL80211_MFP_REQUIRED &&
8281 connect.mfp != NL80211_MFP_NO)
8282 return -EINVAL;
8283 } else {
8284 connect.mfp = NL80211_MFP_NO;
8285 }
8286
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008287 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8288 connect.prev_bssid =
8289 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8290
Samuel Ortizb23aa672009-07-01 21:26:54 +02008291 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008292 connect.channel = nl80211_get_valid_chan(
8293 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8294 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008295 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008296 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008297 connect.channel_hint = nl80211_get_valid_chan(
8298 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8299 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008300 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008301 }
8302
Johannes Bergfffd0932009-07-08 14:22:54 +02008303 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8304 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308305 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008306 if (IS_ERR(connkeys))
8307 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008308 }
8309
Ben Greear7e7c8922011-11-18 11:31:59 -08008310 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8311 connect.flags |= ASSOC_REQ_DISABLE_HT;
8312
8313 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8314 memcpy(&connect.ht_capa_mask,
8315 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8316 sizeof(connect.ht_capa_mask));
8317
8318 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008319 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008320 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008321 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008322 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008323 memcpy(&connect.ht_capa,
8324 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8325 sizeof(connect.ht_capa));
8326 }
8327
Johannes Bergee2aca32013-02-21 17:36:01 +01008328 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8329 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8330
8331 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8332 memcpy(&connect.vht_capa_mask,
8333 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8334 sizeof(connect.vht_capa_mask));
8335
8336 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8337 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008338 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008339 return -EINVAL;
8340 }
8341 memcpy(&connect.vht_capa,
8342 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8343 sizeof(connect.vht_capa));
8344 }
8345
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008346 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008347 if (!((rdev->wiphy.features &
8348 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8349 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8350 !wiphy_ext_feature_isset(&rdev->wiphy,
8351 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008352 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008353 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008354 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008355 connect.flags |= ASSOC_REQ_USE_RRM;
8356 }
8357
Lior David34d50512016-01-28 10:58:25 +02008358 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008359 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008360 kzfree(connkeys);
8361 return -EOPNOTSUPP;
8362 }
8363
Arend van Spriel38de03d2016-03-02 20:37:18 +01008364 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8365 /* bss selection makes no sense if bssid is set */
8366 if (connect.bssid) {
8367 kzfree(connkeys);
8368 return -EINVAL;
8369 }
8370
8371 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8372 wiphy, &connect.bss_select);
8373 if (err) {
8374 kzfree(connkeys);
8375 return err;
8376 }
8377 }
8378
Johannes Berg83739b02013-05-15 17:44:01 +02008379 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008380 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8381 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008382 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008383 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008384 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008385 return err;
8386}
8387
8388static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8389{
Johannes Berg4c476992010-10-04 21:36:35 +02008390 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8391 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008392 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008393 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008394
8395 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8396 reason = WLAN_REASON_DEAUTH_LEAVING;
8397 else
8398 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8399
8400 if (reason == 0)
8401 return -EINVAL;
8402
Johannes Berg074ac8d2010-09-16 14:58:22 +02008403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008404 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8405 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008406
Johannes Berg83739b02013-05-15 17:44:01 +02008407 wdev_lock(dev->ieee80211_ptr);
8408 ret = cfg80211_disconnect(rdev, dev, reason, true);
8409 wdev_unlock(dev->ieee80211_ptr);
8410 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008411}
8412
Johannes Berg463d0182009-07-14 00:33:35 +02008413static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8414{
Johannes Berg4c476992010-10-04 21:36:35 +02008415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008416 struct net *net;
8417 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008418
Vadim Kochan4b681c82015-01-12 16:34:05 +02008419 if (info->attrs[NL80211_ATTR_PID]) {
8420 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8421
8422 net = get_net_ns_by_pid(pid);
8423 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8424 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8425
8426 net = get_net_ns_by_fd(fd);
8427 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008428 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008429 }
Johannes Berg463d0182009-07-14 00:33:35 +02008430
Johannes Berg4c476992010-10-04 21:36:35 +02008431 if (IS_ERR(net))
8432 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008433
8434 err = 0;
8435
8436 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008437 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8438 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008439
Johannes Berg463d0182009-07-14 00:33:35 +02008440 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008441 return err;
8442}
8443
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008444static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8445{
Johannes Berg4c476992010-10-04 21:36:35 +02008446 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008447 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8448 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008449 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008450 struct cfg80211_pmksa pmksa;
8451
8452 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8453
8454 if (!info->attrs[NL80211_ATTR_MAC])
8455 return -EINVAL;
8456
8457 if (!info->attrs[NL80211_ATTR_PMKID])
8458 return -EINVAL;
8459
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008460 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8461 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8462
Johannes Berg074ac8d2010-09-16 14:58:22 +02008463 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008464 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8465 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008466
8467 switch (info->genlhdr->cmd) {
8468 case NL80211_CMD_SET_PMKSA:
8469 rdev_ops = rdev->ops->set_pmksa;
8470 break;
8471 case NL80211_CMD_DEL_PMKSA:
8472 rdev_ops = rdev->ops->del_pmksa;
8473 break;
8474 default:
8475 WARN_ON(1);
8476 break;
8477 }
8478
Johannes Berg4c476992010-10-04 21:36:35 +02008479 if (!rdev_ops)
8480 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008481
Johannes Berg4c476992010-10-04 21:36:35 +02008482 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008483}
8484
8485static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8486{
Johannes Berg4c476992010-10-04 21:36:35 +02008487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8488 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008489
Johannes Berg074ac8d2010-09-16 14:58:22 +02008490 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008491 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8492 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008493
Johannes Berg4c476992010-10-04 21:36:35 +02008494 if (!rdev->ops->flush_pmksa)
8495 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008496
Hila Gonene35e4d22012-06-27 17:19:42 +03008497 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008498}
8499
Arik Nemtsov109086c2011-09-28 14:12:50 +03008500static int nl80211_tdls_mgmt(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 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308505 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008506 u16 status_code;
8507 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008508 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008509
8510 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8511 !rdev->ops->tdls_mgmt)
8512 return -EOPNOTSUPP;
8513
8514 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8515 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8516 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8517 !info->attrs[NL80211_ATTR_IE] ||
8518 !info->attrs[NL80211_ATTR_MAC])
8519 return -EINVAL;
8520
8521 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8522 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8523 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8524 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008525 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308526 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8527 peer_capability =
8528 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008529
Hila Gonene35e4d22012-06-27 17:19:42 +03008530 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308531 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008532 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008533 nla_data(info->attrs[NL80211_ATTR_IE]),
8534 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008535}
8536
8537static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8538{
8539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8540 struct net_device *dev = info->user_ptr[1];
8541 enum nl80211_tdls_operation operation;
8542 u8 *peer;
8543
8544 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8545 !rdev->ops->tdls_oper)
8546 return -EOPNOTSUPP;
8547
8548 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8549 !info->attrs[NL80211_ATTR_MAC])
8550 return -EINVAL;
8551
8552 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8553 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8554
Hila Gonene35e4d22012-06-27 17:19:42 +03008555 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008556}
8557
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008558static int nl80211_remain_on_channel(struct sk_buff *skb,
8559 struct genl_info *info)
8560{
Johannes Berg4c476992010-10-04 21:36:35 +02008561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008562 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008563 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008564 struct sk_buff *msg;
8565 void *hdr;
8566 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008567 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008568 int err;
8569
8570 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8571 !info->attrs[NL80211_ATTR_DURATION])
8572 return -EINVAL;
8573
8574 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8575
Johannes Berg7c4ef712011-11-18 15:33:48 +01008576 if (!rdev->ops->remain_on_channel ||
8577 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008578 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008579
Johannes Bergebf348f2012-06-01 12:50:54 +02008580 /*
8581 * We should be on that channel for at least a minimum amount of
8582 * time (10ms) but no longer than the driver supports.
8583 */
8584 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8585 duration > rdev->wiphy.max_remain_on_channel_duration)
8586 return -EINVAL;
8587
Johannes Berg683b6d32012-11-08 21:25:48 +01008588 err = nl80211_parse_chandef(rdev, info, &chandef);
8589 if (err)
8590 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008591
8592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008593 if (!msg)
8594 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008595
Eric W. Biederman15e47302012-09-07 20:12:54 +00008596 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008597 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008598 if (!hdr) {
8599 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008600 goto free_msg;
8601 }
8602
Johannes Berg683b6d32012-11-08 21:25:48 +01008603 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8604 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008605
8606 if (err)
8607 goto free_msg;
8608
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008609 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8610 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008611 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008612
8613 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008614
8615 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008616
8617 nla_put_failure:
8618 err = -ENOBUFS;
8619 free_msg:
8620 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008621 return err;
8622}
8623
8624static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8625 struct genl_info *info)
8626{
Johannes Berg4c476992010-10-04 21:36:35 +02008627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008628 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008629 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008630
8631 if (!info->attrs[NL80211_ATTR_COOKIE])
8632 return -EINVAL;
8633
Johannes Berg4c476992010-10-04 21:36:35 +02008634 if (!rdev->ops->cancel_remain_on_channel)
8635 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008636
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008637 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8638
Hila Gonene35e4d22012-06-27 17:19:42 +03008639 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008640}
8641
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008642static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8643 u8 *rates, u8 rates_len)
8644{
8645 u8 i;
8646 u32 mask = 0;
8647
8648 for (i = 0; i < rates_len; i++) {
8649 int rate = (rates[i] & 0x7f) * 5;
8650 int ridx;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008651
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008652 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8653 struct ieee80211_rate *srate =
8654 &sband->bitrates[ridx];
8655 if (rate == srate->bitrate) {
8656 mask |= 1 << ridx;
8657 break;
8658 }
8659 }
8660 if (ridx == sband->n_bitrates)
8661 return 0; /* rate not found */
8662 }
8663
8664 return mask;
8665}
8666
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008667static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8668 u8 *rates, u8 rates_len,
8669 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8670{
8671 u8 i;
8672
8673 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8674
8675 for (i = 0; i < rates_len; i++) {
8676 int ridx, rbit;
8677
8678 ridx = rates[i] / 8;
8679 rbit = BIT(rates[i] % 8);
8680
8681 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008682 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008683 return false;
8684
8685 /* check availability */
8686 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8687 mcs[ridx] |= rbit;
8688 else
8689 return false;
8690 }
8691
8692 return true;
8693}
8694
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008695static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8696{
8697 u16 mcs_mask = 0;
8698
8699 switch (vht_mcs_map) {
8700 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8701 break;
8702 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8703 mcs_mask = 0x00FF;
8704 break;
8705 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8706 mcs_mask = 0x01FF;
8707 break;
8708 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8709 mcs_mask = 0x03FF;
8710 break;
8711 default:
8712 break;
8713 }
8714
8715 return mcs_mask;
8716}
8717
8718static void vht_build_mcs_mask(u16 vht_mcs_map,
8719 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8720{
8721 u8 nss;
8722
8723 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8724 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8725 vht_mcs_map >>= 2;
8726 }
8727}
8728
8729static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8730 struct nl80211_txrate_vht *txrate,
8731 u16 mcs[NL80211_VHT_NSS_MAX])
8732{
8733 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8734 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8735 u8 i;
8736
8737 if (!sband->vht_cap.vht_supported)
8738 return false;
8739
8740 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8741
8742 /* Build vht_mcs_mask from VHT capabilities */
8743 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8744
8745 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8746 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8747 mcs[i] = txrate->mcs[i];
8748 else
8749 return false;
8750 }
8751
8752 return true;
8753}
8754
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008755static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008756 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8757 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008758 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8759 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008760 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008761 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008762};
8763
8764static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8765 struct genl_info *info)
8766{
8767 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008769 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008770 int rem, i;
8771 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008772 struct nlattr *tx_rates;
8773 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008774 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008775
Johannes Berg4c476992010-10-04 21:36:35 +02008776 if (!rdev->ops->set_bitrate_mask)
8777 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008778
8779 memset(&mask, 0, sizeof(mask));
8780 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008781 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008782 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008783
8784 if (!sband)
8785 continue;
8786
8787 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008788 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008789 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008790 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008791
8792 if (!sband->vht_cap.vht_supported)
8793 continue;
8794
8795 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8796 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008797 }
8798
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008799 /* if no rates are given set it back to the defaults */
8800 if (!info->attrs[NL80211_ATTR_TX_RATES])
8801 goto out;
8802
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008803 /*
8804 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008805 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008806 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008807 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008808 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008809 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008810 int err;
8811
Johannes Berg57fbcce2016-04-12 15:56:15 +02008812 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008813 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008814 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008815 if (sband == NULL)
8816 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008817 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8818 nla_len(tx_rates), nl80211_txattr_policy);
8819 if (err)
8820 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008821 if (tb[NL80211_TXRATE_LEGACY]) {
8822 mask.control[band].legacy = rateset_to_mask(
8823 sband,
8824 nla_data(tb[NL80211_TXRATE_LEGACY]),
8825 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308826 if ((mask.control[band].legacy == 0) &&
8827 nla_len(tb[NL80211_TXRATE_LEGACY]))
8828 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008829 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008830 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008831 if (!ht_rateset_to_mask(
8832 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008833 nla_data(tb[NL80211_TXRATE_HT]),
8834 nla_len(tb[NL80211_TXRATE_HT]),
8835 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008836 return -EINVAL;
8837 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008838 if (tb[NL80211_TXRATE_VHT]) {
8839 if (!vht_set_mcs_mask(
8840 sband,
8841 nla_data(tb[NL80211_TXRATE_VHT]),
8842 mask.control[band].vht_mcs))
8843 return -EINVAL;
8844 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008845 if (tb[NL80211_TXRATE_GI]) {
8846 mask.control[band].gi =
8847 nla_get_u8(tb[NL80211_TXRATE_GI]);
8848 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8849 return -EINVAL;
8850 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008851
8852 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008853 /* don't allow empty legacy rates if HT or VHT
8854 * are not even supported.
8855 */
8856 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8857 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008858 return -EINVAL;
8859
8860 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008861 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008862 goto out;
8863
8864 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8865 if (mask.control[band].vht_mcs[i])
8866 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008867
8868 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008869 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008870 }
8871 }
8872
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008873out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008874 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008875}
8876
Johannes Berg2e161f72010-08-12 15:38:38 +02008877static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008878{
Johannes Berg4c476992010-10-04 21:36:35 +02008879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008880 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008881 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008882
8883 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8884 return -EINVAL;
8885
Johannes Berg2e161f72010-08-12 15:38:38 +02008886 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8887 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008888
Johannes Berg71bbc992012-06-15 15:30:18 +02008889 switch (wdev->iftype) {
8890 case NL80211_IFTYPE_STATION:
8891 case NL80211_IFTYPE_ADHOC:
8892 case NL80211_IFTYPE_P2P_CLIENT:
8893 case NL80211_IFTYPE_AP:
8894 case NL80211_IFTYPE_AP_VLAN:
8895 case NL80211_IFTYPE_MESH_POINT:
8896 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008897 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008898 break;
8899 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008900 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008901 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008902
8903 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008904 if (!rdev->ops->mgmt_tx)
8905 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008906
Eric W. Biederman15e47302012-09-07 20:12:54 +00008907 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008908 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8909 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008910}
8911
Johannes Berg2e161f72010-08-12 15:38:38 +02008912static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008913{
Johannes Berg4c476992010-10-04 21:36:35 +02008914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008915 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008916 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008917 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008918 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008919 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008920 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008921 struct cfg80211_mgmt_tx_params params = {
8922 .dont_wait_for_ack =
8923 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8924 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008925
Johannes Berg683b6d32012-11-08 21:25:48 +01008926 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008927 return -EINVAL;
8928
Johannes Berg4c476992010-10-04 21:36:35 +02008929 if (!rdev->ops->mgmt_tx)
8930 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008931
Johannes Berg71bbc992012-06-15 15:30:18 +02008932 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008933 case NL80211_IFTYPE_P2P_DEVICE:
8934 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8935 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008936 case NL80211_IFTYPE_STATION:
8937 case NL80211_IFTYPE_ADHOC:
8938 case NL80211_IFTYPE_P2P_CLIENT:
8939 case NL80211_IFTYPE_AP:
8940 case NL80211_IFTYPE_AP_VLAN:
8941 case NL80211_IFTYPE_MESH_POINT:
8942 case NL80211_IFTYPE_P2P_GO:
8943 break;
8944 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008945 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008946 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008947
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008948 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008949 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008950 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008951 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008952
8953 /*
8954 * We should wait on the channel for at least a minimum amount
8955 * of time (10ms) but no longer than the driver supports.
8956 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008957 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8958 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008959 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008960 }
8961
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008962 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008963
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008964 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008965 return -EINVAL;
8966
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008967 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308968
Antonio Quartulliea141b752013-06-11 14:20:03 +02008969 /* get the channel if any has been specified, otherwise pass NULL to
8970 * the driver. The latter will use the current one
8971 */
8972 chandef.chan = NULL;
8973 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8974 err = nl80211_parse_chandef(rdev, info, &chandef);
8975 if (err)
8976 return err;
8977 }
8978
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008979 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008980 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008981
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008982 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8983 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8984
8985 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8986 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8987 int i;
8988
8989 if (len % sizeof(u16))
8990 return -EINVAL;
8991
8992 params.n_csa_offsets = len / sizeof(u16);
8993 params.csa_offsets =
8994 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8995
8996 /* check that all the offsets fit the frame */
8997 for (i = 0; i < params.n_csa_offsets; i++) {
8998 if (params.csa_offsets[i] >= params.len)
8999 return -EINVAL;
9000 }
9001 }
9002
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009003 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009004 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9005 if (!msg)
9006 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009007
Eric W. Biederman15e47302012-09-07 20:12:54 +00009008 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009009 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009010 if (!hdr) {
9011 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009012 goto free_msg;
9013 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009014 }
Johannes Berge247bd902011-11-04 11:18:21 +01009015
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009016 params.chan = chandef.chan;
9017 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009018 if (err)
9019 goto free_msg;
9020
Johannes Berge247bd902011-11-04 11:18:21 +01009021 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009022 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9023 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009024 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009025
Johannes Berge247bd902011-11-04 11:18:21 +01009026 genlmsg_end(msg, hdr);
9027 return genlmsg_reply(msg, info);
9028 }
9029
9030 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009031
9032 nla_put_failure:
9033 err = -ENOBUFS;
9034 free_msg:
9035 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009036 return err;
9037}
9038
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009039static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9040{
9041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009042 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009043 u64 cookie;
9044
9045 if (!info->attrs[NL80211_ATTR_COOKIE])
9046 return -EINVAL;
9047
9048 if (!rdev->ops->mgmt_tx_cancel_wait)
9049 return -EOPNOTSUPP;
9050
Johannes Berg71bbc992012-06-15 15:30:18 +02009051 switch (wdev->iftype) {
9052 case NL80211_IFTYPE_STATION:
9053 case NL80211_IFTYPE_ADHOC:
9054 case NL80211_IFTYPE_P2P_CLIENT:
9055 case NL80211_IFTYPE_AP:
9056 case NL80211_IFTYPE_AP_VLAN:
9057 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009058 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009059 break;
9060 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009061 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009062 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009063
9064 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9065
Hila Gonene35e4d22012-06-27 17:19:42 +03009066 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009067}
9068
Kalle Valoffb9eb32010-02-17 17:58:10 +02009069static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9070{
Johannes Berg4c476992010-10-04 21:36:35 +02009071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009072 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009073 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009074 u8 ps_state;
9075 bool state;
9076 int err;
9077
Johannes Berg4c476992010-10-04 21:36:35 +02009078 if (!info->attrs[NL80211_ATTR_PS_STATE])
9079 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009080
9081 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9082
Johannes Berg4c476992010-10-04 21:36:35 +02009083 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9084 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009085
9086 wdev = dev->ieee80211_ptr;
9087
Johannes Berg4c476992010-10-04 21:36:35 +02009088 if (!rdev->ops->set_power_mgmt)
9089 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009090
9091 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9092
9093 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009094 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009095
Hila Gonene35e4d22012-06-27 17:19:42 +03009096 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009097 if (!err)
9098 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009099 return err;
9100}
9101
9102static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9103{
Johannes Berg4c476992010-10-04 21:36:35 +02009104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009105 enum nl80211_ps_state ps_state;
9106 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009107 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009108 struct sk_buff *msg;
9109 void *hdr;
9110 int err;
9111
Kalle Valoffb9eb32010-02-17 17:58:10 +02009112 wdev = dev->ieee80211_ptr;
9113
Johannes Berg4c476992010-10-04 21:36:35 +02009114 if (!rdev->ops->set_power_mgmt)
9115 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009116
9117 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009118 if (!msg)
9119 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009120
Eric W. Biederman15e47302012-09-07 20:12:54 +00009121 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009122 NL80211_CMD_GET_POWER_SAVE);
9123 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009124 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009125 goto free_msg;
9126 }
9127
9128 if (wdev->ps)
9129 ps_state = NL80211_PS_ENABLED;
9130 else
9131 ps_state = NL80211_PS_DISABLED;
9132
David S. Miller9360ffd2012-03-29 04:41:26 -04009133 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9134 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009135
9136 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009137 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009138
Johannes Berg4c476992010-10-04 21:36:35 +02009139 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009140 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009141 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009142 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009143 return err;
9144}
9145
Johannes Berg94e860f2014-01-20 23:58:15 +01009146static const struct nla_policy
9147nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009148 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9149 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9150 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009151 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9152 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9153 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009154};
9155
Thomas Pedersen84f10702012-07-12 16:17:33 -07009156static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009157 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009158{
9159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009160 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009161 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009162
Johannes Bergd9d8b012012-11-26 12:51:52 +01009163 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009164 return -EINVAL;
9165
Thomas Pedersen84f10702012-07-12 16:17:33 -07009166 if (!rdev->ops->set_cqm_txe_config)
9167 return -EOPNOTSUPP;
9168
9169 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9170 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9171 return -EOPNOTSUPP;
9172
Hila Gonene35e4d22012-06-27 17:19:42 +03009173 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009174}
9175
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009176static int nl80211_set_cqm_rssi(struct genl_info *info,
9177 s32 threshold, u32 hysteresis)
9178{
Johannes Berg4c476992010-10-04 21:36:35 +02009179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009180 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009181 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009182
9183 if (threshold > 0)
9184 return -EINVAL;
9185
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009186 /* disabling - hysteresis should also be zero then */
9187 if (threshold == 0)
9188 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009189
Johannes Berg4c476992010-10-04 21:36:35 +02009190 if (!rdev->ops->set_cqm_rssi_config)
9191 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009192
Johannes Berg074ac8d2010-09-16 14:58:22 +02009193 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009194 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9195 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009196
Hila Gonene35e4d22012-06-27 17:19:42 +03009197 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009198}
9199
9200static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9201{
9202 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9203 struct nlattr *cqm;
9204 int err;
9205
9206 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009207 if (!cqm)
9208 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009209
9210 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9211 nl80211_attr_cqm_policy);
9212 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009213 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009214
9215 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9216 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009217 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9218 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009219
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009220 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9221 }
9222
9223 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9224 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9225 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9226 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9227 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9228 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9229
9230 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9231 }
9232
9233 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009234}
9235
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009236static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9237{
9238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9239 struct net_device *dev = info->user_ptr[1];
9240 struct ocb_setup setup = {};
9241 int err;
9242
9243 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9244 if (err)
9245 return err;
9246
9247 return cfg80211_join_ocb(rdev, dev, &setup);
9248}
9249
9250static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9251{
9252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9253 struct net_device *dev = info->user_ptr[1];
9254
9255 return cfg80211_leave_ocb(rdev, dev);
9256}
9257
Johannes Berg29cbe682010-12-03 09:20:44 +01009258static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9259{
9260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9261 struct net_device *dev = info->user_ptr[1];
9262 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009263 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009264 int err;
9265
9266 /* start with default */
9267 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009268 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009269
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009270 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009271 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009272 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009273 if (err)
9274 return err;
9275 }
9276
9277 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9278 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9279 return -EINVAL;
9280
Javier Cardonac80d5452010-12-16 17:37:49 -08009281 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9282 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9283
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009284 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9285 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9286 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9287 return -EINVAL;
9288
Marco Porsch9bdbf042013-01-07 16:04:51 +01009289 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9290 setup.beacon_interval =
9291 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309292
9293 err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval);
9294 if (err)
9295 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009296 }
9297
9298 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9299 setup.dtim_period =
9300 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9301 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9302 return -EINVAL;
9303 }
9304
Javier Cardonac80d5452010-12-16 17:37:49 -08009305 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9306 /* parse additional setup parameters if given */
9307 err = nl80211_parse_mesh_setup(info, &setup);
9308 if (err)
9309 return err;
9310 }
9311
Thomas Pedersend37bb182013-03-04 13:06:13 -08009312 if (setup.user_mpm)
9313 cfg.auto_open_plinks = false;
9314
Johannes Bergcc1d2802012-05-16 23:50:20 +02009315 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009316 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9317 if (err)
9318 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009319 } else {
9320 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009321 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009322 }
9323
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009324 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9325 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9326 int n_rates =
9327 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9328 struct ieee80211_supported_band *sband;
9329
9330 if (!setup.chandef.chan)
9331 return -EINVAL;
9332
9333 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9334
9335 err = ieee80211_get_ratemask(sband, rates, n_rates,
9336 &setup.basic_rates);
9337 if (err)
9338 return err;
9339 }
9340
Javier Cardonac80d5452010-12-16 17:37:49 -08009341 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009342}
9343
9344static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9345{
9346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9347 struct net_device *dev = info->user_ptr[1];
9348
9349 return cfg80211_leave_mesh(rdev, dev);
9350}
9351
Johannes Bergdfb89c52012-06-27 09:23:48 +02009352#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009353static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9354 struct cfg80211_registered_device *rdev)
9355{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009356 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009357 struct nlattr *nl_pats, *nl_pat;
9358 int i, pat_len;
9359
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009360 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009361 return 0;
9362
9363 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9364 if (!nl_pats)
9365 return -ENOBUFS;
9366
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009367 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009368 nl_pat = nla_nest_start(msg, i + 1);
9369 if (!nl_pat)
9370 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009371 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009372 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009373 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009374 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9375 wowlan->patterns[i].pattern) ||
9376 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009377 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009378 return -ENOBUFS;
9379 nla_nest_end(msg, nl_pat);
9380 }
9381 nla_nest_end(msg, nl_pats);
9382
9383 return 0;
9384}
9385
Johannes Berg2a0e0472013-01-23 22:57:40 +01009386static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9387 struct cfg80211_wowlan_tcp *tcp)
9388{
9389 struct nlattr *nl_tcp;
9390
9391 if (!tcp)
9392 return 0;
9393
9394 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9395 if (!nl_tcp)
9396 return -ENOBUFS;
9397
Jiri Benc930345e2015-03-29 16:59:25 +02009398 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9399 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009400 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9401 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9402 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9403 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9404 tcp->payload_len, tcp->payload) ||
9405 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9406 tcp->data_interval) ||
9407 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9408 tcp->wake_len, tcp->wake_data) ||
9409 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9410 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9411 return -ENOBUFS;
9412
9413 if (tcp->payload_seq.len &&
9414 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9415 sizeof(tcp->payload_seq), &tcp->payload_seq))
9416 return -ENOBUFS;
9417
9418 if (tcp->payload_tok.len &&
9419 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9420 sizeof(tcp->payload_tok) + tcp->tokens_size,
9421 &tcp->payload_tok))
9422 return -ENOBUFS;
9423
Johannes Berge248ad32013-05-16 10:24:28 +02009424 nla_nest_end(msg, nl_tcp);
9425
Johannes Berg2a0e0472013-01-23 22:57:40 +01009426 return 0;
9427}
9428
Luciano Coelho75453cc2015-01-09 14:06:37 +02009429static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9430 struct cfg80211_sched_scan_request *req)
9431{
Avraham Stern3b06d272015-10-12 09:51:34 +03009432 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009433 int i;
9434
9435 if (!req)
9436 return 0;
9437
9438 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9439 if (!nd)
9440 return -ENOBUFS;
9441
Avraham Stern3b06d272015-10-12 09:51:34 +03009442 if (req->n_scan_plans == 1 &&
9443 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9444 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009445 return -ENOBUFS;
9446
Luciano Coelho21fea562015-03-17 16:36:01 +02009447 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9448 return -ENOBUFS;
9449
Luciano Coelho75453cc2015-01-09 14:06:37 +02009450 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9451 if (!freqs)
9452 return -ENOBUFS;
9453
9454 for (i = 0; i < req->n_channels; i++)
9455 nla_put_u32(msg, i, req->channels[i]->center_freq);
9456
9457 nla_nest_end(msg, freqs);
9458
9459 if (req->n_match_sets) {
9460 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9461 for (i = 0; i < req->n_match_sets; i++) {
9462 match = nla_nest_start(msg, i);
9463 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9464 req->match_sets[i].ssid.ssid_len,
9465 req->match_sets[i].ssid.ssid);
9466 nla_nest_end(msg, match);
9467 }
9468 nla_nest_end(msg, matches);
9469 }
9470
Avraham Stern3b06d272015-10-12 09:51:34 +03009471 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9472 if (!scan_plans)
9473 return -ENOBUFS;
9474
9475 for (i = 0; i < req->n_scan_plans; i++) {
9476 scan_plan = nla_nest_start(msg, i + 1);
9477 if (!scan_plan ||
9478 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9479 req->scan_plans[i].interval) ||
9480 (req->scan_plans[i].iterations &&
9481 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9482 req->scan_plans[i].iterations)))
9483 return -ENOBUFS;
9484 nla_nest_end(msg, scan_plan);
9485 }
9486 nla_nest_end(msg, scan_plans);
9487
Luciano Coelho75453cc2015-01-09 14:06:37 +02009488 nla_nest_end(msg, nd);
9489
9490 return 0;
9491}
9492
Johannes Bergff1b6e62011-05-04 15:37:28 +02009493static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9494{
9495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9496 struct sk_buff *msg;
9497 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009498 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009499
Johannes Berg964dc9e2013-06-03 17:25:34 +02009500 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009501 return -EOPNOTSUPP;
9502
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009503 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009504 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009505 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9506 rdev->wiphy.wowlan_config->tcp->payload_len +
9507 rdev->wiphy.wowlan_config->tcp->wake_len +
9508 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009509 }
9510
9511 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009512 if (!msg)
9513 return -ENOMEM;
9514
Eric W. Biederman15e47302012-09-07 20:12:54 +00009515 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009516 NL80211_CMD_GET_WOWLAN);
9517 if (!hdr)
9518 goto nla_put_failure;
9519
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009520 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009521 struct nlattr *nl_wowlan;
9522
9523 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9524 if (!nl_wowlan)
9525 goto nla_put_failure;
9526
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009527 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009528 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009529 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009530 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009531 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009532 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009533 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009534 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009535 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009536 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009537 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009538 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009539 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009540 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9541 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009542
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009543 if (nl80211_send_wowlan_patterns(msg, rdev))
9544 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009545
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009546 if (nl80211_send_wowlan_tcp(msg,
9547 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009548 goto nla_put_failure;
9549
Luciano Coelho75453cc2015-01-09 14:06:37 +02009550 if (nl80211_send_wowlan_nd(
9551 msg,
9552 rdev->wiphy.wowlan_config->nd_config))
9553 goto nla_put_failure;
9554
Johannes Bergff1b6e62011-05-04 15:37:28 +02009555 nla_nest_end(msg, nl_wowlan);
9556 }
9557
9558 genlmsg_end(msg, hdr);
9559 return genlmsg_reply(msg, info);
9560
9561nla_put_failure:
9562 nlmsg_free(msg);
9563 return -ENOBUFS;
9564}
9565
Johannes Berg2a0e0472013-01-23 22:57:40 +01009566static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9567 struct nlattr *attr,
9568 struct cfg80211_wowlan *trig)
9569{
9570 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9571 struct cfg80211_wowlan_tcp *cfg;
9572 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9573 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9574 u32 size;
9575 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9576 int err, port;
9577
Johannes Berg964dc9e2013-06-03 17:25:34 +02009578 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009579 return -EINVAL;
9580
9581 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9582 nla_data(attr), nla_len(attr),
9583 nl80211_wowlan_tcp_policy);
9584 if (err)
9585 return err;
9586
9587 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9588 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9589 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9590 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9591 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9592 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9593 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9594 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9595 return -EINVAL;
9596
9597 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009598 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009599 return -EINVAL;
9600
9601 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009602 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009603 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009604 return -EINVAL;
9605
9606 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009607 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009608 return -EINVAL;
9609
9610 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9611 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9612 return -EINVAL;
9613
9614 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9615 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9616
9617 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9618 tokens_size = tokln - sizeof(*tok);
9619
9620 if (!tok->len || tokens_size % tok->len)
9621 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009622 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009623 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009624 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009625 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009626 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009627 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009628 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009629 return -EINVAL;
9630 if (tok->offset + tok->len > data_size)
9631 return -EINVAL;
9632 }
9633
9634 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9635 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009636 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009637 return -EINVAL;
9638 if (seq->len == 0 || seq->len > 4)
9639 return -EINVAL;
9640 if (seq->len + seq->offset > data_size)
9641 return -EINVAL;
9642 }
9643
9644 size = sizeof(*cfg);
9645 size += data_size;
9646 size += wake_size + wake_mask_size;
9647 size += tokens_size;
9648
9649 cfg = kzalloc(size, GFP_KERNEL);
9650 if (!cfg)
9651 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009652 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9653 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009654 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9655 ETH_ALEN);
9656 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9657 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9658 else
9659 port = 0;
9660#ifdef CONFIG_INET
9661 /* allocate a socket and port for it and use it */
9662 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9663 IPPROTO_TCP, &cfg->sock, 1);
9664 if (err) {
9665 kfree(cfg);
9666 return err;
9667 }
9668 if (inet_csk_get_port(cfg->sock->sk, port)) {
9669 sock_release(cfg->sock);
9670 kfree(cfg);
9671 return -EADDRINUSE;
9672 }
9673 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9674#else
9675 if (!port) {
9676 kfree(cfg);
9677 return -EINVAL;
9678 }
9679 cfg->src_port = port;
9680#endif
9681
9682 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9683 cfg->payload_len = data_size;
9684 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9685 memcpy((void *)cfg->payload,
9686 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9687 data_size);
9688 if (seq)
9689 cfg->payload_seq = *seq;
9690 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9691 cfg->wake_len = wake_size;
9692 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9693 memcpy((void *)cfg->wake_data,
9694 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9695 wake_size);
9696 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9697 data_size + wake_size;
9698 memcpy((void *)cfg->wake_mask,
9699 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9700 wake_mask_size);
9701 if (tok) {
9702 cfg->tokens_size = tokens_size;
9703 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9704 }
9705
9706 trig->tcp = cfg;
9707
9708 return 0;
9709}
9710
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009711static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9712 const struct wiphy_wowlan_support *wowlan,
9713 struct nlattr *attr,
9714 struct cfg80211_wowlan *trig)
9715{
9716 struct nlattr **tb;
9717 int err;
9718
9719 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9720 if (!tb)
9721 return -ENOMEM;
9722
9723 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9724 err = -EOPNOTSUPP;
9725 goto out;
9726 }
9727
9728 err = nla_parse(tb, NL80211_ATTR_MAX,
9729 nla_data(attr), nla_len(attr),
9730 nl80211_policy);
9731 if (err)
9732 goto out;
9733
Johannes Bergad2b26a2014-06-12 21:39:05 +02009734 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009735 err = PTR_ERR_OR_ZERO(trig->nd_config);
9736 if (err)
9737 trig->nd_config = NULL;
9738
9739out:
9740 kfree(tb);
9741 return err;
9742}
9743
Johannes Bergff1b6e62011-05-04 15:37:28 +02009744static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9745{
9746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9747 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009748 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009749 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009750 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009751 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009752 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009753 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009754
Johannes Berg964dc9e2013-06-03 17:25:34 +02009755 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009756 return -EOPNOTSUPP;
9757
Johannes Bergae33bd82012-07-12 16:25:02 +02009758 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9759 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009760 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009761 goto set_wakeup;
9762 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009763
9764 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9765 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9766 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9767 nl80211_wowlan_policy);
9768 if (err)
9769 return err;
9770
9771 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9772 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9773 return -EINVAL;
9774 new_triggers.any = true;
9775 }
9776
9777 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9778 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9779 return -EINVAL;
9780 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009781 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009782 }
9783
9784 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9785 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9786 return -EINVAL;
9787 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009788 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009789 }
9790
Johannes Berg77dbbb12011-07-13 10:48:55 +02009791 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9792 return -EINVAL;
9793
9794 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9795 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9796 return -EINVAL;
9797 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009798 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009799 }
9800
9801 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9802 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9803 return -EINVAL;
9804 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009805 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009806 }
9807
9808 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9809 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9810 return -EINVAL;
9811 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009812 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009813 }
9814
9815 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9816 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9817 return -EINVAL;
9818 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009819 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009820 }
9821
Johannes Bergff1b6e62011-05-04 15:37:28 +02009822 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9823 struct nlattr *pat;
9824 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009825 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009826 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009827
Johannes Berg98fc4382015-03-01 09:10:13 +02009828 regular = true;
9829
Johannes Bergff1b6e62011-05-04 15:37:28 +02009830 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9831 rem)
9832 n_patterns++;
9833 if (n_patterns > wowlan->n_patterns)
9834 return -EINVAL;
9835
9836 new_triggers.patterns = kcalloc(n_patterns,
9837 sizeof(new_triggers.patterns[0]),
9838 GFP_KERNEL);
9839 if (!new_triggers.patterns)
9840 return -ENOMEM;
9841
9842 new_triggers.n_patterns = n_patterns;
9843 i = 0;
9844
9845 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9846 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009847 u8 *mask_pat;
9848
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009849 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9850 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009851 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009852 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9853 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009854 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009855 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009856 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009857 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009858 goto error;
9859 if (pat_len > wowlan->pattern_max_len ||
9860 pat_len < wowlan->pattern_min_len)
9861 goto error;
9862
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009863 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009864 pkt_offset = 0;
9865 else
9866 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009867 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009868 if (pkt_offset > wowlan->max_pkt_offset)
9869 goto error;
9870 new_triggers.patterns[i].pkt_offset = pkt_offset;
9871
Johannes Berg922bd802014-05-19 17:59:50 +02009872 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9873 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009874 err = -ENOMEM;
9875 goto error;
9876 }
Johannes Berg922bd802014-05-19 17:59:50 +02009877 new_triggers.patterns[i].mask = mask_pat;
9878 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009879 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009880 mask_pat += mask_len;
9881 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009882 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009883 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009884 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009885 pat_len);
9886 i++;
9887 }
9888 }
9889
Johannes Berg2a0e0472013-01-23 22:57:40 +01009890 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009891 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009892 err = nl80211_parse_wowlan_tcp(
9893 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9894 &new_triggers);
9895 if (err)
9896 goto error;
9897 }
9898
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009899 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009900 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009901 err = nl80211_parse_wowlan_nd(
9902 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9903 &new_triggers);
9904 if (err)
9905 goto error;
9906 }
9907
Johannes Berg98fc4382015-03-01 09:10:13 +02009908 /* The 'any' trigger means the device continues operating more or less
9909 * as in its normal operation mode and wakes up the host on most of the
9910 * normal interrupts (like packet RX, ...)
9911 * It therefore makes little sense to combine with the more constrained
9912 * wakeup trigger modes.
9913 */
9914 if (new_triggers.any && regular) {
9915 err = -EINVAL;
9916 goto error;
9917 }
9918
Johannes Bergae33bd82012-07-12 16:25:02 +02009919 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9920 if (!ntrig) {
9921 err = -ENOMEM;
9922 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009923 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009924 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009925 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009926
Johannes Bergae33bd82012-07-12 16:25:02 +02009927 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009928 if (rdev->ops->set_wakeup &&
9929 prev_enabled != !!rdev->wiphy.wowlan_config)
9930 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009931
Johannes Bergff1b6e62011-05-04 15:37:28 +02009932 return 0;
9933 error:
9934 for (i = 0; i < new_triggers.n_patterns; i++)
9935 kfree(new_triggers.patterns[i].mask);
9936 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009937 if (new_triggers.tcp && new_triggers.tcp->sock)
9938 sock_release(new_triggers.tcp->sock);
9939 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009940 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009941 return err;
9942}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009943#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009944
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009945static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9946 struct cfg80211_registered_device *rdev)
9947{
9948 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9949 int i, j, pat_len;
9950 struct cfg80211_coalesce_rules *rule;
9951
9952 if (!rdev->coalesce->n_rules)
9953 return 0;
9954
9955 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9956 if (!nl_rules)
9957 return -ENOBUFS;
9958
9959 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9960 nl_rule = nla_nest_start(msg, i + 1);
9961 if (!nl_rule)
9962 return -ENOBUFS;
9963
9964 rule = &rdev->coalesce->rules[i];
9965 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9966 rule->delay))
9967 return -ENOBUFS;
9968
9969 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9970 rule->condition))
9971 return -ENOBUFS;
9972
9973 nl_pats = nla_nest_start(msg,
9974 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9975 if (!nl_pats)
9976 return -ENOBUFS;
9977
9978 for (j = 0; j < rule->n_patterns; j++) {
9979 nl_pat = nla_nest_start(msg, j + 1);
9980 if (!nl_pat)
9981 return -ENOBUFS;
9982 pat_len = rule->patterns[j].pattern_len;
9983 if (nla_put(msg, NL80211_PKTPAT_MASK,
9984 DIV_ROUND_UP(pat_len, 8),
9985 rule->patterns[j].mask) ||
9986 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9987 rule->patterns[j].pattern) ||
9988 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9989 rule->patterns[j].pkt_offset))
9990 return -ENOBUFS;
9991 nla_nest_end(msg, nl_pat);
9992 }
9993 nla_nest_end(msg, nl_pats);
9994 nla_nest_end(msg, nl_rule);
9995 }
9996 nla_nest_end(msg, nl_rules);
9997
9998 return 0;
9999}
10000
10001static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10002{
10003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10004 struct sk_buff *msg;
10005 void *hdr;
10006
10007 if (!rdev->wiphy.coalesce)
10008 return -EOPNOTSUPP;
10009
10010 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10011 if (!msg)
10012 return -ENOMEM;
10013
10014 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10015 NL80211_CMD_GET_COALESCE);
10016 if (!hdr)
10017 goto nla_put_failure;
10018
10019 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10020 goto nla_put_failure;
10021
10022 genlmsg_end(msg, hdr);
10023 return genlmsg_reply(msg, info);
10024
10025nla_put_failure:
10026 nlmsg_free(msg);
10027 return -ENOBUFS;
10028}
10029
10030void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10031{
10032 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10033 int i, j;
10034 struct cfg80211_coalesce_rules *rule;
10035
10036 if (!coalesce)
10037 return;
10038
10039 for (i = 0; i < coalesce->n_rules; i++) {
10040 rule = &coalesce->rules[i];
10041 for (j = 0; j < rule->n_patterns; j++)
10042 kfree(rule->patterns[j].mask);
10043 kfree(rule->patterns);
10044 }
10045 kfree(coalesce->rules);
10046 kfree(coalesce);
10047 rdev->coalesce = NULL;
10048}
10049
10050static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10051 struct nlattr *rule,
10052 struct cfg80211_coalesce_rules *new_rule)
10053{
10054 int err, i;
10055 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10056 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10057 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10058 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10059
10060 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10061 nla_len(rule), nl80211_coalesce_policy);
10062 if (err)
10063 return err;
10064
10065 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10066 new_rule->delay =
10067 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10068 if (new_rule->delay > coalesce->max_delay)
10069 return -EINVAL;
10070
10071 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10072 new_rule->condition =
10073 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10074 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10075 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10076 return -EINVAL;
10077
10078 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10079 return -EINVAL;
10080
10081 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10082 rem)
10083 n_patterns++;
10084 if (n_patterns > coalesce->n_patterns)
10085 return -EINVAL;
10086
10087 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10088 GFP_KERNEL);
10089 if (!new_rule->patterns)
10090 return -ENOMEM;
10091
10092 new_rule->n_patterns = n_patterns;
10093 i = 0;
10094
10095 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10096 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010097 u8 *mask_pat;
10098
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010099 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10100 nla_len(pat), NULL);
10101 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10102 !pat_tb[NL80211_PKTPAT_PATTERN])
10103 return -EINVAL;
10104 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10105 mask_len = DIV_ROUND_UP(pat_len, 8);
10106 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10107 return -EINVAL;
10108 if (pat_len > coalesce->pattern_max_len ||
10109 pat_len < coalesce->pattern_min_len)
10110 return -EINVAL;
10111
10112 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10113 pkt_offset = 0;
10114 else
10115 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10116 if (pkt_offset > coalesce->max_pkt_offset)
10117 return -EINVAL;
10118 new_rule->patterns[i].pkt_offset = pkt_offset;
10119
Johannes Berg922bd802014-05-19 17:59:50 +020010120 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10121 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010122 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010123
10124 new_rule->patterns[i].mask = mask_pat;
10125 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10126 mask_len);
10127
10128 mask_pat += mask_len;
10129 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010130 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010131 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10132 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010133 i++;
10134 }
10135
10136 return 0;
10137}
10138
10139static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10140{
10141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10142 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10143 struct cfg80211_coalesce new_coalesce = {};
10144 struct cfg80211_coalesce *n_coalesce;
10145 int err, rem_rule, n_rules = 0, i, j;
10146 struct nlattr *rule;
10147 struct cfg80211_coalesce_rules *tmp_rule;
10148
10149 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10150 return -EOPNOTSUPP;
10151
10152 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10153 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010154 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010155 return 0;
10156 }
10157
10158 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10159 rem_rule)
10160 n_rules++;
10161 if (n_rules > coalesce->n_rules)
10162 return -EINVAL;
10163
10164 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10165 GFP_KERNEL);
10166 if (!new_coalesce.rules)
10167 return -ENOMEM;
10168
10169 new_coalesce.n_rules = n_rules;
10170 i = 0;
10171
10172 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10173 rem_rule) {
10174 err = nl80211_parse_coalesce_rule(rdev, rule,
10175 &new_coalesce.rules[i]);
10176 if (err)
10177 goto error;
10178
10179 i++;
10180 }
10181
Ilan Peera1056b12015-10-22 22:27:46 +030010182 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010183 if (err)
10184 goto error;
10185
10186 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10187 if (!n_coalesce) {
10188 err = -ENOMEM;
10189 goto error;
10190 }
10191 cfg80211_rdev_free_coalesce(rdev);
10192 rdev->coalesce = n_coalesce;
10193
10194 return 0;
10195error:
10196 for (i = 0; i < new_coalesce.n_rules; i++) {
10197 tmp_rule = &new_coalesce.rules[i];
10198 for (j = 0; j < tmp_rule->n_patterns; j++)
10199 kfree(tmp_rule->patterns[j].mask);
10200 kfree(tmp_rule->patterns);
10201 }
10202 kfree(new_coalesce.rules);
10203
10204 return err;
10205}
10206
Johannes Berge5497d72011-07-05 16:35:40 +020010207static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10208{
10209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10210 struct net_device *dev = info->user_ptr[1];
10211 struct wireless_dev *wdev = dev->ieee80211_ptr;
10212 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10213 struct cfg80211_gtk_rekey_data rekey_data;
10214 int err;
10215
10216 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10217 return -EINVAL;
10218
10219 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10220 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10221 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10222 nl80211_rekey_policy);
10223 if (err)
10224 return err;
10225
10226 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10227 return -ERANGE;
10228 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10229 return -ERANGE;
10230 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10231 return -ERANGE;
10232
Johannes Berg78f686c2014-09-10 22:28:06 +030010233 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10234 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10235 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010236
10237 wdev_lock(wdev);
10238 if (!wdev->current_bss) {
10239 err = -ENOTCONN;
10240 goto out;
10241 }
10242
10243 if (!rdev->ops->set_rekey_data) {
10244 err = -EOPNOTSUPP;
10245 goto out;
10246 }
10247
Hila Gonene35e4d22012-06-27 17:19:42 +030010248 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010249 out:
10250 wdev_unlock(wdev);
10251 return err;
10252}
10253
Johannes Berg28946da2011-11-04 11:18:12 +010010254static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10255 struct genl_info *info)
10256{
10257 struct net_device *dev = info->user_ptr[1];
10258 struct wireless_dev *wdev = dev->ieee80211_ptr;
10259
10260 if (wdev->iftype != NL80211_IFTYPE_AP &&
10261 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10262 return -EINVAL;
10263
Eric W. Biederman15e47302012-09-07 20:12:54 +000010264 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010265 return -EBUSY;
10266
Eric W. Biederman15e47302012-09-07 20:12:54 +000010267 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010268 return 0;
10269}
10270
Johannes Berg7f6cf312011-11-04 11:18:15 +010010271static int nl80211_probe_client(struct sk_buff *skb,
10272 struct genl_info *info)
10273{
10274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10275 struct net_device *dev = info->user_ptr[1];
10276 struct wireless_dev *wdev = dev->ieee80211_ptr;
10277 struct sk_buff *msg;
10278 void *hdr;
10279 const u8 *addr;
10280 u64 cookie;
10281 int err;
10282
10283 if (wdev->iftype != NL80211_IFTYPE_AP &&
10284 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10285 return -EOPNOTSUPP;
10286
10287 if (!info->attrs[NL80211_ATTR_MAC])
10288 return -EINVAL;
10289
10290 if (!rdev->ops->probe_client)
10291 return -EOPNOTSUPP;
10292
10293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10294 if (!msg)
10295 return -ENOMEM;
10296
Eric W. Biederman15e47302012-09-07 20:12:54 +000010297 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010298 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010299 if (!hdr) {
10300 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010301 goto free_msg;
10302 }
10303
10304 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10305
Hila Gonene35e4d22012-06-27 17:19:42 +030010306 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010307 if (err)
10308 goto free_msg;
10309
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010310 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10311 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010312 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010313
10314 genlmsg_end(msg, hdr);
10315
10316 return genlmsg_reply(msg, info);
10317
10318 nla_put_failure:
10319 err = -ENOBUFS;
10320 free_msg:
10321 nlmsg_free(msg);
10322 return err;
10323}
10324
Johannes Berg5e760232011-11-04 11:18:17 +010010325static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10326{
10327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010328 struct cfg80211_beacon_registration *reg, *nreg;
10329 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010330
10331 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10332 return -EOPNOTSUPP;
10333
Ben Greear37c73b52012-10-26 14:49:25 -070010334 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10335 if (!nreg)
10336 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010010337
Ben Greear37c73b52012-10-26 14:49:25 -070010338 /* First, check if already registered. */
10339 spin_lock_bh(&rdev->beacon_registrations_lock);
10340 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10341 if (reg->nlportid == info->snd_portid) {
10342 rv = -EALREADY;
10343 goto out_err;
10344 }
10345 }
10346 /* Add it to the list */
10347 nreg->nlportid = info->snd_portid;
10348 list_add(&nreg->list, &rdev->beacon_registrations);
10349
10350 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010351
10352 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010353out_err:
10354 spin_unlock_bh(&rdev->beacon_registrations_lock);
10355 kfree(nreg);
10356 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010357}
10358
Johannes Berg98104fde2012-06-16 00:19:54 +020010359static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10360{
10361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10362 struct wireless_dev *wdev = info->user_ptr[1];
10363 int err;
10364
10365 if (!rdev->ops->start_p2p_device)
10366 return -EOPNOTSUPP;
10367
10368 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10369 return -EOPNOTSUPP;
10370
10371 if (wdev->p2p_started)
10372 return 0;
10373
Luciano Coelhob6a55012014-02-27 11:07:21 +020010374 if (rfkill_blocked(rdev->rfkill))
10375 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010376
Johannes Bergeeb126e2012-10-23 15:16:50 +020010377 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010378 if (err)
10379 return err;
10380
10381 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010382 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010383
10384 return 0;
10385}
10386
10387static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10388{
10389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10390 struct wireless_dev *wdev = info->user_ptr[1];
10391
10392 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10393 return -EOPNOTSUPP;
10394
10395 if (!rdev->ops->stop_p2p_device)
10396 return -EOPNOTSUPP;
10397
Johannes Bergf9f47522013-03-19 15:04:07 +010010398 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010399
10400 return 0;
10401}
10402
Johannes Berg3713b4e2013-02-14 16:19:38 +010010403static int nl80211_get_protocol_features(struct sk_buff *skb,
10404 struct genl_info *info)
10405{
10406 void *hdr;
10407 struct sk_buff *msg;
10408
10409 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10410 if (!msg)
10411 return -ENOMEM;
10412
10413 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10414 NL80211_CMD_GET_PROTOCOL_FEATURES);
10415 if (!hdr)
10416 goto nla_put_failure;
10417
10418 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10419 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10420 goto nla_put_failure;
10421
10422 genlmsg_end(msg, hdr);
10423 return genlmsg_reply(msg, info);
10424
10425 nla_put_failure:
10426 kfree_skb(msg);
10427 return -ENOBUFS;
10428}
10429
Jouni Malinen355199e2013-02-27 17:14:27 +020010430static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10431{
10432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10433 struct cfg80211_update_ft_ies_params ft_params;
10434 struct net_device *dev = info->user_ptr[1];
10435
10436 if (!rdev->ops->update_ft_ies)
10437 return -EOPNOTSUPP;
10438
10439 if (!info->attrs[NL80211_ATTR_MDID] ||
10440 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10441 return -EINVAL;
10442
10443 memset(&ft_params, 0, sizeof(ft_params));
10444 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10445 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10446 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10447
10448 return rdev_update_ft_ies(rdev, dev, &ft_params);
10449}
10450
Arend van Spriel5de17982013-04-18 15:49:00 +020010451static int nl80211_crit_protocol_start(struct sk_buff *skb,
10452 struct genl_info *info)
10453{
10454 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10455 struct wireless_dev *wdev = info->user_ptr[1];
10456 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10457 u16 duration;
10458 int ret;
10459
10460 if (!rdev->ops->crit_proto_start)
10461 return -EOPNOTSUPP;
10462
10463 if (WARN_ON(!rdev->ops->crit_proto_stop))
10464 return -EINVAL;
10465
10466 if (rdev->crit_proto_nlportid)
10467 return -EBUSY;
10468
10469 /* determine protocol if provided */
10470 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10471 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10472
10473 if (proto >= NUM_NL80211_CRIT_PROTO)
10474 return -EINVAL;
10475
10476 /* timeout must be provided */
10477 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10478 return -EINVAL;
10479
10480 duration =
10481 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10482
10483 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10484 return -ERANGE;
10485
10486 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10487 if (!ret)
10488 rdev->crit_proto_nlportid = info->snd_portid;
10489
10490 return ret;
10491}
10492
10493static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10494 struct genl_info *info)
10495{
10496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10497 struct wireless_dev *wdev = info->user_ptr[1];
10498
10499 if (!rdev->ops->crit_proto_stop)
10500 return -EOPNOTSUPP;
10501
10502 if (rdev->crit_proto_nlportid) {
10503 rdev->crit_proto_nlportid = 0;
10504 rdev_crit_proto_stop(rdev, wdev);
10505 }
10506 return 0;
10507}
10508
Johannes Bergad7e7182013-11-13 13:37:47 +010010509static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10510{
10511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10512 struct wireless_dev *wdev =
10513 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10514 int i, err;
10515 u32 vid, subcmd;
10516
10517 if (!rdev->wiphy.vendor_commands)
10518 return -EOPNOTSUPP;
10519
10520 if (IS_ERR(wdev)) {
10521 err = PTR_ERR(wdev);
10522 if (err != -EINVAL)
10523 return err;
10524 wdev = NULL;
10525 } else if (wdev->wiphy != &rdev->wiphy) {
10526 return -EINVAL;
10527 }
10528
10529 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10530 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10531 return -EINVAL;
10532
10533 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10534 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10535 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10536 const struct wiphy_vendor_command *vcmd;
10537 void *data = NULL;
10538 int len = 0;
10539
10540 vcmd = &rdev->wiphy.vendor_commands[i];
10541
10542 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10543 continue;
10544
10545 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10546 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10547 if (!wdev)
10548 return -EINVAL;
10549 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10550 !wdev->netdev)
10551 return -EINVAL;
10552
10553 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10554 if (wdev->netdev &&
10555 !netif_running(wdev->netdev))
10556 return -ENETDOWN;
10557 if (!wdev->netdev && !wdev->p2p_started)
10558 return -ENETDOWN;
10559 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010560
10561 if (!vcmd->doit)
10562 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010563 } else {
10564 wdev = NULL;
10565 }
10566
10567 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10568 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10569 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10570 }
10571
10572 rdev->cur_cmd_info = info;
10573 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10574 data, len);
10575 rdev->cur_cmd_info = NULL;
10576 return err;
10577 }
10578
10579 return -EOPNOTSUPP;
10580}
10581
Johannes Berg7bdbe402015-08-15 22:39:49 +030010582static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10583 struct netlink_callback *cb,
10584 struct cfg80211_registered_device **rdev,
10585 struct wireless_dev **wdev)
10586{
10587 u32 vid, subcmd;
10588 unsigned int i;
10589 int vcmd_idx = -1;
10590 int err;
10591 void *data = NULL;
10592 unsigned int data_len = 0;
10593
10594 rtnl_lock();
10595
10596 if (cb->args[0]) {
10597 /* subtract the 1 again here */
10598 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10599 struct wireless_dev *tmp;
10600
10601 if (!wiphy) {
10602 err = -ENODEV;
10603 goto out_unlock;
10604 }
10605 *rdev = wiphy_to_rdev(wiphy);
10606 *wdev = NULL;
10607
10608 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010609 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010610 if (tmp->identifier == cb->args[1] - 1) {
10611 *wdev = tmp;
10612 break;
10613 }
10614 }
10615 }
10616
10617 /* keep rtnl locked in successful case */
10618 return 0;
10619 }
10620
10621 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10622 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10623 nl80211_policy);
10624 if (err)
10625 goto out_unlock;
10626
10627 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10628 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10629 err = -EINVAL;
10630 goto out_unlock;
10631 }
10632
10633 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10634 nl80211_fam.attrbuf);
10635 if (IS_ERR(*wdev))
10636 *wdev = NULL;
10637
10638 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10639 nl80211_fam.attrbuf);
10640 if (IS_ERR(*rdev)) {
10641 err = PTR_ERR(*rdev);
10642 goto out_unlock;
10643 }
10644
10645 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10646 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10647
10648 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10649 const struct wiphy_vendor_command *vcmd;
10650
10651 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10652
10653 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10654 continue;
10655
10656 if (!vcmd->dumpit) {
10657 err = -EOPNOTSUPP;
10658 goto out_unlock;
10659 }
10660
10661 vcmd_idx = i;
10662 break;
10663 }
10664
10665 if (vcmd_idx < 0) {
10666 err = -EOPNOTSUPP;
10667 goto out_unlock;
10668 }
10669
10670 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10671 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10672 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10673 }
10674
10675 /* 0 is the first index - add 1 to parse only once */
10676 cb->args[0] = (*rdev)->wiphy_idx + 1;
10677 /* add 1 to know if it was NULL */
10678 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10679 cb->args[2] = vcmd_idx;
10680 cb->args[3] = (unsigned long)data;
10681 cb->args[4] = data_len;
10682
10683 /* keep rtnl locked in successful case */
10684 return 0;
10685 out_unlock:
10686 rtnl_unlock();
10687 return err;
10688}
10689
10690static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10691 struct netlink_callback *cb)
10692{
10693 struct cfg80211_registered_device *rdev;
10694 struct wireless_dev *wdev;
10695 unsigned int vcmd_idx;
10696 const struct wiphy_vendor_command *vcmd;
10697 void *data;
10698 int data_len;
10699 int err;
10700 struct nlattr *vendor_data;
10701
10702 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10703 if (err)
10704 return err;
10705
10706 vcmd_idx = cb->args[2];
10707 data = (void *)cb->args[3];
10708 data_len = cb->args[4];
10709 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10710
10711 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10712 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10713 if (!wdev)
10714 return -EINVAL;
10715 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10716 !wdev->netdev)
10717 return -EINVAL;
10718
10719 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10720 if (wdev->netdev &&
10721 !netif_running(wdev->netdev))
10722 return -ENETDOWN;
10723 if (!wdev->netdev && !wdev->p2p_started)
10724 return -ENETDOWN;
10725 }
10726 }
10727
10728 while (1) {
10729 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10730 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10731 NL80211_CMD_VENDOR);
10732 if (!hdr)
10733 break;
10734
10735 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010736 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10737 wdev_id(wdev),
10738 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010739 genlmsg_cancel(skb, hdr);
10740 break;
10741 }
10742
10743 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10744 if (!vendor_data) {
10745 genlmsg_cancel(skb, hdr);
10746 break;
10747 }
10748
10749 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10750 (unsigned long *)&cb->args[5]);
10751 nla_nest_end(skb, vendor_data);
10752
10753 if (err == -ENOBUFS || err == -ENOENT) {
10754 genlmsg_cancel(skb, hdr);
10755 break;
10756 } else if (err) {
10757 genlmsg_cancel(skb, hdr);
10758 goto out;
10759 }
10760
10761 genlmsg_end(skb, hdr);
10762 }
10763
10764 err = skb->len;
10765 out:
10766 rtnl_unlock();
10767 return err;
10768}
10769
Johannes Bergad7e7182013-11-13 13:37:47 +010010770struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10771 enum nl80211_commands cmd,
10772 enum nl80211_attrs attr,
10773 int approxlen)
10774{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010775 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010776
10777 if (WARN_ON(!rdev->cur_cmd_info))
10778 return NULL;
10779
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010780 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010781 rdev->cur_cmd_info->snd_portid,
10782 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010783 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010784}
10785EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10786
10787int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10788{
10789 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10790 void *hdr = ((void **)skb->cb)[1];
10791 struct nlattr *data = ((void **)skb->cb)[2];
10792
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010793 /* clear CB data for netlink core to own from now on */
10794 memset(skb->cb, 0, sizeof(skb->cb));
10795
Johannes Bergad7e7182013-11-13 13:37:47 +010010796 if (WARN_ON(!rdev->cur_cmd_info)) {
10797 kfree_skb(skb);
10798 return -EINVAL;
10799 }
10800
10801 nla_nest_end(skb, data);
10802 genlmsg_end(skb, hdr);
10803 return genlmsg_reply(skb, rdev->cur_cmd_info);
10804}
10805EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10806
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010807static int nl80211_set_qos_map(struct sk_buff *skb,
10808 struct genl_info *info)
10809{
10810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10811 struct cfg80211_qos_map *qos_map = NULL;
10812 struct net_device *dev = info->user_ptr[1];
10813 u8 *pos, len, num_des, des_len, des;
10814 int ret;
10815
10816 if (!rdev->ops->set_qos_map)
10817 return -EOPNOTSUPP;
10818
10819 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10820 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10821 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10822
10823 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10824 len > IEEE80211_QOS_MAP_LEN_MAX)
10825 return -EINVAL;
10826
10827 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10828 if (!qos_map)
10829 return -ENOMEM;
10830
10831 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10832 if (num_des) {
10833 des_len = num_des *
10834 sizeof(struct cfg80211_dscp_exception);
10835 memcpy(qos_map->dscp_exception, pos, des_len);
10836 qos_map->num_des = num_des;
10837 for (des = 0; des < num_des; des++) {
10838 if (qos_map->dscp_exception[des].up > 7) {
10839 kfree(qos_map);
10840 return -EINVAL;
10841 }
10842 }
10843 pos += des_len;
10844 }
10845 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10846 }
10847
10848 wdev_lock(dev->ieee80211_ptr);
10849 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10850 if (!ret)
10851 ret = rdev_set_qos_map(rdev, dev, qos_map);
10852 wdev_unlock(dev->ieee80211_ptr);
10853
10854 kfree(qos_map);
10855 return ret;
10856}
10857
Johannes Berg960d01a2014-09-09 22:55:35 +030010858static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10859{
10860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10861 struct net_device *dev = info->user_ptr[1];
10862 struct wireless_dev *wdev = dev->ieee80211_ptr;
10863 const u8 *peer;
10864 u8 tsid, up;
10865 u16 admitted_time = 0;
10866 int err;
10867
Johannes Berg723e73a2014-10-22 09:25:06 +020010868 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010869 return -EOPNOTSUPP;
10870
10871 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10872 !info->attrs[NL80211_ATTR_USER_PRIO])
10873 return -EINVAL;
10874
10875 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10876 if (tsid >= IEEE80211_NUM_TIDS)
10877 return -EINVAL;
10878
10879 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10880 if (up >= IEEE80211_NUM_UPS)
10881 return -EINVAL;
10882
10883 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010884 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010885 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010886 * need more attributes for that (e.g. BA session requirement);
10887 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010888 */
10889 return -EINVAL;
10890 }
10891
10892 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10893
10894 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10895 admitted_time =
10896 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10897 if (!admitted_time)
10898 return -EINVAL;
10899 }
10900
10901 wdev_lock(wdev);
10902 switch (wdev->iftype) {
10903 case NL80211_IFTYPE_STATION:
10904 case NL80211_IFTYPE_P2P_CLIENT:
10905 if (wdev->current_bss)
10906 break;
10907 err = -ENOTCONN;
10908 goto out;
10909 default:
10910 err = -EOPNOTSUPP;
10911 goto out;
10912 }
10913
10914 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10915
10916 out:
10917 wdev_unlock(wdev);
10918 return err;
10919}
10920
10921static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10922{
10923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10924 struct net_device *dev = info->user_ptr[1];
10925 struct wireless_dev *wdev = dev->ieee80211_ptr;
10926 const u8 *peer;
10927 u8 tsid;
10928 int err;
10929
10930 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10931 return -EINVAL;
10932
10933 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10934 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10935
10936 wdev_lock(wdev);
10937 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10938 wdev_unlock(wdev);
10939
10940 return err;
10941}
10942
Arik Nemtsov1057d352014-11-19 12:54:26 +020010943static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10944 struct genl_info *info)
10945{
10946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10947 struct net_device *dev = info->user_ptr[1];
10948 struct wireless_dev *wdev = dev->ieee80211_ptr;
10949 struct cfg80211_chan_def chandef = {};
10950 const u8 *addr;
10951 u8 oper_class;
10952 int err;
10953
10954 if (!rdev->ops->tdls_channel_switch ||
10955 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10956 return -EOPNOTSUPP;
10957
10958 switch (dev->ieee80211_ptr->iftype) {
10959 case NL80211_IFTYPE_STATION:
10960 case NL80211_IFTYPE_P2P_CLIENT:
10961 break;
10962 default:
10963 return -EOPNOTSUPP;
10964 }
10965
10966 if (!info->attrs[NL80211_ATTR_MAC] ||
10967 !info->attrs[NL80211_ATTR_OPER_CLASS])
10968 return -EINVAL;
10969
10970 err = nl80211_parse_chandef(rdev, info, &chandef);
10971 if (err)
10972 return err;
10973
10974 /*
10975 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10976 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10977 * specification is not defined for them.
10978 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010979 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010980 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10981 chandef.width != NL80211_CHAN_WIDTH_20)
10982 return -EINVAL;
10983
10984 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010985 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10986 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010987 return -EINVAL;
10988
10989 /* don't allow switching to DFS channels */
10990 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10991 return -EINVAL;
10992
10993 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10994 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10995
10996 wdev_lock(wdev);
10997 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10998 wdev_unlock(wdev);
10999
11000 return err;
11001}
11002
11003static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
11004 struct genl_info *info)
11005{
11006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11007 struct net_device *dev = info->user_ptr[1];
11008 struct wireless_dev *wdev = dev->ieee80211_ptr;
11009 const u8 *addr;
11010
11011 if (!rdev->ops->tdls_channel_switch ||
11012 !rdev->ops->tdls_cancel_channel_switch ||
11013 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11014 return -EOPNOTSUPP;
11015
11016 switch (dev->ieee80211_ptr->iftype) {
11017 case NL80211_IFTYPE_STATION:
11018 case NL80211_IFTYPE_P2P_CLIENT:
11019 break;
11020 default:
11021 return -EOPNOTSUPP;
11022 }
11023
11024 if (!info->attrs[NL80211_ATTR_MAC])
11025 return -EINVAL;
11026
11027 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11028
11029 wdev_lock(wdev);
11030 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
11031 wdev_unlock(wdev);
11032
11033 return 0;
11034}
11035
Johannes Berg4c476992010-10-04 21:36:35 +020011036#define NL80211_FLAG_NEED_WIPHY 0x01
11037#define NL80211_FLAG_NEED_NETDEV 0x02
11038#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011039#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11040#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11041 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011042#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011043/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011044#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11045 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011046#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011047
Johannes Bergf84f7712013-11-14 17:14:45 +010011048static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011049 struct genl_info *info)
11050{
11051 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011052 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011053 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011054 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11055
11056 if (rtnl)
11057 rtnl_lock();
11058
11059 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011060 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011061 if (IS_ERR(rdev)) {
11062 if (rtnl)
11063 rtnl_unlock();
11064 return PTR_ERR(rdev);
11065 }
11066 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011067 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11068 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011069 ASSERT_RTNL();
11070
Johannes Berg89a54e42012-06-15 14:33:17 +020011071 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11072 info->attrs);
11073 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011074 if (rtnl)
11075 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011076 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011077 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011078
Johannes Berg89a54e42012-06-15 14:33:17 +020011079 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011080 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011081
Johannes Berg1bf614e2012-06-15 15:23:36 +020011082 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11083 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011084 if (rtnl)
11085 rtnl_unlock();
11086 return -EINVAL;
11087 }
11088
11089 info->user_ptr[1] = dev;
11090 } else {
11091 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011092 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011093
Johannes Berg1bf614e2012-06-15 15:23:36 +020011094 if (dev) {
11095 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11096 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011097 if (rtnl)
11098 rtnl_unlock();
11099 return -ENETDOWN;
11100 }
11101
11102 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011103 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
11104 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020011105 if (rtnl)
11106 rtnl_unlock();
11107 return -ENETDOWN;
11108 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020011109 }
11110
Johannes Berg4c476992010-10-04 21:36:35 +020011111 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011112 }
11113
11114 return 0;
11115}
11116
Johannes Bergf84f7712013-11-14 17:14:45 +010011117static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011118 struct genl_info *info)
11119{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011120 if (info->user_ptr[1]) {
11121 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11122 struct wireless_dev *wdev = info->user_ptr[1];
11123
11124 if (wdev->netdev)
11125 dev_put(wdev->netdev);
11126 } else {
11127 dev_put(info->user_ptr[1]);
11128 }
11129 }
Johannes Berg5393b912014-09-10 15:00:16 +030011130
Johannes Berg4c476992010-10-04 21:36:35 +020011131 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11132 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011133
11134 /* If needed, clear the netlink message payload from the SKB
11135 * as it might contain key data that shouldn't stick around on
11136 * the heap after the SKB is freed. The netlink message header
11137 * is still needed for further processing, so leave it intact.
11138 */
11139 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11140 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11141
11142 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11143 }
Johannes Berg4c476992010-10-04 21:36:35 +020011144}
11145
Johannes Berg4534de82013-11-14 17:14:46 +010011146static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011147 {
11148 .cmd = NL80211_CMD_GET_WIPHY,
11149 .doit = nl80211_get_wiphy,
11150 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011151 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011152 .policy = nl80211_policy,
11153 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011154 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11155 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011156 },
11157 {
11158 .cmd = NL80211_CMD_SET_WIPHY,
11159 .doit = nl80211_set_wiphy,
11160 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011161 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011162 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011163 },
11164 {
11165 .cmd = NL80211_CMD_GET_INTERFACE,
11166 .doit = nl80211_get_interface,
11167 .dumpit = nl80211_dump_interface,
11168 .policy = nl80211_policy,
11169 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011170 .internal_flags = NL80211_FLAG_NEED_WDEV |
11171 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011172 },
11173 {
11174 .cmd = NL80211_CMD_SET_INTERFACE,
11175 .doit = nl80211_set_interface,
11176 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011177 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011178 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11179 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011180 },
11181 {
11182 .cmd = NL80211_CMD_NEW_INTERFACE,
11183 .doit = nl80211_new_interface,
11184 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011185 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011186 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11187 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011188 },
11189 {
11190 .cmd = NL80211_CMD_DEL_INTERFACE,
11191 .doit = nl80211_del_interface,
11192 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011193 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011194 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011195 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011196 },
Johannes Berg41ade002007-12-19 02:03:29 +010011197 {
11198 .cmd = NL80211_CMD_GET_KEY,
11199 .doit = nl80211_get_key,
11200 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011201 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011202 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011203 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011204 },
11205 {
11206 .cmd = NL80211_CMD_SET_KEY,
11207 .doit = nl80211_set_key,
11208 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011209 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011210 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011211 NL80211_FLAG_NEED_RTNL |
11212 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011213 },
11214 {
11215 .cmd = NL80211_CMD_NEW_KEY,
11216 .doit = nl80211_new_key,
11217 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011218 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011219 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011220 NL80211_FLAG_NEED_RTNL |
11221 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011222 },
11223 {
11224 .cmd = NL80211_CMD_DEL_KEY,
11225 .doit = nl80211_del_key,
11226 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011227 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011228 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011229 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011230 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011231 {
11232 .cmd = NL80211_CMD_SET_BEACON,
11233 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011234 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011235 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011236 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011237 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011238 },
11239 {
Johannes Berg88600202012-02-13 15:17:18 +010011240 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011241 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011242 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011243 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011244 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011245 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011246 },
11247 {
Johannes Berg88600202012-02-13 15:17:18 +010011248 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011249 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011250 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011251 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011252 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011253 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011254 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011255 {
11256 .cmd = NL80211_CMD_GET_STATION,
11257 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011258 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011259 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011260 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11261 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011262 },
11263 {
11264 .cmd = NL80211_CMD_SET_STATION,
11265 .doit = nl80211_set_station,
11266 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011267 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011268 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011269 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011270 },
11271 {
11272 .cmd = NL80211_CMD_NEW_STATION,
11273 .doit = nl80211_new_station,
11274 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011275 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011276 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011277 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011278 },
11279 {
11280 .cmd = NL80211_CMD_DEL_STATION,
11281 .doit = nl80211_del_station,
11282 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011283 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011284 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011285 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011286 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011287 {
11288 .cmd = NL80211_CMD_GET_MPATH,
11289 .doit = nl80211_get_mpath,
11290 .dumpit = nl80211_dump_mpath,
11291 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011292 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011293 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011294 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011295 },
11296 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011297 .cmd = NL80211_CMD_GET_MPP,
11298 .doit = nl80211_get_mpp,
11299 .dumpit = nl80211_dump_mpp,
11300 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011301 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011302 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11303 NL80211_FLAG_NEED_RTNL,
11304 },
11305 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011306 .cmd = NL80211_CMD_SET_MPATH,
11307 .doit = nl80211_set_mpath,
11308 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011309 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011310 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011311 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011312 },
11313 {
11314 .cmd = NL80211_CMD_NEW_MPATH,
11315 .doit = nl80211_new_mpath,
11316 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011317 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011318 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011319 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011320 },
11321 {
11322 .cmd = NL80211_CMD_DEL_MPATH,
11323 .doit = nl80211_del_mpath,
11324 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011325 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011326 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011327 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011328 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011329 {
11330 .cmd = NL80211_CMD_SET_BSS,
11331 .doit = nl80211_set_bss,
11332 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011333 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011334 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011335 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011336 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011337 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011338 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011339 .doit = nl80211_get_reg_do,
11340 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011341 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011342 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011343 /* can be retrieved by unprivileged users */
11344 },
Johannes Bergb6863032015-10-15 09:25:18 +020011345#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011346 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011347 .cmd = NL80211_CMD_SET_REG,
11348 .doit = nl80211_set_reg,
11349 .policy = nl80211_policy,
11350 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011351 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011352 },
Johannes Bergb6863032015-10-15 09:25:18 +020011353#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011354 {
11355 .cmd = NL80211_CMD_REQ_SET_REG,
11356 .doit = nl80211_req_set_reg,
11357 .policy = nl80211_policy,
11358 .flags = GENL_ADMIN_PERM,
11359 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011360 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011361 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11362 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011363 .policy = nl80211_policy,
11364 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011365 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011366 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011367 },
11368 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011369 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11370 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011371 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011372 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011373 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011374 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011375 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011376 {
Johannes Berg2a519312009-02-10 21:25:55 +010011377 .cmd = NL80211_CMD_TRIGGER_SCAN,
11378 .doit = nl80211_trigger_scan,
11379 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011380 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011381 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011382 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011383 },
11384 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011385 .cmd = NL80211_CMD_ABORT_SCAN,
11386 .doit = nl80211_abort_scan,
11387 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011388 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011389 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11390 NL80211_FLAG_NEED_RTNL,
11391 },
11392 {
Johannes Berg2a519312009-02-10 21:25:55 +010011393 .cmd = NL80211_CMD_GET_SCAN,
11394 .policy = nl80211_policy,
11395 .dumpit = nl80211_dump_scan,
11396 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011397 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011398 .cmd = NL80211_CMD_START_SCHED_SCAN,
11399 .doit = nl80211_start_sched_scan,
11400 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011401 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11403 NL80211_FLAG_NEED_RTNL,
11404 },
11405 {
11406 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11407 .doit = nl80211_stop_sched_scan,
11408 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011409 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11411 NL80211_FLAG_NEED_RTNL,
11412 },
11413 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011414 .cmd = NL80211_CMD_AUTHENTICATE,
11415 .doit = nl80211_authenticate,
11416 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011417 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011418 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011419 NL80211_FLAG_NEED_RTNL |
11420 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011421 },
11422 {
11423 .cmd = NL80211_CMD_ASSOCIATE,
11424 .doit = nl80211_associate,
11425 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011426 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011428 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011429 },
11430 {
11431 .cmd = NL80211_CMD_DEAUTHENTICATE,
11432 .doit = nl80211_deauthenticate,
11433 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011434 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011436 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011437 },
11438 {
11439 .cmd = NL80211_CMD_DISASSOCIATE,
11440 .doit = nl80211_disassociate,
11441 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011442 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011444 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011445 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011446 {
11447 .cmd = NL80211_CMD_JOIN_IBSS,
11448 .doit = nl80211_join_ibss,
11449 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011450 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011452 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011453 },
11454 {
11455 .cmd = NL80211_CMD_LEAVE_IBSS,
11456 .doit = nl80211_leave_ibss,
11457 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011458 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011460 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011461 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011462#ifdef CONFIG_NL80211_TESTMODE
11463 {
11464 .cmd = NL80211_CMD_TESTMODE,
11465 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011466 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011467 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011468 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011469 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11470 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011471 },
11472#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011473 {
11474 .cmd = NL80211_CMD_CONNECT,
11475 .doit = nl80211_connect,
11476 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011477 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011478 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011479 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011480 },
11481 {
11482 .cmd = NL80211_CMD_DISCONNECT,
11483 .doit = nl80211_disconnect,
11484 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011485 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011486 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011487 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011488 },
Johannes Berg463d0182009-07-14 00:33:35 +020011489 {
11490 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11491 .doit = nl80211_wiphy_netns,
11492 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011493 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011494 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11495 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011496 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011497 {
11498 .cmd = NL80211_CMD_GET_SURVEY,
11499 .policy = nl80211_policy,
11500 .dumpit = nl80211_dump_survey,
11501 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011502 {
11503 .cmd = NL80211_CMD_SET_PMKSA,
11504 .doit = nl80211_setdel_pmksa,
11505 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011506 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011508 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011509 },
11510 {
11511 .cmd = NL80211_CMD_DEL_PMKSA,
11512 .doit = nl80211_setdel_pmksa,
11513 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011514 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011516 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011517 },
11518 {
11519 .cmd = NL80211_CMD_FLUSH_PMKSA,
11520 .doit = nl80211_flush_pmksa,
11521 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011522 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011523 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011524 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011525 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011526 {
11527 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11528 .doit = nl80211_remain_on_channel,
11529 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011530 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011531 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011532 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011533 },
11534 {
11535 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11536 .doit = nl80211_cancel_remain_on_channel,
11537 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011538 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011539 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011540 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011541 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011542 {
11543 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11544 .doit = nl80211_set_tx_bitrate_mask,
11545 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011546 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011547 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11548 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011549 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011550 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011551 .cmd = NL80211_CMD_REGISTER_FRAME,
11552 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011553 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011554 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011555 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011556 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011557 },
11558 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011559 .cmd = NL80211_CMD_FRAME,
11560 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011561 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011562 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011563 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011564 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011565 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011566 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011567 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11568 .doit = nl80211_tx_mgmt_cancel_wait,
11569 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011570 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011571 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011572 NL80211_FLAG_NEED_RTNL,
11573 },
11574 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011575 .cmd = NL80211_CMD_SET_POWER_SAVE,
11576 .doit = nl80211_set_power_save,
11577 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011578 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011579 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11580 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011581 },
11582 {
11583 .cmd = NL80211_CMD_GET_POWER_SAVE,
11584 .doit = nl80211_get_power_save,
11585 .policy = nl80211_policy,
11586 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011587 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11588 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011589 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011590 {
11591 .cmd = NL80211_CMD_SET_CQM,
11592 .doit = nl80211_set_cqm,
11593 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011594 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011595 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11596 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011597 },
Johannes Bergf444de02010-05-05 15:25:02 +020011598 {
11599 .cmd = NL80211_CMD_SET_CHANNEL,
11600 .doit = nl80211_set_channel,
11601 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011602 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011603 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11604 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011605 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011606 {
11607 .cmd = NL80211_CMD_SET_WDS_PEER,
11608 .doit = nl80211_set_wds_peer,
11609 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011610 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011611 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11612 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011613 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011614 {
11615 .cmd = NL80211_CMD_JOIN_MESH,
11616 .doit = nl80211_join_mesh,
11617 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011618 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11620 NL80211_FLAG_NEED_RTNL,
11621 },
11622 {
11623 .cmd = NL80211_CMD_LEAVE_MESH,
11624 .doit = nl80211_leave_mesh,
11625 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011626 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011627 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11628 NL80211_FLAG_NEED_RTNL,
11629 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011630 {
11631 .cmd = NL80211_CMD_JOIN_OCB,
11632 .doit = nl80211_join_ocb,
11633 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011634 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011635 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11636 NL80211_FLAG_NEED_RTNL,
11637 },
11638 {
11639 .cmd = NL80211_CMD_LEAVE_OCB,
11640 .doit = nl80211_leave_ocb,
11641 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011642 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11644 NL80211_FLAG_NEED_RTNL,
11645 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011646#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011647 {
11648 .cmd = NL80211_CMD_GET_WOWLAN,
11649 .doit = nl80211_get_wowlan,
11650 .policy = nl80211_policy,
11651 /* can be retrieved by unprivileged users */
11652 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11653 NL80211_FLAG_NEED_RTNL,
11654 },
11655 {
11656 .cmd = NL80211_CMD_SET_WOWLAN,
11657 .doit = nl80211_set_wowlan,
11658 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011659 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011660 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11661 NL80211_FLAG_NEED_RTNL,
11662 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011663#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011664 {
11665 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11666 .doit = nl80211_set_rekey_data,
11667 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011668 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011669 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011670 NL80211_FLAG_NEED_RTNL |
11671 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011672 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011673 {
11674 .cmd = NL80211_CMD_TDLS_MGMT,
11675 .doit = nl80211_tdls_mgmt,
11676 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011677 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011678 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11679 NL80211_FLAG_NEED_RTNL,
11680 },
11681 {
11682 .cmd = NL80211_CMD_TDLS_OPER,
11683 .doit = nl80211_tdls_oper,
11684 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011685 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011686 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11687 NL80211_FLAG_NEED_RTNL,
11688 },
Johannes Berg28946da2011-11-04 11:18:12 +010011689 {
11690 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11691 .doit = nl80211_register_unexpected_frame,
11692 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011693 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011694 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11695 NL80211_FLAG_NEED_RTNL,
11696 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011697 {
11698 .cmd = NL80211_CMD_PROBE_CLIENT,
11699 .doit = nl80211_probe_client,
11700 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011701 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011702 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011703 NL80211_FLAG_NEED_RTNL,
11704 },
Johannes Berg5e760232011-11-04 11:18:17 +010011705 {
11706 .cmd = NL80211_CMD_REGISTER_BEACONS,
11707 .doit = nl80211_register_beacons,
11708 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011709 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010011710 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11711 NL80211_FLAG_NEED_RTNL,
11712 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011713 {
11714 .cmd = NL80211_CMD_SET_NOACK_MAP,
11715 .doit = nl80211_set_noack_map,
11716 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011717 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011718 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11719 NL80211_FLAG_NEED_RTNL,
11720 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011721 {
11722 .cmd = NL80211_CMD_START_P2P_DEVICE,
11723 .doit = nl80211_start_p2p_device,
11724 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011725 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011726 .internal_flags = NL80211_FLAG_NEED_WDEV |
11727 NL80211_FLAG_NEED_RTNL,
11728 },
11729 {
11730 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11731 .doit = nl80211_stop_p2p_device,
11732 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011733 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011734 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11735 NL80211_FLAG_NEED_RTNL,
11736 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011737 {
11738 .cmd = NL80211_CMD_SET_MCAST_RATE,
11739 .doit = nl80211_set_mcast_rate,
11740 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011741 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011742 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11743 NL80211_FLAG_NEED_RTNL,
11744 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011745 {
11746 .cmd = NL80211_CMD_SET_MAC_ACL,
11747 .doit = nl80211_set_mac_acl,
11748 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011749 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011750 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11751 NL80211_FLAG_NEED_RTNL,
11752 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011753 {
11754 .cmd = NL80211_CMD_RADAR_DETECT,
11755 .doit = nl80211_start_radar_detection,
11756 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011757 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011758 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11759 NL80211_FLAG_NEED_RTNL,
11760 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011761 {
11762 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11763 .doit = nl80211_get_protocol_features,
11764 .policy = nl80211_policy,
11765 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011766 {
11767 .cmd = NL80211_CMD_UPDATE_FT_IES,
11768 .doit = nl80211_update_ft_ies,
11769 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011770 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11772 NL80211_FLAG_NEED_RTNL,
11773 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011774 {
11775 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11776 .doit = nl80211_crit_protocol_start,
11777 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011778 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011779 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11780 NL80211_FLAG_NEED_RTNL,
11781 },
11782 {
11783 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11784 .doit = nl80211_crit_protocol_stop,
11785 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011786 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011787 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11788 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011789 },
11790 {
11791 .cmd = NL80211_CMD_GET_COALESCE,
11792 .doit = nl80211_get_coalesce,
11793 .policy = nl80211_policy,
11794 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11795 NL80211_FLAG_NEED_RTNL,
11796 },
11797 {
11798 .cmd = NL80211_CMD_SET_COALESCE,
11799 .doit = nl80211_set_coalesce,
11800 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011801 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011802 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11803 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011804 },
11805 {
11806 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11807 .doit = nl80211_channel_switch,
11808 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011809 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11811 NL80211_FLAG_NEED_RTNL,
11812 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011813 {
11814 .cmd = NL80211_CMD_VENDOR,
11815 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011816 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011817 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011818 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011819 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11820 NL80211_FLAG_NEED_RTNL,
11821 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011822 {
11823 .cmd = NL80211_CMD_SET_QOS_MAP,
11824 .doit = nl80211_set_qos_map,
11825 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011826 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011827 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11828 NL80211_FLAG_NEED_RTNL,
11829 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011830 {
11831 .cmd = NL80211_CMD_ADD_TX_TS,
11832 .doit = nl80211_add_tx_ts,
11833 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011834 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11836 NL80211_FLAG_NEED_RTNL,
11837 },
11838 {
11839 .cmd = NL80211_CMD_DEL_TX_TS,
11840 .doit = nl80211_del_tx_ts,
11841 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011842 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11844 NL80211_FLAG_NEED_RTNL,
11845 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011846 {
11847 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11848 .doit = nl80211_tdls_channel_switch,
11849 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011850 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11852 NL80211_FLAG_NEED_RTNL,
11853 },
11854 {
11855 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11856 .doit = nl80211_tdls_cancel_channel_switch,
11857 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011858 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011859 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11860 NL80211_FLAG_NEED_RTNL,
11861 },
Johannes Berg55682962007-09-20 13:09:35 -040011862};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011863
Johannes Berg55682962007-09-20 13:09:35 -040011864/* notification functions */
11865
Johannes Berg3bb20552014-05-26 13:52:25 +020011866void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11867 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011868{
11869 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011870 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011871
Johannes Berg3bb20552014-05-26 13:52:25 +020011872 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11873 cmd != NL80211_CMD_DEL_WIPHY);
11874
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011876 if (!msg)
11877 return;
11878
Johannes Berg3bb20552014-05-26 13:52:25 +020011879 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011880 nlmsg_free(msg);
11881 return;
11882 }
11883
Johannes Berg68eb5502013-11-19 15:19:38 +010011884 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011885 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011886}
11887
Denis Kenzior896ff062016-08-03 16:58:33 -050011888void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
11889 struct wireless_dev *wdev,
11890 enum nl80211_commands cmd)
11891{
11892 struct sk_buff *msg;
11893
11894 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
11895 cmd != NL80211_CMD_DEL_INTERFACE);
11896
11897 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11898 if (!msg)
11899 return;
11900
11901 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
11902 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
11903 nlmsg_free(msg);
11904 return;
11905 }
11906
11907 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11908 NL80211_MCGRP_CONFIG, GFP_KERNEL);
11909}
11910
Johannes Berg362a4152009-05-24 16:43:15 +020011911static int nl80211_add_scan_req(struct sk_buff *msg,
11912 struct cfg80211_registered_device *rdev)
11913{
11914 struct cfg80211_scan_request *req = rdev->scan_req;
11915 struct nlattr *nest;
11916 int i;
11917
11918 if (WARN_ON(!req))
11919 return 0;
11920
11921 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11922 if (!nest)
11923 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011924 for (i = 0; i < req->n_ssids; i++) {
11925 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11926 goto nla_put_failure;
11927 }
Johannes Berg362a4152009-05-24 16:43:15 +020011928 nla_nest_end(msg, nest);
11929
11930 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11931 if (!nest)
11932 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011933 for (i = 0; i < req->n_channels; i++) {
11934 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11935 goto nla_put_failure;
11936 }
Johannes Berg362a4152009-05-24 16:43:15 +020011937 nla_nest_end(msg, nest);
11938
David S. Miller9360ffd2012-03-29 04:41:26 -040011939 if (req->ie &&
11940 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11941 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011942
Johannes Bergae917c92013-10-25 11:05:22 +020011943 if (req->flags &&
11944 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11945 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011946
Avraham Stern1d762502016-07-05 17:10:13 +030011947 if (req->info.scan_start_tsf &&
11948 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
11949 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
11950 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
11951 req->info.tsf_bssid)))
11952 goto nla_put_failure;
11953
Johannes Berg362a4152009-05-24 16:43:15 +020011954 return 0;
11955 nla_put_failure:
11956 return -ENOBUFS;
11957}
11958
Johannes Berga538e2d2009-06-16 19:56:42 +020011959static int nl80211_send_scan_msg(struct sk_buff *msg,
11960 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011961 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011962 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011963 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011964{
11965 void *hdr;
11966
Eric W. Biederman15e47302012-09-07 20:12:54 +000011967 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011968 if (!hdr)
11969 return -1;
11970
David S. Miller9360ffd2012-03-29 04:41:26 -040011971 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011972 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11973 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011974 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11975 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011976 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011977
Johannes Berg362a4152009-05-24 16:43:15 +020011978 /* ignore errors and send incomplete event anyway */
11979 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011980
Johannes Berg053c0952015-01-16 22:09:00 +010011981 genlmsg_end(msg, hdr);
11982 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011983
11984 nla_put_failure:
11985 genlmsg_cancel(msg, hdr);
11986 return -EMSGSIZE;
11987}
11988
Luciano Coelho807f8a82011-05-11 17:09:35 +030011989static int
11990nl80211_send_sched_scan_msg(struct sk_buff *msg,
11991 struct cfg80211_registered_device *rdev,
11992 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011993 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011994{
11995 void *hdr;
11996
Eric W. Biederman15e47302012-09-07 20:12:54 +000011997 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011998 if (!hdr)
11999 return -1;
12000
David S. Miller9360ffd2012-03-29 04:41:26 -040012001 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12002 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12003 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012004
Johannes Berg053c0952015-01-16 22:09:00 +010012005 genlmsg_end(msg, hdr);
12006 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012007
12008 nla_put_failure:
12009 genlmsg_cancel(msg, hdr);
12010 return -EMSGSIZE;
12011}
12012
Johannes Berga538e2d2009-06-16 19:56:42 +020012013void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012014 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020012015{
12016 struct sk_buff *msg;
12017
Thomas Graf58050fc2012-06-28 03:57:45 +000012018 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012019 if (!msg)
12020 return;
12021
Johannes Bergfd014282012-06-18 19:17:03 +020012022 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020012023 NL80211_CMD_TRIGGER_SCAN) < 0) {
12024 nlmsg_free(msg);
12025 return;
12026 }
12027
Johannes Berg68eb5502013-11-19 15:19:38 +010012028 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012029 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012030}
12031
Johannes Bergf9d15d12014-01-22 11:14:19 +020012032struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
12033 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010012034{
12035 struct sk_buff *msg;
12036
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012037 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012038 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020012039 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012040
Johannes Bergfd014282012-06-18 19:17:03 +020012041 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020012042 aborted ? NL80211_CMD_SCAN_ABORTED :
12043 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010012044 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020012045 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012046 }
12047
Johannes Bergf9d15d12014-01-22 11:14:19 +020012048 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010012049}
12050
Johannes Bergf9d15d12014-01-22 11:14:19 +020012051void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
12052 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010012053{
Johannes Berg2a519312009-02-10 21:25:55 +010012054 if (!msg)
12055 return;
12056
Johannes Berg68eb5502013-11-19 15:19:38 +010012057 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012058 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012059}
12060
Luciano Coelho807f8a82011-05-11 17:09:35 +030012061void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12062 struct net_device *netdev)
12063{
12064 struct sk_buff *msg;
12065
12066 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12067 if (!msg)
12068 return;
12069
12070 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12071 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12072 nlmsg_free(msg);
12073 return;
12074 }
12075
Johannes Berg68eb5502013-11-19 15:19:38 +010012076 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012077 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012078}
12079
12080void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12081 struct net_device *netdev, u32 cmd)
12082{
12083 struct sk_buff *msg;
12084
Thomas Graf58050fc2012-06-28 03:57:45 +000012085 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012086 if (!msg)
12087 return;
12088
12089 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12090 nlmsg_free(msg);
12091 return;
12092 }
12093
Johannes Berg68eb5502013-11-19 15:19:38 +010012094 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012095 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012096}
12097
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012098static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12099 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012100{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012101 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012102 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12103 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012104
David S. Miller9360ffd2012-03-29 04:41:26 -040012105 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12106 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12107 NL80211_REGDOM_TYPE_WORLD))
12108 goto nla_put_failure;
12109 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12110 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12111 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12112 goto nla_put_failure;
12113 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12114 request->intersect) {
12115 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12116 NL80211_REGDOM_TYPE_INTERSECTION))
12117 goto nla_put_failure;
12118 } else {
12119 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12120 NL80211_REGDOM_TYPE_COUNTRY) ||
12121 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12122 request->alpha2))
12123 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012124 }
12125
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012126 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12127 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12128
12129 if (wiphy &&
12130 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12131 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012132
12133 if (wiphy &&
12134 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12135 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12136 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012137 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012138
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012139 return true;
12140
12141nla_put_failure:
12142 return false;
12143}
12144
12145/*
12146 * This can happen on global regulatory changes or device specific settings
12147 * based on custom regulatory domains.
12148 */
12149void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12150 struct regulatory_request *request)
12151{
12152 struct sk_buff *msg;
12153 void *hdr;
12154
12155 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12156 if (!msg)
12157 return;
12158
12159 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12160 if (!hdr) {
12161 nlmsg_free(msg);
12162 return;
12163 }
12164
12165 if (nl80211_reg_change_event_fill(msg, request) == false)
12166 goto nla_put_failure;
12167
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012168 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012169
Johannes Bergbc43b282009-07-25 10:54:13 +020012170 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012171 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012172 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012173 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012174
12175 return;
12176
12177nla_put_failure:
12178 genlmsg_cancel(msg, hdr);
12179 nlmsg_free(msg);
12180}
12181
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012182static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12183 struct net_device *netdev,
12184 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012185 enum nl80211_commands cmd, gfp_t gfp,
12186 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012187{
12188 struct sk_buff *msg;
12189 void *hdr;
12190
Johannes Berge6d6e342009-07-01 21:26:47 +020012191 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012192 if (!msg)
12193 return;
12194
12195 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12196 if (!hdr) {
12197 nlmsg_free(msg);
12198 return;
12199 }
12200
David S. Miller9360ffd2012-03-29 04:41:26 -040012201 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12202 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12203 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12204 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012205
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012206 if (uapsd_queues >= 0) {
12207 struct nlattr *nla_wmm =
12208 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12209 if (!nla_wmm)
12210 goto nla_put_failure;
12211
12212 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12213 uapsd_queues))
12214 goto nla_put_failure;
12215
12216 nla_nest_end(msg, nla_wmm);
12217 }
12218
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012219 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012220
Johannes Berg68eb5502013-11-19 15:19:38 +010012221 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012222 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012223 return;
12224
12225 nla_put_failure:
12226 genlmsg_cancel(msg, hdr);
12227 nlmsg_free(msg);
12228}
12229
12230void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012231 struct net_device *netdev, const u8 *buf,
12232 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012233{
12234 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012235 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012236}
12237
12238void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12239 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012240 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012241{
Johannes Berge6d6e342009-07-01 21:26:47 +020012242 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012243 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012244}
12245
Jouni Malinen53b46b82009-03-27 20:53:56 +020012246void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012247 struct net_device *netdev, const u8 *buf,
12248 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012249{
12250 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012251 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012252}
12253
Jouni Malinen53b46b82009-03-27 20:53:56 +020012254void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12255 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012256 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012257{
12258 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012259 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012260}
12261
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012262void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12263 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012264{
Johannes Berg947add32013-02-22 22:05:20 +010012265 struct wireless_dev *wdev = dev->ieee80211_ptr;
12266 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012267 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012268 const struct ieee80211_mgmt *mgmt = (void *)buf;
12269 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012270
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012271 if (WARN_ON(len < 2))
12272 return;
12273
12274 if (ieee80211_is_deauth(mgmt->frame_control))
12275 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12276 else
12277 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12278
12279 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012280 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012281}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012282EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012283
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012284static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12285 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012286 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012287{
12288 struct sk_buff *msg;
12289 void *hdr;
12290
Johannes Berge6d6e342009-07-01 21:26:47 +020012291 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012292 if (!msg)
12293 return;
12294
12295 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12296 if (!hdr) {
12297 nlmsg_free(msg);
12298 return;
12299 }
12300
David S. Miller9360ffd2012-03-29 04:41:26 -040012301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12302 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12303 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12304 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12305 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012306
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012307 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012308
Johannes Berg68eb5502013-11-19 15:19:38 +010012309 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012310 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012311 return;
12312
12313 nla_put_failure:
12314 genlmsg_cancel(msg, hdr);
12315 nlmsg_free(msg);
12316}
12317
12318void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012319 struct net_device *netdev, const u8 *addr,
12320 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012321{
12322 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012323 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012324}
12325
12326void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012327 struct net_device *netdev, const u8 *addr,
12328 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012329{
Johannes Berge6d6e342009-07-01 21:26:47 +020012330 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12331 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012332}
12333
Samuel Ortizb23aa672009-07-01 21:26:54 +020012334void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12335 struct net_device *netdev, const u8 *bssid,
12336 const u8 *req_ie, size_t req_ie_len,
12337 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012338 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012339{
12340 struct sk_buff *msg;
12341 void *hdr;
12342
Thomas Graf58050fc2012-06-28 03:57:45 +000012343 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012344 if (!msg)
12345 return;
12346
12347 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12348 if (!hdr) {
12349 nlmsg_free(msg);
12350 return;
12351 }
12352
David S. Miller9360ffd2012-03-29 04:41:26 -040012353 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12354 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12355 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012356 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12357 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12358 status) ||
12359 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012360 (req_ie &&
12361 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12362 (resp_ie &&
12363 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12364 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012365
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012366 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012367
Johannes Berg68eb5502013-11-19 15:19:38 +010012368 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012369 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012370 return;
12371
12372 nla_put_failure:
12373 genlmsg_cancel(msg, hdr);
12374 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012375}
12376
12377void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12378 struct net_device *netdev, const u8 *bssid,
12379 const u8 *req_ie, size_t req_ie_len,
12380 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12381{
12382 struct sk_buff *msg;
12383 void *hdr;
12384
Thomas Graf58050fc2012-06-28 03:57:45 +000012385 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012386 if (!msg)
12387 return;
12388
12389 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12390 if (!hdr) {
12391 nlmsg_free(msg);
12392 return;
12393 }
12394
David S. Miller9360ffd2012-03-29 04:41:26 -040012395 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12396 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12397 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12398 (req_ie &&
12399 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12400 (resp_ie &&
12401 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12402 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012403
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012404 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012405
Johannes Berg68eb5502013-11-19 15:19:38 +010012406 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012407 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012408 return;
12409
12410 nla_put_failure:
12411 genlmsg_cancel(msg, hdr);
12412 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012413}
12414
12415void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12416 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020012417 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012418{
12419 struct sk_buff *msg;
12420 void *hdr;
12421
Thomas Graf58050fc2012-06-28 03:57:45 +000012422 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012423 if (!msg)
12424 return;
12425
12426 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12427 if (!hdr) {
12428 nlmsg_free(msg);
12429 return;
12430 }
12431
David S. Miller9360ffd2012-03-29 04:41:26 -040012432 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12433 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12434 (from_ap && reason &&
12435 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12436 (from_ap &&
12437 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12438 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12439 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012440
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012441 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012442
Johannes Berg68eb5502013-11-19 15:19:38 +010012443 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012444 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012445 return;
12446
12447 nla_put_failure:
12448 genlmsg_cancel(msg, hdr);
12449 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012450}
12451
Johannes Berg04a773a2009-04-19 21:24:32 +020012452void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12453 struct net_device *netdev, const u8 *bssid,
12454 gfp_t gfp)
12455{
12456 struct sk_buff *msg;
12457 void *hdr;
12458
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012459 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012460 if (!msg)
12461 return;
12462
12463 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12464 if (!hdr) {
12465 nlmsg_free(msg);
12466 return;
12467 }
12468
David S. Miller9360ffd2012-03-29 04:41:26 -040012469 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12470 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12471 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12472 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012473
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012474 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012475
Johannes Berg68eb5502013-11-19 15:19:38 +010012476 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012477 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012478 return;
12479
12480 nla_put_failure:
12481 genlmsg_cancel(msg, hdr);
12482 nlmsg_free(msg);
12483}
12484
Johannes Berg947add32013-02-22 22:05:20 +010012485void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12486 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012487{
Johannes Berg947add32013-02-22 22:05:20 +010012488 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012489 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012490 struct sk_buff *msg;
12491 void *hdr;
12492
Johannes Berg947add32013-02-22 22:05:20 +010012493 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12494 return;
12495
12496 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12497
Javier Cardonac93b5e72011-04-07 15:08:34 -070012498 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12499 if (!msg)
12500 return;
12501
12502 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12503 if (!hdr) {
12504 nlmsg_free(msg);
12505 return;
12506 }
12507
David S. Miller9360ffd2012-03-29 04:41:26 -040012508 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012509 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12510 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012511 (ie_len && ie &&
12512 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12513 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012514
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012515 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012516
Johannes Berg68eb5502013-11-19 15:19:38 +010012517 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012518 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012519 return;
12520
12521 nla_put_failure:
12522 genlmsg_cancel(msg, hdr);
12523 nlmsg_free(msg);
12524}
Johannes Berg947add32013-02-22 22:05:20 +010012525EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012526
Jouni Malinena3b8b052009-03-27 21:59:49 +020012527void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12528 struct net_device *netdev, const u8 *addr,
12529 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012530 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012531{
12532 struct sk_buff *msg;
12533 void *hdr;
12534
Johannes Berge6d6e342009-07-01 21:26:47 +020012535 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012536 if (!msg)
12537 return;
12538
12539 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12540 if (!hdr) {
12541 nlmsg_free(msg);
12542 return;
12543 }
12544
David S. Miller9360ffd2012-03-29 04:41:26 -040012545 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12546 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12547 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12548 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12549 (key_id != -1 &&
12550 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12551 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12552 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012553
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012554 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012555
Johannes Berg68eb5502013-11-19 15:19:38 +010012556 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012557 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012558 return;
12559
12560 nla_put_failure:
12561 genlmsg_cancel(msg, hdr);
12562 nlmsg_free(msg);
12563}
12564
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012565void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12566 struct ieee80211_channel *channel_before,
12567 struct ieee80211_channel *channel_after)
12568{
12569 struct sk_buff *msg;
12570 void *hdr;
12571 struct nlattr *nl_freq;
12572
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012573 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012574 if (!msg)
12575 return;
12576
12577 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12578 if (!hdr) {
12579 nlmsg_free(msg);
12580 return;
12581 }
12582
12583 /*
12584 * Since we are applying the beacon hint to a wiphy we know its
12585 * wiphy_idx is valid
12586 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012587 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12588 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012589
12590 /* Before */
12591 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12592 if (!nl_freq)
12593 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012594 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012595 goto nla_put_failure;
12596 nla_nest_end(msg, nl_freq);
12597
12598 /* After */
12599 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12600 if (!nl_freq)
12601 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012602 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012603 goto nla_put_failure;
12604 nla_nest_end(msg, nl_freq);
12605
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012606 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012607
Johannes Berg463d0182009-07-14 00:33:35 +020012608 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012609 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012610 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012611 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012612
12613 return;
12614
12615nla_put_failure:
12616 genlmsg_cancel(msg, hdr);
12617 nlmsg_free(msg);
12618}
12619
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012620static void nl80211_send_remain_on_chan_event(
12621 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012622 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012623 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012624 unsigned int duration, gfp_t gfp)
12625{
12626 struct sk_buff *msg;
12627 void *hdr;
12628
12629 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12630 if (!msg)
12631 return;
12632
12633 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12634 if (!hdr) {
12635 nlmsg_free(msg);
12636 return;
12637 }
12638
David S. Miller9360ffd2012-03-29 04:41:26 -040012639 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012640 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12641 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012642 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12643 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012644 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012645 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12646 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012647 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12648 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012649 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012650
David S. Miller9360ffd2012-03-29 04:41:26 -040012651 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12652 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12653 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012654
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012655 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012656
Johannes Berg68eb5502013-11-19 15:19:38 +010012657 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012658 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012659 return;
12660
12661 nla_put_failure:
12662 genlmsg_cancel(msg, hdr);
12663 nlmsg_free(msg);
12664}
12665
Johannes Berg947add32013-02-22 22:05:20 +010012666void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12667 struct ieee80211_channel *chan,
12668 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012669{
Johannes Berg947add32013-02-22 22:05:20 +010012670 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012671 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012672
12673 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012674 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012675 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012676 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012677}
Johannes Berg947add32013-02-22 22:05:20 +010012678EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012679
Johannes Berg947add32013-02-22 22:05:20 +010012680void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12681 struct ieee80211_channel *chan,
12682 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012683{
Johannes Berg947add32013-02-22 22:05:20 +010012684 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012685 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012686
12687 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012688 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012689 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012690}
Johannes Berg947add32013-02-22 22:05:20 +010012691EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012692
Johannes Berg947add32013-02-22 22:05:20 +010012693void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12694 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012695{
Johannes Berg947add32013-02-22 22:05:20 +010012696 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012697 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012698 struct sk_buff *msg;
12699
Johannes Berg947add32013-02-22 22:05:20 +010012700 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12701
Thomas Graf58050fc2012-06-28 03:57:45 +000012702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012703 if (!msg)
12704 return;
12705
Johannes Bergcf5ead82014-11-14 17:14:00 +010012706 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012707 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012708 nlmsg_free(msg);
12709 return;
12710 }
12711
Johannes Berg68eb5502013-11-19 15:19:38 +010012712 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012713 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012714}
Johannes Berg947add32013-02-22 22:05:20 +010012715EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012716
Johannes Bergcf5ead82014-11-14 17:14:00 +010012717void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12718 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012719{
Johannes Berg947add32013-02-22 22:05:20 +010012720 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012721 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012722 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012723 struct station_info empty_sinfo = {};
12724
12725 if (!sinfo)
12726 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012727
Johannes Berg947add32013-02-22 22:05:20 +010012728 trace_cfg80211_del_sta(dev, mac_addr);
12729
Thomas Graf58050fc2012-06-28 03:57:45 +000012730 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012731 if (!msg)
12732 return;
12733
Johannes Bergcf5ead82014-11-14 17:14:00 +010012734 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012735 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012736 nlmsg_free(msg);
12737 return;
12738 }
12739
Johannes Berg68eb5502013-11-19 15:19:38 +010012740 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012741 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012742}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012743EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012744
Johannes Berg947add32013-02-22 22:05:20 +010012745void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12746 enum nl80211_connect_failed_reason reason,
12747 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012748{
Johannes Berg947add32013-02-22 22:05:20 +010012749 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012750 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012751 struct sk_buff *msg;
12752 void *hdr;
12753
12754 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12755 if (!msg)
12756 return;
12757
12758 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12759 if (!hdr) {
12760 nlmsg_free(msg);
12761 return;
12762 }
12763
12764 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12765 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12766 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12767 goto nla_put_failure;
12768
12769 genlmsg_end(msg, hdr);
12770
Johannes Berg68eb5502013-11-19 15:19:38 +010012771 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012772 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012773 return;
12774
12775 nla_put_failure:
12776 genlmsg_cancel(msg, hdr);
12777 nlmsg_free(msg);
12778}
Johannes Berg947add32013-02-22 22:05:20 +010012779EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012780
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012781static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12782 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012783{
12784 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012785 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012786 struct sk_buff *msg;
12787 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012788 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012789
Eric W. Biederman15e47302012-09-07 20:12:54 +000012790 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012791 return false;
12792
12793 msg = nlmsg_new(100, gfp);
12794 if (!msg)
12795 return true;
12796
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012797 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012798 if (!hdr) {
12799 nlmsg_free(msg);
12800 return true;
12801 }
12802
David S. Miller9360ffd2012-03-29 04:41:26 -040012803 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12804 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12805 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12806 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012807
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012808 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012809 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012810 return true;
12811
12812 nla_put_failure:
12813 genlmsg_cancel(msg, hdr);
12814 nlmsg_free(msg);
12815 return true;
12816}
12817
Johannes Berg947add32013-02-22 22:05:20 +010012818bool cfg80211_rx_spurious_frame(struct net_device *dev,
12819 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012820{
Johannes Berg947add32013-02-22 22:05:20 +010012821 struct wireless_dev *wdev = dev->ieee80211_ptr;
12822 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012823
Johannes Berg947add32013-02-22 22:05:20 +010012824 trace_cfg80211_rx_spurious_frame(dev, addr);
12825
12826 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12827 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12828 trace_cfg80211_return_bool(false);
12829 return false;
12830 }
12831 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12832 addr, gfp);
12833 trace_cfg80211_return_bool(ret);
12834 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012835}
Johannes Berg947add32013-02-22 22:05:20 +010012836EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12837
12838bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12839 const u8 *addr, gfp_t gfp)
12840{
12841 struct wireless_dev *wdev = dev->ieee80211_ptr;
12842 bool ret;
12843
12844 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12845
12846 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12847 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12848 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12849 trace_cfg80211_return_bool(false);
12850 return false;
12851 }
12852 ret = __nl80211_unexpected_frame(dev,
12853 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12854 addr, gfp);
12855 trace_cfg80211_return_bool(ret);
12856 return ret;
12857}
12858EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012859
Johannes Berg2e161f72010-08-12 15:38:38 +020012860int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012861 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012862 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012863 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012864{
Johannes Berg71bbc992012-06-15 15:30:18 +020012865 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012866 struct sk_buff *msg;
12867 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012868
12869 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12870 if (!msg)
12871 return -ENOMEM;
12872
Johannes Berg2e161f72010-08-12 15:38:38 +020012873 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012874 if (!hdr) {
12875 nlmsg_free(msg);
12876 return -ENOMEM;
12877 }
12878
David S. Miller9360ffd2012-03-29 04:41:26 -040012879 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012880 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12881 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012882 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12883 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012884 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12885 (sig_dbm &&
12886 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012887 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12888 (flags &&
12889 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012890 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012891
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012892 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012893
Eric W. Biederman15e47302012-09-07 20:12:54 +000012894 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012895
12896 nla_put_failure:
12897 genlmsg_cancel(msg, hdr);
12898 nlmsg_free(msg);
12899 return -ENOBUFS;
12900}
12901
Johannes Berg947add32013-02-22 22:05:20 +010012902void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12903 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012904{
Johannes Berg947add32013-02-22 22:05:20 +010012905 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012906 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012907 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012908 struct sk_buff *msg;
12909 void *hdr;
12910
Johannes Berg947add32013-02-22 22:05:20 +010012911 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12912
Jouni Malinen026331c2010-02-15 12:53:10 +020012913 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12914 if (!msg)
12915 return;
12916
Johannes Berg2e161f72010-08-12 15:38:38 +020012917 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012918 if (!hdr) {
12919 nlmsg_free(msg);
12920 return;
12921 }
12922
David S. Miller9360ffd2012-03-29 04:41:26 -040012923 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012924 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12925 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012926 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12927 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012928 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012929 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12930 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012931 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12932 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012933
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012934 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012935
Johannes Berg68eb5502013-11-19 15:19:38 +010012936 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012937 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012938 return;
12939
12940 nla_put_failure:
12941 genlmsg_cancel(msg, hdr);
12942 nlmsg_free(msg);
12943}
Johannes Berg947add32013-02-22 22:05:20 +010012944EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012945
Johannes Berg5b97f492014-11-26 12:37:43 +010012946static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12947 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012948{
Johannes Berg947add32013-02-22 22:05:20 +010012949 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012950 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12951 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12952 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012953
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012954 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012955 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012956
Johannes Berg5b97f492014-11-26 12:37:43 +010012957 cb = (void **)msg->cb;
12958
12959 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12960 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012961 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012962 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012963 }
12964
David S. Miller9360ffd2012-03-29 04:41:26 -040012965 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012966 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012967 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012968
Johannes Berg5b97f492014-11-26 12:37:43 +010012969 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012970 goto nla_put_failure;
12971
Johannes Berg5b97f492014-11-26 12:37:43 +010012972 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12973 if (!cb[1])
12974 goto nla_put_failure;
12975
12976 cb[2] = rdev;
12977
12978 return msg;
12979 nla_put_failure:
12980 nlmsg_free(msg);
12981 return NULL;
12982}
12983
12984static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12985{
12986 void **cb = (void **)msg->cb;
12987 struct cfg80211_registered_device *rdev = cb[2];
12988
12989 nla_nest_end(msg, cb[1]);
12990 genlmsg_end(msg, cb[0]);
12991
12992 memset(msg->cb, 0, sizeof(msg->cb));
12993
12994 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12995 NL80211_MCGRP_MLME, gfp);
12996}
12997
12998void cfg80211_cqm_rssi_notify(struct net_device *dev,
12999 enum nl80211_cqm_rssi_threshold_event rssi_event,
13000 gfp_t gfp)
13001{
13002 struct sk_buff *msg;
13003
13004 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
13005
Johannes Berg98f03342014-11-26 12:42:02 +010013006 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
13007 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
13008 return;
13009
Johannes Berg5b97f492014-11-26 12:37:43 +010013010 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13011 if (!msg)
13012 return;
13013
David S. Miller9360ffd2012-03-29 04:41:26 -040013014 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
13015 rssi_event))
13016 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013017
Johannes Berg5b97f492014-11-26 12:37:43 +010013018 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013019
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013020 return;
13021
13022 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013023 nlmsg_free(msg);
13024}
Johannes Berg947add32013-02-22 22:05:20 +010013025EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013026
Johannes Berg5b97f492014-11-26 12:37:43 +010013027void cfg80211_cqm_txe_notify(struct net_device *dev,
13028 const u8 *peer, u32 num_packets,
13029 u32 rate, u32 intvl, gfp_t gfp)
13030{
13031 struct sk_buff *msg;
13032
13033 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13034 if (!msg)
13035 return;
13036
13037 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
13038 goto nla_put_failure;
13039
13040 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
13041 goto nla_put_failure;
13042
13043 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
13044 goto nla_put_failure;
13045
13046 cfg80211_send_cqm(msg, gfp);
13047 return;
13048
13049 nla_put_failure:
13050 nlmsg_free(msg);
13051}
13052EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
13053
13054void cfg80211_cqm_pktloss_notify(struct net_device *dev,
13055 const u8 *peer, u32 num_packets, gfp_t gfp)
13056{
13057 struct sk_buff *msg;
13058
13059 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
13060
13061 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13062 if (!msg)
13063 return;
13064
13065 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13066 goto nla_put_failure;
13067
13068 cfg80211_send_cqm(msg, gfp);
13069 return;
13070
13071 nla_put_failure:
13072 nlmsg_free(msg);
13073}
13074EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13075
Johannes Berg98f03342014-11-26 12:42:02 +010013076void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13077{
13078 struct sk_buff *msg;
13079
13080 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13081 if (!msg)
13082 return;
13083
13084 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13085 goto nla_put_failure;
13086
13087 cfg80211_send_cqm(msg, gfp);
13088 return;
13089
13090 nla_put_failure:
13091 nlmsg_free(msg);
13092}
13093EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13094
Johannes Berg947add32013-02-22 22:05:20 +010013095static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13096 struct net_device *netdev, const u8 *bssid,
13097 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013098{
13099 struct sk_buff *msg;
13100 struct nlattr *rekey_attr;
13101 void *hdr;
13102
Thomas Graf58050fc2012-06-28 03:57:45 +000013103 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013104 if (!msg)
13105 return;
13106
13107 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13108 if (!hdr) {
13109 nlmsg_free(msg);
13110 return;
13111 }
13112
David S. Miller9360ffd2012-03-29 04:41:26 -040013113 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13114 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13115 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13116 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013117
13118 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13119 if (!rekey_attr)
13120 goto nla_put_failure;
13121
David S. Miller9360ffd2012-03-29 04:41:26 -040013122 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13123 NL80211_REPLAY_CTR_LEN, replay_ctr))
13124 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013125
13126 nla_nest_end(msg, rekey_attr);
13127
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013128 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013129
Johannes Berg68eb5502013-11-19 15:19:38 +010013130 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013131 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013132 return;
13133
13134 nla_put_failure:
13135 genlmsg_cancel(msg, hdr);
13136 nlmsg_free(msg);
13137}
13138
Johannes Berg947add32013-02-22 22:05:20 +010013139void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13140 const u8 *replay_ctr, gfp_t gfp)
13141{
13142 struct wireless_dev *wdev = dev->ieee80211_ptr;
13143 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013144 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013145
13146 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13147 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13148}
13149EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13150
13151static void
13152nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13153 struct net_device *netdev, int index,
13154 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013155{
13156 struct sk_buff *msg;
13157 struct nlattr *attr;
13158 void *hdr;
13159
Thomas Graf58050fc2012-06-28 03:57:45 +000013160 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013161 if (!msg)
13162 return;
13163
13164 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13165 if (!hdr) {
13166 nlmsg_free(msg);
13167 return;
13168 }
13169
David S. Miller9360ffd2012-03-29 04:41:26 -040013170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13171 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13172 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013173
13174 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13175 if (!attr)
13176 goto nla_put_failure;
13177
David S. Miller9360ffd2012-03-29 04:41:26 -040013178 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13179 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13180 (preauth &&
13181 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13182 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013183
13184 nla_nest_end(msg, attr);
13185
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013186 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013187
Johannes Berg68eb5502013-11-19 15:19:38 +010013188 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013189 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013190 return;
13191
13192 nla_put_failure:
13193 genlmsg_cancel(msg, hdr);
13194 nlmsg_free(msg);
13195}
13196
Johannes Berg947add32013-02-22 22:05:20 +010013197void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13198 const u8 *bssid, bool preauth, gfp_t gfp)
13199{
13200 struct wireless_dev *wdev = dev->ieee80211_ptr;
13201 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013202 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013203
13204 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13205 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13206}
13207EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13208
13209static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13210 struct net_device *netdev,
13211 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013212 gfp_t gfp,
13213 enum nl80211_commands notif,
13214 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013215{
13216 struct sk_buff *msg;
13217 void *hdr;
13218
Thomas Graf58050fc2012-06-28 03:57:45 +000013219 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013220 if (!msg)
13221 return;
13222
Luciano Coelhof8d75522014-11-07 14:31:35 +020013223 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013224 if (!hdr) {
13225 nlmsg_free(msg);
13226 return;
13227 }
13228
Johannes Berg683b6d32012-11-08 21:25:48 +010013229 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13230 goto nla_put_failure;
13231
13232 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013233 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013234
Luciano Coelhof8d75522014-11-07 14:31:35 +020013235 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13236 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13237 goto nla_put_failure;
13238
Thomas Pedersen53145262012-04-06 13:35:47 -070013239 genlmsg_end(msg, hdr);
13240
Johannes Berg68eb5502013-11-19 15:19:38 +010013241 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013242 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013243 return;
13244
13245 nla_put_failure:
13246 genlmsg_cancel(msg, hdr);
13247 nlmsg_free(msg);
13248}
13249
Johannes Berg947add32013-02-22 22:05:20 +010013250void cfg80211_ch_switch_notify(struct net_device *dev,
13251 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013252{
Johannes Berg947add32013-02-22 22:05:20 +010013253 struct wireless_dev *wdev = dev->ieee80211_ptr;
13254 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013255 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013256
Simon Wunderliche487eae2013-11-21 18:19:51 +010013257 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013258
Simon Wunderliche487eae2013-11-21 18:19:51 +010013259 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013260
Michal Kazior9e0e2962014-01-29 14:22:27 +010013261 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013262 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013263 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13264 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013265}
13266EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13267
Luciano Coelhof8d75522014-11-07 14:31:35 +020013268void cfg80211_ch_switch_started_notify(struct net_device *dev,
13269 struct cfg80211_chan_def *chandef,
13270 u8 count)
13271{
13272 struct wireless_dev *wdev = dev->ieee80211_ptr;
13273 struct wiphy *wiphy = wdev->wiphy;
13274 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13275
13276 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13277
13278 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13279 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13280}
13281EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13282
Thomas Pedersen84f10702012-07-12 16:17:33 -070013283void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013284nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013285 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013286 enum nl80211_radar_event event,
13287 struct net_device *netdev, gfp_t gfp)
13288{
13289 struct sk_buff *msg;
13290 void *hdr;
13291
13292 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13293 if (!msg)
13294 return;
13295
13296 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13297 if (!hdr) {
13298 nlmsg_free(msg);
13299 return;
13300 }
13301
13302 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13303 goto nla_put_failure;
13304
13305 /* NOP and radar events don't need a netdev parameter */
13306 if (netdev) {
13307 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13308
13309 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013310 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13311 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013312 goto nla_put_failure;
13313 }
13314
13315 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13316 goto nla_put_failure;
13317
13318 if (nl80211_send_chandef(msg, chandef))
13319 goto nla_put_failure;
13320
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013321 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013322
Johannes Berg68eb5502013-11-19 15:19:38 +010013323 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013324 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013325 return;
13326
13327 nla_put_failure:
13328 genlmsg_cancel(msg, hdr);
13329 nlmsg_free(msg);
13330}
13331
Johannes Berg7f6cf312011-11-04 11:18:15 +010013332void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13333 u64 cookie, bool acked, gfp_t gfp)
13334{
13335 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013336 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013337 struct sk_buff *msg;
13338 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013339
Beni Lev4ee3e062012-08-27 12:49:39 +030013340 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13341
Thomas Graf58050fc2012-06-28 03:57:45 +000013342 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013343
Johannes Berg7f6cf312011-11-04 11:18:15 +010013344 if (!msg)
13345 return;
13346
13347 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13348 if (!hdr) {
13349 nlmsg_free(msg);
13350 return;
13351 }
13352
David S. Miller9360ffd2012-03-29 04:41:26 -040013353 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13354 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13355 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013356 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13357 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013358 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13359 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013360
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013361 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013362
Johannes Berg68eb5502013-11-19 15:19:38 +010013363 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013364 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013365 return;
13366
13367 nla_put_failure:
13368 genlmsg_cancel(msg, hdr);
13369 nlmsg_free(msg);
13370}
13371EXPORT_SYMBOL(cfg80211_probe_status);
13372
Johannes Berg5e760232011-11-04 11:18:17 +010013373void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13374 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013375 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010013376{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013377 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010013378 struct sk_buff *msg;
13379 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013380 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010013381
Beni Lev4ee3e062012-08-27 12:49:39 +030013382 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13383
Ben Greear37c73b52012-10-26 14:49:25 -070013384 spin_lock_bh(&rdev->beacon_registrations_lock);
13385 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13386 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13387 if (!msg) {
13388 spin_unlock_bh(&rdev->beacon_registrations_lock);
13389 return;
13390 }
Johannes Berg5e760232011-11-04 11:18:17 +010013391
Ben Greear37c73b52012-10-26 14:49:25 -070013392 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13393 if (!hdr)
13394 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010013395
Ben Greear37c73b52012-10-26 14:49:25 -070013396 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13397 (freq &&
13398 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13399 (sig_dbm &&
13400 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13401 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13402 goto nla_put_failure;
13403
13404 genlmsg_end(msg, hdr);
13405
13406 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010013407 }
Ben Greear37c73b52012-10-26 14:49:25 -070013408 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010013409 return;
13410
13411 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013412 spin_unlock_bh(&rdev->beacon_registrations_lock);
13413 if (hdr)
13414 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010013415 nlmsg_free(msg);
13416}
13417EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13418
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013419#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013420static int cfg80211_net_detect_results(struct sk_buff *msg,
13421 struct cfg80211_wowlan_wakeup *wakeup)
13422{
13423 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13424 struct nlattr *nl_results, *nl_match, *nl_freqs;
13425 int i, j;
13426
13427 nl_results = nla_nest_start(
13428 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13429 if (!nl_results)
13430 return -EMSGSIZE;
13431
13432 for (i = 0; i < nd->n_matches; i++) {
13433 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13434
13435 nl_match = nla_nest_start(msg, i);
13436 if (!nl_match)
13437 break;
13438
13439 /* The SSID attribute is optional in nl80211, but for
13440 * simplicity reasons it's always present in the
13441 * cfg80211 structure. If a driver can't pass the
13442 * SSID, that needs to be changed. A zero length SSID
13443 * is still a valid SSID (wildcard), so it cannot be
13444 * used for this purpose.
13445 */
13446 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13447 match->ssid.ssid)) {
13448 nla_nest_cancel(msg, nl_match);
13449 goto out;
13450 }
13451
13452 if (match->n_channels) {
13453 nl_freqs = nla_nest_start(
13454 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13455 if (!nl_freqs) {
13456 nla_nest_cancel(msg, nl_match);
13457 goto out;
13458 }
13459
13460 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013461 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013462 nla_nest_cancel(msg, nl_freqs);
13463 nla_nest_cancel(msg, nl_match);
13464 goto out;
13465 }
13466 }
13467
13468 nla_nest_end(msg, nl_freqs);
13469 }
13470
13471 nla_nest_end(msg, nl_match);
13472 }
13473
13474out:
13475 nla_nest_end(msg, nl_results);
13476 return 0;
13477}
13478
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013479void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13480 struct cfg80211_wowlan_wakeup *wakeup,
13481 gfp_t gfp)
13482{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013483 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013484 struct sk_buff *msg;
13485 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013486 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013487
13488 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13489
13490 if (wakeup)
13491 size += wakeup->packet_present_len;
13492
13493 msg = nlmsg_new(size, gfp);
13494 if (!msg)
13495 return;
13496
13497 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13498 if (!hdr)
13499 goto free_msg;
13500
13501 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013502 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13503 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013504 goto free_msg;
13505
13506 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13507 wdev->netdev->ifindex))
13508 goto free_msg;
13509
13510 if (wakeup) {
13511 struct nlattr *reasons;
13512
13513 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013514 if (!reasons)
13515 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013516
13517 if (wakeup->disconnect &&
13518 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13519 goto free_msg;
13520 if (wakeup->magic_pkt &&
13521 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13522 goto free_msg;
13523 if (wakeup->gtk_rekey_failure &&
13524 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13525 goto free_msg;
13526 if (wakeup->eap_identity_req &&
13527 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13528 goto free_msg;
13529 if (wakeup->four_way_handshake &&
13530 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13531 goto free_msg;
13532 if (wakeup->rfkill_release &&
13533 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13534 goto free_msg;
13535
13536 if (wakeup->pattern_idx >= 0 &&
13537 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13538 wakeup->pattern_idx))
13539 goto free_msg;
13540
Johannes Bergae917c92013-10-25 11:05:22 +020013541 if (wakeup->tcp_match &&
13542 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13543 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013544
Johannes Bergae917c92013-10-25 11:05:22 +020013545 if (wakeup->tcp_connlost &&
13546 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13547 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013548
Johannes Bergae917c92013-10-25 11:05:22 +020013549 if (wakeup->tcp_nomoretokens &&
13550 nla_put_flag(msg,
13551 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13552 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013553
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013554 if (wakeup->packet) {
13555 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13556 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13557
13558 if (!wakeup->packet_80211) {
13559 pkt_attr =
13560 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13561 len_attr =
13562 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13563 }
13564
13565 if (wakeup->packet_len &&
13566 nla_put_u32(msg, len_attr, wakeup->packet_len))
13567 goto free_msg;
13568
13569 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13570 wakeup->packet))
13571 goto free_msg;
13572 }
13573
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013574 if (wakeup->net_detect &&
13575 cfg80211_net_detect_results(msg, wakeup))
13576 goto free_msg;
13577
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013578 nla_nest_end(msg, reasons);
13579 }
13580
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013581 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013582
Johannes Berg68eb5502013-11-19 15:19:38 +010013583 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013584 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013585 return;
13586
13587 free_msg:
13588 nlmsg_free(msg);
13589}
13590EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13591#endif
13592
Jouni Malinen3475b092012-11-16 22:49:57 +020013593void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13594 enum nl80211_tdls_operation oper,
13595 u16 reason_code, gfp_t gfp)
13596{
13597 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013598 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013599 struct sk_buff *msg;
13600 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013601
13602 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13603 reason_code);
13604
13605 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13606 if (!msg)
13607 return;
13608
13609 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13610 if (!hdr) {
13611 nlmsg_free(msg);
13612 return;
13613 }
13614
13615 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13616 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13617 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13618 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13619 (reason_code > 0 &&
13620 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13621 goto nla_put_failure;
13622
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013623 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013624
Johannes Berg68eb5502013-11-19 15:19:38 +010013625 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013626 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013627 return;
13628
13629 nla_put_failure:
13630 genlmsg_cancel(msg, hdr);
13631 nlmsg_free(msg);
13632}
13633EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13634
Jouni Malinen026331c2010-02-15 12:53:10 +020013635static int nl80211_netlink_notify(struct notifier_block * nb,
13636 unsigned long state,
13637 void *_notify)
13638{
13639 struct netlink_notify *notify = _notify;
13640 struct cfg80211_registered_device *rdev;
13641 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013642 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013643
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013644 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013645 return NOTIFY_DONE;
13646
13647 rcu_read_lock();
13648
Johannes Berg5e760232011-11-04 11:18:17 +010013649 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013650 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013651 bool schedule_scan_stop = false;
13652 struct cfg80211_sched_scan_request *sched_scan_req =
13653 rcu_dereference(rdev->sched_scan_req);
13654
13655 if (sched_scan_req && notify->portid &&
13656 sched_scan_req->owner_nlportid == notify->portid)
13657 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013658
Johannes Berg53873f12016-05-03 16:52:04 +030013659 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013660 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013661
Johannes Berg78f22b62014-03-24 17:57:27 +010013662 if (wdev->owner_nlportid == notify->portid)
13663 schedule_destroy_work = true;
13664 }
13665
Ben Greear37c73b52012-10-26 14:49:25 -070013666 spin_lock_bh(&rdev->beacon_registrations_lock);
13667 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13668 list) {
13669 if (reg->nlportid == notify->portid) {
13670 list_del(&reg->list);
13671 kfree(reg);
13672 break;
13673 }
13674 }
13675 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013676
13677 if (schedule_destroy_work) {
13678 struct cfg80211_iface_destroy *destroy;
13679
13680 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13681 if (destroy) {
13682 destroy->nlportid = notify->portid;
13683 spin_lock(&rdev->destroy_list_lock);
13684 list_add(&destroy->list, &rdev->destroy_list);
13685 spin_unlock(&rdev->destroy_list_lock);
13686 schedule_work(&rdev->destroy_work);
13687 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013688 } else if (schedule_scan_stop) {
13689 sched_scan_req->owner_nlportid = 0;
13690
13691 if (rdev->ops->sched_scan_stop &&
13692 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13693 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013694 }
Johannes Berg5e760232011-11-04 11:18:17 +010013695 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013696
13697 rcu_read_unlock();
13698
Ilan peer05050752015-03-04 00:32:06 -050013699 /*
13700 * It is possible that the user space process that is controlling the
13701 * indoor setting disappeared, so notify the regulatory core.
13702 */
13703 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013704 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013705}
13706
13707static struct notifier_block nl80211_netlink_notifier = {
13708 .notifier_call = nl80211_netlink_notify,
13709};
13710
Jouni Malinen355199e2013-02-27 17:14:27 +020013711void cfg80211_ft_event(struct net_device *netdev,
13712 struct cfg80211_ft_event_params *ft_event)
13713{
13714 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013715 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013716 struct sk_buff *msg;
13717 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013718
13719 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13720
13721 if (!ft_event->target_ap)
13722 return;
13723
13724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13725 if (!msg)
13726 return;
13727
13728 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013729 if (!hdr)
13730 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013731
Johannes Bergae917c92013-10-25 11:05:22 +020013732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13733 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13734 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13735 goto out;
13736
13737 if (ft_event->ies &&
13738 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13739 goto out;
13740 if (ft_event->ric_ies &&
13741 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13742 ft_event->ric_ies))
13743 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013744
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013745 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013746
Johannes Berg68eb5502013-11-19 15:19:38 +010013747 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013748 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013749 return;
13750 out:
13751 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013752}
13753EXPORT_SYMBOL(cfg80211_ft_event);
13754
Arend van Spriel5de17982013-04-18 15:49:00 +020013755void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13756{
13757 struct cfg80211_registered_device *rdev;
13758 struct sk_buff *msg;
13759 void *hdr;
13760 u32 nlportid;
13761
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013762 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013763 if (!rdev->crit_proto_nlportid)
13764 return;
13765
13766 nlportid = rdev->crit_proto_nlportid;
13767 rdev->crit_proto_nlportid = 0;
13768
13769 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13770 if (!msg)
13771 return;
13772
13773 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13774 if (!hdr)
13775 goto nla_put_failure;
13776
13777 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013778 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13779 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013780 goto nla_put_failure;
13781
13782 genlmsg_end(msg, hdr);
13783
13784 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13785 return;
13786
13787 nla_put_failure:
13788 if (hdr)
13789 genlmsg_cancel(msg, hdr);
13790 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020013791}
13792EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13793
Johannes Berg348baf02014-01-24 14:06:29 +010013794void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13795{
13796 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013797 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013798 struct sk_buff *msg;
13799 void *hdr;
13800
13801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13802 if (!msg)
13803 return;
13804
13805 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13806 if (!hdr)
13807 goto out;
13808
13809 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13810 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013811 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13812 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013813 goto out;
13814
13815 genlmsg_end(msg, hdr);
13816
13817 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13818 NL80211_MCGRP_MLME, GFP_KERNEL);
13819 return;
13820 out:
13821 nlmsg_free(msg);
13822}
13823
Johannes Berg55682962007-09-20 13:09:35 -040013824/* initialisation/exit functions */
13825
13826int nl80211_init(void)
13827{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013828 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013829
Johannes Berg2a94fe42013-11-19 15:19:39 +010013830 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13831 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013832 if (err)
13833 return err;
13834
Jouni Malinen026331c2010-02-15 12:53:10 +020013835 err = netlink_register_notifier(&nl80211_netlink_notifier);
13836 if (err)
13837 goto err_out;
13838
Johannes Berg55682962007-09-20 13:09:35 -040013839 return 0;
13840 err_out:
13841 genl_unregister_family(&nl80211_fam);
13842 return err;
13843}
13844
13845void nl80211_exit(void)
13846{
Jouni Malinen026331c2010-02-15 12:53:10 +020013847 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013848 genl_unregister_family(&nl80211_fam);
13849}