blob: d12044996a0ef9fb20ba9a4ff390e005f9a2275c [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]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800170 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200171 if (netdev) {
172 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800173 tmp = wiphy_to_rdev(
174 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200175 else
176 tmp = NULL;
177
Johannes Berg7fee4772012-06-15 14:09:58 +0200178 /* not wireless device -- return error */
179 if (!tmp)
180 return ERR_PTR(-EINVAL);
181
182 /* mismatch -- return error */
183 if (rdev && tmp != rdev)
184 return ERR_PTR(-EINVAL);
185
186 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
189
Johannes Berg4f7eff12012-06-15 14:14:22 +0200190 if (!rdev)
191 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (netns != wiphy_net(&rdev->wiphy))
194 return ERR_PTR(-ENODEV);
195
196 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200197}
198
199/*
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200202 *
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
205 */
206static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200207cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200208{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200209 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200210}
211
Johannes Berg55682962007-09-20 13:09:35 -0400212/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300213static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400214 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
215 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700216 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200217 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100218
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200219 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
224
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200225 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200230 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400231
232 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Eliad Pellere007b852011-11-24 18:13:56 +0200236 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
237 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100238
Johannes Bergb9454e82009-07-08 13:29:08 +0200239 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100240 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
241 .len = WLAN_MAX_KEY_LEN },
242 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
243 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
244 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200245 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200246 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100247
248 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
249 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
250 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
252 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100254 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
255 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
256 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
258 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100260 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200261 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800263 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100264 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300265
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700266 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
267 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
268
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300269 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200272 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
273 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100274 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300275
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800276 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700277 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700278
Johannes Berg6c739412011-11-03 09:27:01 +0100279 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200280
281 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
282 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
283 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100284 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
285 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200286
287 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_SSID_LEN },
289 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
290 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200291 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300292 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300293 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300294 [NL80211_ATTR_STA_FLAGS2] = {
295 .len = sizeof(struct nl80211_sta_flag_update),
296 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300297 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200300 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
301 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
302 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200303 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100304 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100305 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
306 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100307 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
308 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200309 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200310 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
311 .len = IEEE80211_MAX_DATA_LEN },
312 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200313 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200314 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300315 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200316 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300317 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200319 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900320 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100322 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100323 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100324 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200325 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700326 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300327 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200328 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200329 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300330 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300331 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
332 .len = IEEE80211_MAX_DATA_LEN },
333 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530335 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300336 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530337 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300338 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
342 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300343 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000358 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700359 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100360 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
361 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530362 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
363 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200364 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
365 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100366 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100367 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
368 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
369 .len = NL80211_VHT_CAPABILITY_LEN,
370 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200371 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
372 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
373 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300374 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200375 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
377 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300378 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
379 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200382 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100383 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100384 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800387 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
388 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200389 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
390 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530391 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200392 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300393 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300394 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300395 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
396 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
397 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300398 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200399 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200401 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200402 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500403 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200404 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100405 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200406 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400407};
408
Johannes Berge31b8212010-10-05 19:39:30 +0200409/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000410static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200411 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200412 [NL80211_KEY_IDX] = { .type = NLA_U8 },
413 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200414 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200415 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
416 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200417 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100418 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
419};
420
421/* policy for the key default flags */
422static const struct nla_policy
423nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
424 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
425 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200426};
427
Johannes Bergff1b6e62011-05-04 15:37:28 +0200428/* policy for WoWLAN attributes */
429static const struct nla_policy
430nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
431 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200435 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
436 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
437 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100439 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300440 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100441};
442
443static const struct nla_policy
444nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
445 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
446 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
447 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
448 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
449 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
451 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
452 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
453 },
454 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
455 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
456 },
457 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
458 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
459 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200460};
461
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700462/* policy for coalesce rule attributes */
463static const struct nla_policy
464nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
465 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
466 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
467 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
468};
469
Johannes Berge5497d72011-07-05 16:35:40 +0200470/* policy for GTK rekey offload attributes */
471static const struct nla_policy
472nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
473 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
474 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
475 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
476};
477
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300478static const struct nla_policy
479nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200480 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300481 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700482 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300483};
484
Avraham Stern3b06d272015-10-12 09:51:34 +0300485static const struct nla_policy
486nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
487 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
488 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
489};
490
Arend van Spriel38de03d2016-03-02 20:37:18 +0100491static const struct nla_policy
492nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
493 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
494 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
495 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
496 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
497 },
498};
499
Johannes Berg97990a02013-04-19 01:02:55 +0200500static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
501 struct netlink_callback *cb,
502 struct cfg80211_registered_device **rdev,
503 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100504{
Johannes Berg67748892010-10-04 21:14:06 +0200505 int err;
506
Johannes Berg67748892010-10-04 21:14:06 +0200507 rtnl_lock();
508
Johannes Berg97990a02013-04-19 01:02:55 +0200509 if (!cb->args[0]) {
510 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
511 nl80211_fam.attrbuf, nl80211_fam.maxattr,
512 nl80211_policy);
513 if (err)
514 goto out_unlock;
515
516 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
517 nl80211_fam.attrbuf);
518 if (IS_ERR(*wdev)) {
519 err = PTR_ERR(*wdev);
520 goto out_unlock;
521 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800522 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200523 /* 0 is the first index - add 1 to parse only once */
524 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200525 cb->args[1] = (*wdev)->identifier;
526 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200527 /* subtract the 1 again here */
528 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200529 struct wireless_dev *tmp;
530
531 if (!wiphy) {
532 err = -ENODEV;
533 goto out_unlock;
534 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800535 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200536 *wdev = NULL;
537
Johannes Berg53873f12016-05-03 16:52:04 +0300538 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200539 if (tmp->identifier == cb->args[1]) {
540 *wdev = tmp;
541 break;
542 }
543 }
Johannes Berg97990a02013-04-19 01:02:55 +0200544
545 if (!*wdev) {
546 err = -ENODEV;
547 goto out_unlock;
548 }
Johannes Berg67748892010-10-04 21:14:06 +0200549 }
550
Johannes Berg67748892010-10-04 21:14:06 +0200551 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200552 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200553 rtnl_unlock();
554 return err;
555}
556
Johannes Berg97990a02013-04-19 01:02:55 +0200557static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200558{
Johannes Berg67748892010-10-04 21:14:06 +0200559 rtnl_unlock();
560}
561
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100562/* IE validation */
563static bool is_valid_ie_attr(const struct nlattr *attr)
564{
565 const u8 *pos;
566 int len;
567
568 if (!attr)
569 return true;
570
571 pos = nla_data(attr);
572 len = nla_len(attr);
573
574 while (len) {
575 u8 elemlen;
576
577 if (len < 2)
578 return false;
579 len -= 2;
580
581 elemlen = pos[1];
582 if (elemlen > len)
583 return false;
584
585 len -= elemlen;
586 pos += 2 + elemlen;
587 }
588
589 return true;
590}
591
Johannes Berg55682962007-09-20 13:09:35 -0400592/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000593static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400594 int flags, u8 cmd)
595{
596 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000597 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400598}
599
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400600static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100601 struct ieee80211_channel *chan,
602 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400603{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200604 /* Some channels must be completely excluded from the
605 * list to protect old user-space tools from breaking
606 */
607 if (!large && chan->flags &
608 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
609 return 0;
610
David S. Miller9360ffd2012-03-29 04:41:26 -0400611 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
612 chan->center_freq))
613 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400614
David S. Miller9360ffd2012-03-29 04:41:26 -0400615 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
616 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
617 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200618 if (chan->flags & IEEE80211_CHAN_NO_IR) {
619 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
620 goto nla_put_failure;
621 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
622 goto nla_put_failure;
623 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100624 if (chan->flags & IEEE80211_CHAN_RADAR) {
625 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
626 goto nla_put_failure;
627 if (large) {
628 u32 time;
629
630 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
631
632 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
633 chan->dfs_state))
634 goto nla_put_failure;
635 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
636 time))
637 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100638 if (nla_put_u32(msg,
639 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
640 chan->dfs_cac_ms))
641 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100642 }
643 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400644
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100645 if (large) {
646 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
647 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
648 goto nla_put_failure;
649 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
650 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
651 goto nla_put_failure;
652 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
653 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
654 goto nla_put_failure;
655 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
656 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
657 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200658 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
659 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
660 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300661 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
662 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200663 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200664 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
665 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
666 goto nla_put_failure;
667 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
668 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
669 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100670 }
671
David S. Miller9360ffd2012-03-29 04:41:26 -0400672 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
673 DBM_TO_MBM(chan->max_power)))
674 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400675
676 return 0;
677
678 nla_put_failure:
679 return -ENOBUFS;
680}
681
Johannes Berg55682962007-09-20 13:09:35 -0400682/* netlink command implementations */
683
Johannes Bergb9454e82009-07-08 13:29:08 +0200684struct key_parse {
685 struct key_params p;
686 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200687 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200688 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100689 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200690};
691
692static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
693{
694 struct nlattr *tb[NL80211_KEY_MAX + 1];
695 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
696 nl80211_key_policy);
697 if (err)
698 return err;
699
700 k->def = !!tb[NL80211_KEY_DEFAULT];
701 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
702
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100703 if (k->def) {
704 k->def_uni = true;
705 k->def_multi = true;
706 }
707 if (k->defmgmt)
708 k->def_multi = true;
709
Johannes Bergb9454e82009-07-08 13:29:08 +0200710 if (tb[NL80211_KEY_IDX])
711 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
712
713 if (tb[NL80211_KEY_DATA]) {
714 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
715 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
716 }
717
718 if (tb[NL80211_KEY_SEQ]) {
719 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
720 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
721 }
722
723 if (tb[NL80211_KEY_CIPHER])
724 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
725
Johannes Berge31b8212010-10-05 19:39:30 +0200726 if (tb[NL80211_KEY_TYPE]) {
727 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
728 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
729 return -EINVAL;
730 }
731
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100732 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
733 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100734 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
735 tb[NL80211_KEY_DEFAULT_TYPES],
736 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100737 if (err)
738 return err;
739
740 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
741 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
742 }
743
Johannes Bergb9454e82009-07-08 13:29:08 +0200744 return 0;
745}
746
747static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
748{
749 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
750 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
751 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
752 }
753
754 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
755 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
756 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
757 }
758
759 if (info->attrs[NL80211_ATTR_KEY_IDX])
760 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
761
762 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
763 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
764
765 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
766 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
767
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100768 if (k->def) {
769 k->def_uni = true;
770 k->def_multi = true;
771 }
772 if (k->defmgmt)
773 k->def_multi = true;
774
Johannes Berge31b8212010-10-05 19:39:30 +0200775 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
776 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
777 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
778 return -EINVAL;
779 }
780
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100781 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
782 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
783 int err = nla_parse_nested(
784 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
785 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
786 nl80211_key_default_policy);
787 if (err)
788 return err;
789
790 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
791 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
792 }
793
Johannes Bergb9454e82009-07-08 13:29:08 +0200794 return 0;
795}
796
797static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
798{
799 int err;
800
801 memset(k, 0, sizeof(*k));
802 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200803 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200804
805 if (info->attrs[NL80211_ATTR_KEY])
806 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
807 else
808 err = nl80211_parse_key_old(info, k);
809
810 if (err)
811 return err;
812
813 if (k->def && k->defmgmt)
814 return -EINVAL;
815
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100816 if (k->defmgmt) {
817 if (k->def_uni || !k->def_multi)
818 return -EINVAL;
819 }
820
Johannes Bergb9454e82009-07-08 13:29:08 +0200821 if (k->idx != -1) {
822 if (k->defmgmt) {
823 if (k->idx < 4 || k->idx > 5)
824 return -EINVAL;
825 } else if (k->def) {
826 if (k->idx < 0 || k->idx > 3)
827 return -EINVAL;
828 } else {
829 if (k->idx < 0 || k->idx > 5)
830 return -EINVAL;
831 }
832 }
833
834 return 0;
835}
836
Johannes Bergfffd0932009-07-08 14:22:54 +0200837static struct cfg80211_cached_keys *
838nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530839 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200840{
841 struct key_parse parse;
842 struct nlattr *key;
843 struct cfg80211_cached_keys *result;
844 int rem, err, def = 0;
845
846 result = kzalloc(sizeof(*result), GFP_KERNEL);
847 if (!result)
848 return ERR_PTR(-ENOMEM);
849
850 result->def = -1;
851 result->defmgmt = -1;
852
853 nla_for_each_nested(key, keys, rem) {
854 memset(&parse, 0, sizeof(parse));
855 parse.idx = -1;
856
857 err = nl80211_parse_key_new(key, &parse);
858 if (err)
859 goto error;
860 err = -EINVAL;
861 if (!parse.p.key)
862 goto error;
863 if (parse.idx < 0 || parse.idx > 4)
864 goto error;
865 if (parse.def) {
866 if (def)
867 goto error;
868 def = 1;
869 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100870 if (!parse.def_uni || !parse.def_multi)
871 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200872 } else if (parse.defmgmt)
873 goto error;
874 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200875 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 if (err)
877 goto error;
878 result->params[parse.idx].cipher = parse.p.cipher;
879 result->params[parse.idx].key_len = parse.p.key_len;
880 result->params[parse.idx].key = result->data[parse.idx];
881 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530882
883 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
884 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
885 if (no_ht)
886 *no_ht = true;
887 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 }
889
890 return result;
891 error:
892 kfree(result);
893 return ERR_PTR(err);
894}
895
896static int nl80211_key_allowed(struct wireless_dev *wdev)
897{
898 ASSERT_WDEV_LOCK(wdev);
899
Johannes Bergfffd0932009-07-08 14:22:54 +0200900 switch (wdev->iftype) {
901 case NL80211_IFTYPE_AP:
902 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200903 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700904 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200905 break;
906 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200907 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200908 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200909 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200910 return -ENOLINK;
911 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100912 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100913 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100914 case NL80211_IFTYPE_MONITOR:
915 case NL80211_IFTYPE_P2P_DEVICE:
916 case NL80211_IFTYPE_WDS:
917 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200918 return -EINVAL;
919 }
920
921 return 0;
922}
923
Jouni Malinen664834d2014-01-15 00:01:44 +0200924static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
925 struct nlattr *tb)
926{
927 struct ieee80211_channel *chan;
928
929 if (tb == NULL)
930 return NULL;
931 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
932 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
933 return NULL;
934 return chan;
935}
936
Johannes Berg7527a782011-05-13 10:58:57 +0200937static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
938{
939 struct nlattr *nl_modes = nla_nest_start(msg, attr);
940 int i;
941
942 if (!nl_modes)
943 goto nla_put_failure;
944
945 i = 0;
946 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400947 if ((ifmodes & 1) && nla_put_flag(msg, i))
948 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200949 ifmodes >>= 1;
950 i++;
951 }
952
953 nla_nest_end(msg, nl_modes);
954 return 0;
955
956nla_put_failure:
957 return -ENOBUFS;
958}
959
960static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100961 struct sk_buff *msg,
962 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200963{
964 struct nlattr *nl_combis;
965 int i, j;
966
967 nl_combis = nla_nest_start(msg,
968 NL80211_ATTR_INTERFACE_COMBINATIONS);
969 if (!nl_combis)
970 goto nla_put_failure;
971
972 for (i = 0; i < wiphy->n_iface_combinations; i++) {
973 const struct ieee80211_iface_combination *c;
974 struct nlattr *nl_combi, *nl_limits;
975
976 c = &wiphy->iface_combinations[i];
977
978 nl_combi = nla_nest_start(msg, i + 1);
979 if (!nl_combi)
980 goto nla_put_failure;
981
982 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
983 if (!nl_limits)
984 goto nla_put_failure;
985
986 for (j = 0; j < c->n_limits; j++) {
987 struct nlattr *nl_limit;
988
989 nl_limit = nla_nest_start(msg, j + 1);
990 if (!nl_limit)
991 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400992 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
993 c->limits[j].max))
994 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200995 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
996 c->limits[j].types))
997 goto nla_put_failure;
998 nla_nest_end(msg, nl_limit);
999 }
1000
1001 nla_nest_end(msg, nl_limits);
1002
David S. Miller9360ffd2012-03-29 04:41:26 -04001003 if (c->beacon_int_infra_match &&
1004 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1005 goto nla_put_failure;
1006 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1007 c->num_different_channels) ||
1008 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1009 c->max_interfaces))
1010 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001011 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001012 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1013 c->radar_detect_widths) ||
1014 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1015 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001016 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001017
1018 nla_nest_end(msg, nl_combi);
1019 }
1020
1021 nla_nest_end(msg, nl_combis);
1022
1023 return 0;
1024nla_put_failure:
1025 return -ENOBUFS;
1026}
1027
Johannes Berg3713b4e2013-02-14 16:19:38 +01001028#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001029static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1030 struct sk_buff *msg)
1031{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001032 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001033 struct nlattr *nl_tcp;
1034
1035 if (!tcp)
1036 return 0;
1037
1038 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1039 if (!nl_tcp)
1040 return -ENOBUFS;
1041
1042 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1043 tcp->data_payload_max))
1044 return -ENOBUFS;
1045
1046 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1047 tcp->data_payload_max))
1048 return -ENOBUFS;
1049
1050 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1051 return -ENOBUFS;
1052
1053 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1054 sizeof(*tcp->tok), tcp->tok))
1055 return -ENOBUFS;
1056
1057 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1058 tcp->data_interval_max))
1059 return -ENOBUFS;
1060
1061 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1062 tcp->wake_payload_max))
1063 return -ENOBUFS;
1064
1065 nla_nest_end(msg, nl_tcp);
1066 return 0;
1067}
1068
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001071 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072{
1073 struct nlattr *nl_wowlan;
1074
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 return 0;
1077
1078 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1079 if (!nl_wowlan)
1080 return -ENOBUFS;
1081
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001083 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001084 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001085 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1098 return -ENOBUFS;
1099
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001101 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1103 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1104 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1105 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001106 };
1107
1108 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1109 sizeof(pat), &pat))
1110 return -ENOBUFS;
1111 }
1112
Luciano Coelho75453cc2015-01-09 14:06:37 +02001113 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1114 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1115 rdev->wiphy.wowlan->max_nd_match_sets))
1116 return -ENOBUFS;
1117
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001118 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001119 return -ENOBUFS;
1120
Johannes Berg3713b4e2013-02-14 16:19:38 +01001121 nla_nest_end(msg, nl_wowlan);
1122
1123 return 0;
1124}
1125#endif
1126
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001127static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001128 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001129{
1130 struct nl80211_coalesce_rule_support rule;
1131
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001132 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001133 return 0;
1134
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001135 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1136 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1137 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1138 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1139 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1140 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001141
1142 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1143 return -ENOBUFS;
1144
1145 return 0;
1146}
1147
Johannes Berg3713b4e2013-02-14 16:19:38 +01001148static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1149 struct ieee80211_supported_band *sband)
1150{
1151 struct nlattr *nl_rates, *nl_rate;
1152 struct ieee80211_rate *rate;
1153 int i;
1154
1155 /* add HT info */
1156 if (sband->ht_cap.ht_supported &&
1157 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1158 sizeof(sband->ht_cap.mcs),
1159 &sband->ht_cap.mcs) ||
1160 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1161 sband->ht_cap.cap) ||
1162 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1163 sband->ht_cap.ampdu_factor) ||
1164 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1165 sband->ht_cap.ampdu_density)))
1166 return -ENOBUFS;
1167
1168 /* add VHT info */
1169 if (sband->vht_cap.vht_supported &&
1170 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1171 sizeof(sband->vht_cap.vht_mcs),
1172 &sband->vht_cap.vht_mcs) ||
1173 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1174 sband->vht_cap.cap)))
1175 return -ENOBUFS;
1176
1177 /* add bitrates */
1178 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1179 if (!nl_rates)
1180 return -ENOBUFS;
1181
1182 for (i = 0; i < sband->n_bitrates; i++) {
1183 nl_rate = nla_nest_start(msg, i);
1184 if (!nl_rate)
1185 return -ENOBUFS;
1186
1187 rate = &sband->bitrates[i];
1188 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1189 rate->bitrate))
1190 return -ENOBUFS;
1191 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1192 nla_put_flag(msg,
1193 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1194 return -ENOBUFS;
1195
1196 nla_nest_end(msg, nl_rate);
1197 }
1198
1199 nla_nest_end(msg, nl_rates);
1200
1201 return 0;
1202}
1203
1204static int
1205nl80211_send_mgmt_stypes(struct sk_buff *msg,
1206 const struct ieee80211_txrx_stypes *mgmt_stypes)
1207{
1208 u16 stypes;
1209 struct nlattr *nl_ftypes, *nl_ifs;
1210 enum nl80211_iftype ift;
1211 int i;
1212
1213 if (!mgmt_stypes)
1214 return 0;
1215
1216 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1217 if (!nl_ifs)
1218 return -ENOBUFS;
1219
1220 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1221 nl_ftypes = nla_nest_start(msg, ift);
1222 if (!nl_ftypes)
1223 return -ENOBUFS;
1224 i = 0;
1225 stypes = mgmt_stypes[ift].tx;
1226 while (stypes) {
1227 if ((stypes & 1) &&
1228 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1229 (i << 4) | IEEE80211_FTYPE_MGMT))
1230 return -ENOBUFS;
1231 stypes >>= 1;
1232 i++;
1233 }
1234 nla_nest_end(msg, nl_ftypes);
1235 }
1236
1237 nla_nest_end(msg, nl_ifs);
1238
1239 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1240 if (!nl_ifs)
1241 return -ENOBUFS;
1242
1243 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1244 nl_ftypes = nla_nest_start(msg, ift);
1245 if (!nl_ftypes)
1246 return -ENOBUFS;
1247 i = 0;
1248 stypes = mgmt_stypes[ift].rx;
1249 while (stypes) {
1250 if ((stypes & 1) &&
1251 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1252 (i << 4) | IEEE80211_FTYPE_MGMT))
1253 return -ENOBUFS;
1254 stypes >>= 1;
1255 i++;
1256 }
1257 nla_nest_end(msg, nl_ftypes);
1258 }
1259 nla_nest_end(msg, nl_ifs);
1260
1261 return 0;
1262}
1263
Johannes Berg86e8cf92013-06-19 10:57:22 +02001264struct nl80211_dump_wiphy_state {
1265 s64 filter_wiphy;
1266 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301267 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001268 bool split;
1269};
1270
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001272 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001275{
1276 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001277 struct nlattr *nl_bands, *nl_band;
1278 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001279 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001280 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001281 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001282 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001283 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001285 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001286
Johannes Berg3bb20552014-05-26 13:52:25 +02001287 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001288 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 return -ENOBUFS;
1290
Johannes Berg86e8cf92013-06-19 10:57:22 +02001291 if (WARN_ON(!state))
1292 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001293
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001297 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001299 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001300
Johannes Berg3bb20552014-05-26 13:52:25 +02001301 if (cmd != NL80211_CMD_NEW_WIPHY)
1302 goto finish;
1303
Johannes Berg86e8cf92013-06-19 10:57:22 +02001304 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 case 0:
1306 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001325 rdev->wiphy.max_match_sets) ||
1326 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1327 rdev->wiphy.max_sched_scan_plans) ||
1328 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1329 rdev->wiphy.max_sched_scan_plan_interval) ||
1330 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1331 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001332 goto nla_put_failure;
1333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1336 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1339 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1342 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1345 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1348 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001351 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001352 state->split_start++;
1353 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 break;
1355 case 1:
1356 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001357 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1358 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001359 goto nla_put_failure;
1360
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001362 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001363 goto nla_put_failure;
1364
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001365 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1367 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001368
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001370 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001372 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001374
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001375 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001377 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001379
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001380 if ((rdev->wiphy.available_antennas_tx ||
1381 rdev->wiphy.available_antennas_rx) &&
1382 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 u32 tx_ant = 0, rx_ant = 0;
1384 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001385 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 if (!res) {
1387 if (nla_put_u32(msg,
1388 NL80211_ATTR_WIPHY_ANTENNA_TX,
1389 tx_ant) ||
1390 nla_put_u32(msg,
1391 NL80211_ATTR_WIPHY_ANTENNA_RX,
1392 rx_ant))
1393 goto nla_put_failure;
1394 }
Johannes Bergee688b002008-01-24 19:38:39 +01001395 }
1396
Johannes Berg86e8cf92013-06-19 10:57:22 +02001397 state->split_start++;
1398 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 break;
1400 case 2:
1401 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001402 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->split_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 case 3:
1408 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1409 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001410 goto nla_put_failure;
1411
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001413 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 struct ieee80211_supported_band *sband;
1415
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001416 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417
1418 if (!sband)
1419 continue;
1420
1421 nl_band = nla_nest_start(msg, band);
1422 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001423 goto nla_put_failure;
1424
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 case 0:
1427 if (nl80211_send_band_rateinfo(msg, sband))
1428 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 state->chan_start++;
1430 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 break;
1432 default:
1433 /* add frequencies */
1434 nl_freqs = nla_nest_start(
1435 msg, NL80211_BAND_ATTR_FREQS);
1436 if (!nl_freqs)
1437 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001438
Johannes Berg86e8cf92013-06-19 10:57:22 +02001439 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 i < sband->n_channels;
1441 i++) {
1442 nl_freq = nla_nest_start(msg, i);
1443 if (!nl_freq)
1444 goto nla_put_failure;
1445
1446 chan = &sband->channels[i];
1447
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 if (nl80211_msg_put_channel(
1449 msg, chan,
1450 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 goto nla_put_failure;
1452
1453 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001454 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 break;
1456 }
1457 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001458 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001460 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 nla_nest_end(msg, nl_freqs);
1462 }
1463
1464 nla_nest_end(msg, nl_band);
1465
Johannes Berg86e8cf92013-06-19 10:57:22 +02001466 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 band--;
1470 break;
1471 }
Johannes Bergee688b002008-01-24 19:38:39 +01001472 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001474
Johannes Berg57fbcce2016-04-12 15:56:15 +02001475 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001476 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001478 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001479
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 if (state->band_start == 0 && state->chan_start == 0)
1482 state->split_start++;
1483 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 break;
1485 case 4:
1486 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1487 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001488 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001489
1490 i = 0;
1491#define CMD(op, n) \
1492 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 i++; \
1495 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1496 goto nla_put_failure; \
1497 } \
1498 } while (0)
1499
1500 CMD(add_virtual_intf, NEW_INTERFACE);
1501 CMD(change_virtual_intf, SET_INTERFACE);
1502 CMD(add_key, NEW_KEY);
1503 CMD(start_ap, START_AP);
1504 CMD(add_station, NEW_STATION);
1505 CMD(add_mpath, NEW_MPATH);
1506 CMD(update_mesh_config, SET_MESH_CONFIG);
1507 CMD(change_bss, SET_BSS);
1508 CMD(auth, AUTHENTICATE);
1509 CMD(assoc, ASSOCIATE);
1510 CMD(deauth, DEAUTHENTICATE);
1511 CMD(disassoc, DISASSOCIATE);
1512 CMD(join_ibss, JOIN_IBSS);
1513 CMD(join_mesh, JOIN_MESH);
1514 CMD(set_pmksa, SET_PMKSA);
1515 CMD(del_pmksa, DEL_PMKSA);
1516 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1519 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1520 CMD(mgmt_tx, FRAME);
1521 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 i++;
1524 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1525 goto nla_put_failure;
1526 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001527 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1528 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 i++;
1530 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1531 goto nla_put_failure;
1532 }
1533 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 CMD(tdls_mgmt, TDLS_MGMT);
1536 CMD(tdls_oper, TDLS_OPER);
1537 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 CMD(sched_scan_start, START_SCHED_SCAN);
1540 CMD(probe_client, PROBE_CLIENT);
1541 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001542 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 i++;
1544 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1545 goto nla_put_failure;
1546 }
1547 CMD(start_p2p_device, START_P2P_DEVICE);
1548 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001549#ifdef CONFIG_NL80211_TESTMODE
1550 CMD(testmode_cmd, TESTMODE);
1551#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001552 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001553 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1554 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001556 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001557 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001558 if (rdev->wiphy.features &
1559 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001560 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001561 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001562 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001563#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001564
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 i++;
1567 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001568 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001569 }
1570
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 i++;
1573 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1574 goto nla_put_failure;
1575 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001576
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001578 state->split_start++;
1579 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 break;
1581 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 if (rdev->ops->remain_on_channel &&
1583 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_put_u32(msg,
1585 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001587 goto nla_put_failure;
1588
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1591 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001592
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1594 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001595 state->split_start++;
1596 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 break;
1598 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001599#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001600 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001601 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split_start++;
1603 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 break;
1605#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001606 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607#endif
1608 case 7:
1609 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001611 goto nla_put_failure;
1612
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001614 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001616
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 state->split_start++;
1618 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 break;
1620 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 goto nla_put_failure;
1625
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001627 /*
1628 * We can only add the per-channel limit information if the
1629 * dump is split, otherwise it makes it too big. Therefore
1630 * only advertise it in that case.
1631 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001633 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1634 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 goto nla_put_failure;
1636
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1640 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 goto nla_put_failure;
1642
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001643 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1644 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647 goto nla_put_failure;
1648
1649 /*
1650 * Any information below this point is only available to
1651 * applications that can deal with it being split. This
1652 * helps ensure that newly added capabilities don't break
1653 * older tools by overrunning their buffers.
1654 *
1655 * We still increment split_start so that in the split
1656 * case we'll continue with more data in the next round,
1657 * but break unconditionally so unsplit data stops here.
1658 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001659 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001660 break;
1661 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001662 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001663 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 rdev->wiphy.extended_capabilities_len,
1665 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001666 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001667 rdev->wiphy.extended_capabilities_len,
1668 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001669 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001672 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1674 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001675 goto nla_put_failure;
1676
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001677 state->split_start++;
1678 break;
1679 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001681 goto nla_put_failure;
1682
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001683 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001684 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1685 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1686 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001687
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001689 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001691 goto nla_put_failure;
1692
Johannes Bergad7e7182013-11-13 13:37:47 +01001693 state->split_start++;
1694 break;
1695 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001697 const struct nl80211_vendor_cmd_info *info;
1698 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001699
Johannes Berg567ffc32013-12-18 14:43:31 +01001700 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1701 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001702 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001703
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001704 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1705 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001706 if (nla_put(msg, i + 1, sizeof(*info), info))
1707 goto nla_put_failure;
1708 }
1709 nla_nest_end(msg, nested);
1710 }
1711
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001712 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001713 const struct nl80211_vendor_cmd_info *info;
1714 struct nlattr *nested;
1715
1716 nested = nla_nest_start(msg,
1717 NL80211_ATTR_VENDOR_EVENTS);
1718 if (!nested)
1719 goto nla_put_failure;
1720
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001721 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1722 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001723 if (nla_put(msg, i + 1, sizeof(*info), info))
1724 goto nla_put_failure;
1725 }
1726 nla_nest_end(msg, nested);
1727 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001728 state->split_start++;
1729 break;
1730 case 12:
1731 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1732 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1733 rdev->wiphy.max_num_csa_counters))
1734 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001735
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001736 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1737 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1738 goto nla_put_failure;
1739
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001740 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1741 sizeof(rdev->wiphy.ext_features),
1742 rdev->wiphy.ext_features))
1743 goto nla_put_failure;
1744
Arend van Spriel38de03d2016-03-02 20:37:18 +01001745 if (rdev->wiphy.bss_select_support) {
1746 struct nlattr *nested;
1747 u32 bss_select_support = rdev->wiphy.bss_select_support;
1748
1749 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1750 if (!nested)
1751 goto nla_put_failure;
1752
1753 i = 0;
1754 while (bss_select_support) {
1755 if ((bss_select_support & 1) &&
1756 nla_put_flag(msg, i))
1757 goto nla_put_failure;
1758 i++;
1759 bss_select_support >>= 1;
1760 }
1761 nla_nest_end(msg, nested);
1762 }
1763
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301764 state->split_start++;
1765 break;
1766 case 13:
1767 if (rdev->wiphy.num_iftype_ext_capab &&
1768 rdev->wiphy.iftype_ext_capab) {
1769 struct nlattr *nested_ext_capab, *nested;
1770
1771 nested = nla_nest_start(msg,
1772 NL80211_ATTR_IFTYPE_EXT_CAPA);
1773 if (!nested)
1774 goto nla_put_failure;
1775
1776 for (i = state->capa_start;
1777 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1778 const struct wiphy_iftype_ext_capab *capab;
1779
1780 capab = &rdev->wiphy.iftype_ext_capab[i];
1781
1782 nested_ext_capab = nla_nest_start(msg, i);
1783 if (!nested_ext_capab ||
1784 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1785 capab->iftype) ||
1786 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1787 capab->extended_capabilities_len,
1788 capab->extended_capabilities) ||
1789 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1790 capab->extended_capabilities_len,
1791 capab->extended_capabilities_mask))
1792 goto nla_put_failure;
1793
1794 nla_nest_end(msg, nested_ext_capab);
1795 if (state->split)
1796 break;
1797 }
1798 nla_nest_end(msg, nested);
1799 if (i < rdev->wiphy.num_iftype_ext_capab) {
1800 state->capa_start = i + 1;
1801 break;
1802 }
1803 }
1804
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001807 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001808 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001809 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001810 genlmsg_end(msg, hdr);
1811 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001812
1813 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001814 genlmsg_cancel(msg, hdr);
1815 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001816}
1817
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1819 struct netlink_callback *cb,
1820 struct nl80211_dump_wiphy_state *state)
1821{
1822 struct nlattr **tb = nl80211_fam.attrbuf;
1823 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1824 tb, nl80211_fam.maxattr, nl80211_policy);
1825 /* ignore parse errors for backward compatibility */
1826 if (ret)
1827 return 0;
1828
1829 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1830 if (tb[NL80211_ATTR_WIPHY])
1831 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1832 if (tb[NL80211_ATTR_WDEV])
1833 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1834 if (tb[NL80211_ATTR_IFINDEX]) {
1835 struct net_device *netdev;
1836 struct cfg80211_registered_device *rdev;
1837 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1838
Ying Xue7f2b8562014-01-15 10:23:45 +08001839 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001840 if (!netdev)
1841 return -ENODEV;
1842 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001843 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001844 netdev->ieee80211_ptr->wiphy);
1845 state->filter_wiphy = rdev->wiphy_idx;
1846 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001847 }
1848
1849 return 0;
1850}
1851
Johannes Berg55682962007-09-20 13:09:35 -04001852static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1853{
Johannes Berg645e77d2013-03-01 14:03:49 +01001854 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001855 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001856 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001857
Johannes Berg5fe231e2013-05-08 21:45:15 +02001858 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001859 if (!state) {
1860 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001861 if (!state) {
1862 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001863 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001864 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001865 state->filter_wiphy = -1;
1866 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1867 if (ret) {
1868 kfree(state);
1869 rtnl_unlock();
1870 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001871 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001872 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001873 }
1874
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001875 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1876 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001877 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001878 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001879 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001880 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001881 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001882 continue;
1883 /* attempt to fit multiple wiphy data chunks into the skb */
1884 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001885 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1886 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001887 NETLINK_CB(cb->skb).portid,
1888 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001889 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001890 if (ret < 0) {
1891 /*
1892 * If sending the wiphy data didn't fit (ENOBUFS
1893 * or EMSGSIZE returned), this SKB is still
1894 * empty (so it's not too big because another
1895 * wiphy dataset is already in the skb) and
1896 * we've not tried to adjust the dump allocation
1897 * yet ... then adjust the alloc size to be
1898 * bigger, and return 1 but with the empty skb.
1899 * This results in an empty message being RX'ed
1900 * in userspace, but that is ignored.
1901 *
1902 * We can then retry with the larger buffer.
1903 */
1904 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001905 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001906 cb->min_dump_alloc < 4096) {
1907 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001908 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001909 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001910 return 1;
1911 }
1912 idx--;
1913 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001914 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001915 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001916 break;
Johannes Berg55682962007-09-20 13:09:35 -04001917 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001918 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001919
Johannes Berg86e8cf92013-06-19 10:57:22 +02001920 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001921
1922 return skb->len;
1923}
1924
Johannes Berg86e8cf92013-06-19 10:57:22 +02001925static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1926{
1927 kfree((void *)cb->args[0]);
1928 return 0;
1929}
1930
Johannes Berg55682962007-09-20 13:09:35 -04001931static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1932{
1933 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001934 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001935 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001936
Johannes Berg645e77d2013-03-01 14:03:49 +01001937 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001938 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001939 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001940
Johannes Berg3bb20552014-05-26 13:52:25 +02001941 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1942 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001943 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001944 nlmsg_free(msg);
1945 return -ENOBUFS;
1946 }
Johannes Berg55682962007-09-20 13:09:35 -04001947
Johannes Berg134e6372009-07-10 09:51:34 +00001948 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001949}
1950
Jouni Malinen31888482008-10-30 16:59:24 +02001951static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1952 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1953 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1954 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1955 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1956 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1957};
1958
1959static int parse_txq_params(struct nlattr *tb[],
1960 struct ieee80211_txq_params *txq_params)
1961{
Johannes Berga3304b02012-03-28 11:04:24 +02001962 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001963 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1964 !tb[NL80211_TXQ_ATTR_AIFS])
1965 return -EINVAL;
1966
Johannes Berga3304b02012-03-28 11:04:24 +02001967 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001968 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1969 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1970 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1971 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1972
Johannes Berga3304b02012-03-28 11:04:24 +02001973 if (txq_params->ac >= NL80211_NUM_ACS)
1974 return -EINVAL;
1975
Jouni Malinen31888482008-10-30 16:59:24 +02001976 return 0;
1977}
1978
Johannes Bergf444de02010-05-05 15:25:02 +02001979static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1980{
1981 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001982 * You can only set the channel explicitly for WDS interfaces,
1983 * all others have their channel managed via their respective
1984 * "establish a connection" command (connect, join, ...)
1985 *
1986 * For AP/GO and mesh mode, the channel can be set with the
1987 * channel userspace API, but is only stored and passed to the
1988 * low-level driver when the AP starts or the mesh is joined.
1989 * This is for backward compatibility, userspace can also give
1990 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001991 *
1992 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001993 * whatever else is going on, so they have their own special
1994 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001995 */
1996 return !wdev ||
1997 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001998 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001999 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2000 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002001}
2002
Johannes Berg683b6d32012-11-08 21:25:48 +01002003static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2004 struct genl_info *info,
2005 struct cfg80211_chan_def *chandef)
2006{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302007 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002008
2009 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2010 return -EINVAL;
2011
2012 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2013
2014 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002015 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2016 chandef->center_freq1 = control_freq;
2017 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002018
2019 /* Primary channel not allowed */
2020 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2021 return -EINVAL;
2022
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002023 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2024 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002025
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002026 chantype = nla_get_u32(
2027 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2028
2029 switch (chantype) {
2030 case NL80211_CHAN_NO_HT:
2031 case NL80211_CHAN_HT20:
2032 case NL80211_CHAN_HT40PLUS:
2033 case NL80211_CHAN_HT40MINUS:
2034 cfg80211_chandef_create(chandef, chandef->chan,
2035 chantype);
2036 break;
2037 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002038 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002039 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002040 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2041 chandef->width =
2042 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2043 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2044 chandef->center_freq1 =
2045 nla_get_u32(
2046 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2047 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2048 chandef->center_freq2 =
2049 nla_get_u32(
2050 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2051 }
2052
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002053 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002054 return -EINVAL;
2055
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002056 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2057 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002058 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002059
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002060 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2061 chandef->width == NL80211_CHAN_WIDTH_10) &&
2062 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2063 return -EINVAL;
2064
Johannes Berg683b6d32012-11-08 21:25:48 +01002065 return 0;
2066}
2067
Johannes Bergf444de02010-05-05 15:25:02 +02002068static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002069 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002070 struct genl_info *info)
2071{
Johannes Berg683b6d32012-11-08 21:25:48 +01002072 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002073 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002074 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002075 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002076
Jouni Malinene16821b2014-04-28 11:22:08 +03002077 if (dev)
2078 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002079 if (!nl80211_can_set_dev_channel(wdev))
2080 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002081 if (wdev)
2082 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002083
Johannes Berg683b6d32012-11-08 21:25:48 +01002084 result = nl80211_parse_chandef(rdev, info, &chandef);
2085 if (result)
2086 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002087
Johannes Berge8c9bd52012-06-06 08:18:22 +02002088 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002089 case NL80211_IFTYPE_AP:
2090 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002091 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2092 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002093 result = -EINVAL;
2094 break;
2095 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002096 if (wdev->beacon_interval) {
2097 if (!dev || !rdev->ops->set_ap_chanwidth ||
2098 !(rdev->wiphy.features &
2099 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2100 result = -EBUSY;
2101 break;
2102 }
2103
2104 /* Only allow dynamic channel width changes */
2105 if (chandef.chan != wdev->preset_chandef.chan) {
2106 result = -EBUSY;
2107 break;
2108 }
2109 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2110 if (result)
2111 break;
2112 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002113 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002114 result = 0;
2115 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002116 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002117 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002118 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002119 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002120 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002121 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002122 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002123 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002124 }
Johannes Bergf444de02010-05-05 15:25:02 +02002125
2126 return result;
2127}
2128
2129static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2130{
Johannes Berg4c476992010-10-04 21:36:35 +02002131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2132 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002133
Jouni Malinene16821b2014-04-28 11:22:08 +03002134 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002135}
2136
Bill Jordane8347eb2010-10-01 13:54:28 -04002137static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2138{
Johannes Berg43b19952010-10-07 13:10:30 +02002139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2140 struct net_device *dev = info->user_ptr[1];
2141 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002142 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002143
2144 if (!info->attrs[NL80211_ATTR_MAC])
2145 return -EINVAL;
2146
Johannes Berg43b19952010-10-07 13:10:30 +02002147 if (netif_running(dev))
2148 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002149
Johannes Berg43b19952010-10-07 13:10:30 +02002150 if (!rdev->ops->set_wds_peer)
2151 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002152
Johannes Berg43b19952010-10-07 13:10:30 +02002153 if (wdev->iftype != NL80211_IFTYPE_WDS)
2154 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002155
2156 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002157 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002158}
2159
2160
Johannes Berg55682962007-09-20 13:09:35 -04002161static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2162{
2163 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002164 struct net_device *netdev = NULL;
2165 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002166 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002167 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002168 u32 changed;
2169 u8 retry_short = 0, retry_long = 0;
2170 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002171 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002172
Johannes Berg5fe231e2013-05-08 21:45:15 +02002173 ASSERT_RTNL();
2174
Johannes Bergf444de02010-05-05 15:25:02 +02002175 /*
2176 * Try to find the wiphy and netdev. Normally this
2177 * function shouldn't need the netdev, but this is
2178 * done for backward compatibility -- previously
2179 * setting the channel was done per wiphy, but now
2180 * it is per netdev. Previous userland like hostapd
2181 * also passed a netdev to set_wiphy, so that it is
2182 * possible to let that go to the right netdev!
2183 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002184
Johannes Bergf444de02010-05-05 15:25:02 +02002185 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2186 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2187
Ying Xue7f2b8562014-01-15 10:23:45 +08002188 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002189 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002190 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002191 else
Johannes Bergf444de02010-05-05 15:25:02 +02002192 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002193 }
2194
Johannes Bergf444de02010-05-05 15:25:02 +02002195 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002196 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2197 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002198 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002199 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002200 wdev = NULL;
2201 netdev = NULL;
2202 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002203 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002204 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002205
2206 /*
2207 * end workaround code, by now the rdev is available
2208 * and locked, and wdev may or may not be NULL.
2209 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002210
2211 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002212 result = cfg80211_dev_rename(
2213 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002214
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002215 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002216 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002217
Jouni Malinen31888482008-10-30 16:59:24 +02002218 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2219 struct ieee80211_txq_params txq_params;
2220 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2221
Ying Xue7f2b8562014-01-15 10:23:45 +08002222 if (!rdev->ops->set_txq_params)
2223 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002224
Ying Xue7f2b8562014-01-15 10:23:45 +08002225 if (!netdev)
2226 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002227
Johannes Berg133a3ff2011-11-03 14:50:13 +01002228 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002229 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2230 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002231
Ying Xue7f2b8562014-01-15 10:23:45 +08002232 if (!netif_running(netdev))
2233 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002234
Jouni Malinen31888482008-10-30 16:59:24 +02002235 nla_for_each_nested(nl_txq_params,
2236 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2237 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002238 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2239 nla_data(nl_txq_params),
2240 nla_len(nl_txq_params),
2241 txq_params_policy);
2242 if (result)
2243 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002244 result = parse_txq_params(tb, &txq_params);
2245 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002246 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002247
Hila Gonene35e4d22012-06-27 17:19:42 +03002248 result = rdev_set_txq_params(rdev, netdev,
2249 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002250 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002251 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002252 }
2253 }
2254
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002255 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002256 result = __nl80211_set_channel(
2257 rdev,
2258 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2259 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002260 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002261 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002262 }
2263
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002264 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002265 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002266 enum nl80211_tx_power_setting type;
2267 int idx, mbm = 0;
2268
Johannes Bergc8442112012-10-24 10:17:18 +02002269 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2270 txp_wdev = NULL;
2271
Ying Xue7f2b8562014-01-15 10:23:45 +08002272 if (!rdev->ops->set_tx_power)
2273 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002274
2275 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2276 type = nla_get_u32(info->attrs[idx]);
2277
2278 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002279 (type != NL80211_TX_POWER_AUTOMATIC))
2280 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002281
2282 if (type != NL80211_TX_POWER_AUTOMATIC) {
2283 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2284 mbm = nla_get_u32(info->attrs[idx]);
2285 }
2286
Johannes Bergc8442112012-10-24 10:17:18 +02002287 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002288 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002289 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002290 }
2291
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002292 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2293 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2294 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002295 if ((!rdev->wiphy.available_antennas_tx &&
2296 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002297 !rdev->ops->set_antenna)
2298 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002299
2300 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2301 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2302
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002303 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002304 * available antenna masks, except for the "all" mask */
2305 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002306 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2307 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002308
Bruno Randolf7f531e02010-12-16 11:30:22 +09002309 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2310 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002311
Hila Gonene35e4d22012-06-27 17:19:42 +03002312 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002313 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002314 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002315 }
2316
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002317 changed = 0;
2318
2319 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2320 retry_short = nla_get_u8(
2321 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002322 if (retry_short == 0)
2323 return -EINVAL;
2324
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002325 changed |= WIPHY_PARAM_RETRY_SHORT;
2326 }
2327
2328 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2329 retry_long = nla_get_u8(
2330 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002331 if (retry_long == 0)
2332 return -EINVAL;
2333
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002334 changed |= WIPHY_PARAM_RETRY_LONG;
2335 }
2336
2337 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2338 frag_threshold = nla_get_u32(
2339 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002340 if (frag_threshold < 256)
2341 return -EINVAL;
2342
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002343 if (frag_threshold != (u32) -1) {
2344 /*
2345 * Fragments (apart from the last one) are required to
2346 * have even length. Make the fragmentation code
2347 * simpler by stripping LSB should someone try to use
2348 * odd threshold value.
2349 */
2350 frag_threshold &= ~0x1;
2351 }
2352 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2353 }
2354
2355 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2356 rts_threshold = nla_get_u32(
2357 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2358 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2359 }
2360
Lukáš Turek81077e82009-12-21 22:50:47 +01002361 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002362 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2363 return -EINVAL;
2364
Lukáš Turek81077e82009-12-21 22:50:47 +01002365 coverage_class = nla_get_u8(
2366 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2367 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2368 }
2369
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002370 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2371 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2372 return -EOPNOTSUPP;
2373
2374 changed |= WIPHY_PARAM_DYN_ACK;
2375 }
2376
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002377 if (changed) {
2378 u8 old_retry_short, old_retry_long;
2379 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002380 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002381
Ying Xue7f2b8562014-01-15 10:23:45 +08002382 if (!rdev->ops->set_wiphy_params)
2383 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002384
2385 old_retry_short = rdev->wiphy.retry_short;
2386 old_retry_long = rdev->wiphy.retry_long;
2387 old_frag_threshold = rdev->wiphy.frag_threshold;
2388 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002389 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002390
2391 if (changed & WIPHY_PARAM_RETRY_SHORT)
2392 rdev->wiphy.retry_short = retry_short;
2393 if (changed & WIPHY_PARAM_RETRY_LONG)
2394 rdev->wiphy.retry_long = retry_long;
2395 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2396 rdev->wiphy.frag_threshold = frag_threshold;
2397 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2398 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002399 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2400 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002401
Hila Gonene35e4d22012-06-27 17:19:42 +03002402 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002403 if (result) {
2404 rdev->wiphy.retry_short = old_retry_short;
2405 rdev->wiphy.retry_long = old_retry_long;
2406 rdev->wiphy.frag_threshold = old_frag_threshold;
2407 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002408 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002409 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002410 }
2411 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002412 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002413}
2414
Johannes Berg71bbc992012-06-15 15:30:18 +02002415static inline u64 wdev_id(struct wireless_dev *wdev)
2416{
2417 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002418 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002419}
Johannes Berg55682962007-09-20 13:09:35 -04002420
Johannes Berg683b6d32012-11-08 21:25:48 +01002421static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002422 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002423{
Johannes Berg601555c2014-11-27 17:26:56 +01002424 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2425 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002426
Johannes Berg683b6d32012-11-08 21:25:48 +01002427 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2428 chandef->chan->center_freq))
2429 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002430 switch (chandef->width) {
2431 case NL80211_CHAN_WIDTH_20_NOHT:
2432 case NL80211_CHAN_WIDTH_20:
2433 case NL80211_CHAN_WIDTH_40:
2434 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2435 cfg80211_get_chandef_type(chandef)))
2436 return -ENOBUFS;
2437 break;
2438 default:
2439 break;
2440 }
2441 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2442 return -ENOBUFS;
2443 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2444 return -ENOBUFS;
2445 if (chandef->center_freq2 &&
2446 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002447 return -ENOBUFS;
2448 return 0;
2449}
2450
Eric W. Biederman15e47302012-09-07 20:12:54 +00002451static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002452 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002453 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002454{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002455 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002456 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002457 void *hdr;
2458
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002459 if (removal)
2460 cmd = NL80211_CMD_DEL_INTERFACE;
2461
2462 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002463 if (!hdr)
2464 return -1;
2465
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002466 if (dev &&
2467 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002468 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002469 goto nla_put_failure;
2470
2471 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2472 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002473 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2474 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002475 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002476 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2477 rdev->devlist_generation ^
2478 (cfg80211_rdev_list_generation << 2)))
2479 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002480
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002481 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002482 int ret;
2483 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002484
Johannes Berg683b6d32012-11-08 21:25:48 +01002485 ret = rdev_get_channel(rdev, wdev, &chandef);
2486 if (ret == 0) {
2487 if (nl80211_send_chandef(msg, &chandef))
2488 goto nla_put_failure;
2489 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002490 }
2491
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002492 if (rdev->ops->get_tx_power) {
2493 int dbm, ret;
2494
2495 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2496 if (ret == 0 &&
2497 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2498 DBM_TO_MBM(dbm)))
2499 goto nla_put_failure;
2500 }
2501
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002502 if (wdev->ssid_len) {
2503 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2504 goto nla_put_failure;
2505 }
2506
Johannes Berg053c0952015-01-16 22:09:00 +01002507 genlmsg_end(msg, hdr);
2508 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002509
2510 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002511 genlmsg_cancel(msg, hdr);
2512 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002513}
2514
2515static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2516{
2517 int wp_idx = 0;
2518 int if_idx = 0;
2519 int wp_start = cb->args[0];
2520 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002521 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002522 struct wireless_dev *wdev;
2523
Johannes Berg5fe231e2013-05-08 21:45:15 +02002524 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002525 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2526 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002527 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002528 if (wp_idx < wp_start) {
2529 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002530 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002531 }
Johannes Berg55682962007-09-20 13:09:35 -04002532 if_idx = 0;
2533
Johannes Berg53873f12016-05-03 16:52:04 +03002534 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002535 if (if_idx < if_start) {
2536 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002537 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002538 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002539 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002540 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002541 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002542 goto out;
2543 }
2544 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002545 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002546
2547 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002548 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002549 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002550 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002551
2552 cb->args[0] = wp_idx;
2553 cb->args[1] = if_idx;
2554
2555 return skb->len;
2556}
2557
2558static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2559{
2560 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002562 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002563
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002564 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002565 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002566 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002567
Eric W. Biederman15e47302012-09-07 20:12:54 +00002568 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002569 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002570 nlmsg_free(msg);
2571 return -ENOBUFS;
2572 }
Johannes Berg55682962007-09-20 13:09:35 -04002573
Johannes Berg134e6372009-07-10 09:51:34 +00002574 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002575}
2576
Michael Wu66f7ac52008-01-31 19:48:22 +01002577static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2578 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2579 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2580 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2581 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2582 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002583 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002584};
2585
2586static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2587{
2588 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2589 int flag;
2590
2591 *mntrflags = 0;
2592
2593 if (!nla)
2594 return -EINVAL;
2595
2596 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2597 nla, mntr_flags_policy))
2598 return -EINVAL;
2599
2600 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2601 if (flags[flag])
2602 *mntrflags |= (1<<flag);
2603
2604 return 0;
2605}
2606
Johannes Berg9bc383d2009-11-19 11:55:19 +01002607static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002608 struct net_device *netdev, u8 use_4addr,
2609 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002610{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002611 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002612 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002613 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002614 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002615 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002616
2617 switch (iftype) {
2618 case NL80211_IFTYPE_AP_VLAN:
2619 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2620 return 0;
2621 break;
2622 case NL80211_IFTYPE_STATION:
2623 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2624 return 0;
2625 break;
2626 default:
2627 break;
2628 }
2629
2630 return -EOPNOTSUPP;
2631}
2632
Johannes Berg55682962007-09-20 13:09:35 -04002633static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2634{
Johannes Berg4c476992010-10-04 21:36:35 +02002635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002636 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002637 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002638 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002639 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002640 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002641 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002642
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002643 memset(&params, 0, sizeof(params));
2644
Johannes Berg04a773a2009-04-19 21:24:32 +02002645 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002646
Johannes Berg723b0382008-09-16 20:22:09 +02002647 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002648 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002649 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002650 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002651 if (ntype > NL80211_IFTYPE_MAX)
2652 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002653 }
2654
Johannes Berg92ffe052008-09-16 20:39:36 +02002655 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002656 struct wireless_dev *wdev = dev->ieee80211_ptr;
2657
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (ntype != NL80211_IFTYPE_MESH_POINT)
2659 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002660 if (netif_running(dev))
2661 return -EBUSY;
2662
2663 wdev_lock(wdev);
2664 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2665 IEEE80211_MAX_MESH_ID_LEN);
2666 wdev->mesh_id_up_len =
2667 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2668 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2669 wdev->mesh_id_up_len);
2670 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002671 }
2672
Felix Fietkau8b787642009-11-10 18:53:10 +01002673 if (info->attrs[NL80211_ATTR_4ADDR]) {
2674 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2675 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002676 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002677 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002678 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002679 } else {
2680 params.use_4addr = -1;
2681 }
2682
Johannes Berg92ffe052008-09-16 20:39:36 +02002683 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002684 if (ntype != NL80211_IFTYPE_MONITOR)
2685 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002686 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2687 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002688 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002689 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002690
2691 flags = &_flags;
2692 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002693 }
Johannes Berg3b858752009-03-12 09:55:09 +01002694
Luciano Coelho18003292013-08-29 13:26:57 +03002695 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002696 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2697 return -EOPNOTSUPP;
2698
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002699 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002700 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002701 else
2702 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002703
Johannes Berg9bc383d2009-11-19 11:55:19 +01002704 if (!err && params.use_4addr != -1)
2705 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2706
Johannes Berg55682962007-09-20 13:09:35 -04002707 return err;
2708}
2709
2710static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2711{
Johannes Berg4c476992010-10-04 21:36:35 +02002712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002713 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002714 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002715 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002716 int err;
2717 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002718 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002719
Johannes Berg78f22b62014-03-24 17:57:27 +01002720 /* to avoid failing a new interface creation due to pending removal */
2721 cfg80211_destroy_ifaces(rdev);
2722
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002723 memset(&params, 0, sizeof(params));
2724
Johannes Berg55682962007-09-20 13:09:35 -04002725 if (!info->attrs[NL80211_ATTR_IFNAME])
2726 return -EINVAL;
2727
2728 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2729 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2730 if (type > NL80211_IFTYPE_MAX)
2731 return -EINVAL;
2732 }
2733
Johannes Berg79c97e92009-07-07 03:56:12 +02002734 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002735 !(rdev->wiphy.interface_modes & (1 << type)))
2736 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002737
Ben Greeare8f479b2014-10-22 12:23:05 -07002738 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2739 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2740 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002741 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2742 ETH_ALEN);
2743 if (!is_valid_ether_addr(params.macaddr))
2744 return -EADDRNOTAVAIL;
2745 }
2746
Johannes Berg9bc383d2009-11-19 11:55:19 +01002747 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002748 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002749 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002750 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002751 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002752 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002753
Michael Wu66f7ac52008-01-31 19:48:22 +01002754 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2755 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2756 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002757
Luciano Coelho18003292013-08-29 13:26:57 +03002758 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002759 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2760 return -EOPNOTSUPP;
2761
Johannes Berga18c7192015-02-24 10:56:42 +01002762 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2763 if (!msg)
2764 return -ENOMEM;
2765
Hila Gonene35e4d22012-06-27 17:19:42 +03002766 wdev = rdev_add_virtual_intf(rdev,
2767 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002768 NET_NAME_USER, type, err ? NULL : &flags,
2769 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002770 if (WARN_ON(!wdev)) {
2771 nlmsg_free(msg);
2772 return -EPROTO;
2773 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002774 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002775 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002776 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002777
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002778 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002779 wdev->owner_nlportid = info->snd_portid;
2780
Johannes Berg98104fde2012-06-16 00:19:54 +02002781 switch (type) {
2782 case NL80211_IFTYPE_MESH_POINT:
2783 if (!info->attrs[NL80211_ATTR_MESH_ID])
2784 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002785 wdev_lock(wdev);
2786 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2787 IEEE80211_MAX_MESH_ID_LEN);
2788 wdev->mesh_id_up_len =
2789 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2790 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2791 wdev->mesh_id_up_len);
2792 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002793 break;
2794 case NL80211_IFTYPE_P2P_DEVICE:
2795 /*
2796 * P2P Device doesn't have a netdev, so doesn't go
2797 * through the netdev notifier and must be added here
2798 */
2799 mutex_init(&wdev->mtx);
2800 INIT_LIST_HEAD(&wdev->event_list);
2801 spin_lock_init(&wdev->event_lock);
2802 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2803 spin_lock_init(&wdev->mgmt_registrations_lock);
2804
Johannes Berg98104fde2012-06-16 00:19:54 +02002805 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002806 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002807 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002808 break;
2809 default:
2810 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002811 }
2812
Eric W. Biederman15e47302012-09-07 20:12:54 +00002813 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002814 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002815 nlmsg_free(msg);
2816 return -ENOBUFS;
2817 }
2818
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002819 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2820 if (event) {
2821 if (nl80211_send_iface(event, 0, 0, 0,
2822 rdev, wdev, false) < 0) {
2823 nlmsg_free(event);
2824 goto out;
2825 }
2826
2827 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2828 event, 0, NL80211_MCGRP_CONFIG,
2829 GFP_KERNEL);
2830 }
2831
2832out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002833 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002834}
2835
2836static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2837{
Johannes Berg4c476992010-10-04 21:36:35 +02002838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002839 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002840 struct sk_buff *msg;
2841 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002842
Johannes Berg4c476992010-10-04 21:36:35 +02002843 if (!rdev->ops->del_virtual_intf)
2844 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002845
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002846 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2847 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2848 nlmsg_free(msg);
2849 msg = NULL;
2850 }
2851
Johannes Berg84efbb82012-06-16 00:00:26 +02002852 /*
2853 * If we remove a wireless device without a netdev then clear
2854 * user_ptr[1] so that nl80211_post_doit won't dereference it
2855 * to check if it needs to do dev_put(). Otherwise it crashes
2856 * since the wdev has been freed, unlike with a netdev where
2857 * we need the dev_put() for the netdev to really be freed.
2858 */
2859 if (!wdev->netdev)
2860 info->user_ptr[1] = NULL;
2861
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002862 status = rdev_del_virtual_intf(rdev, wdev);
2863 if (status >= 0 && msg)
2864 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2865 msg, 0, NL80211_MCGRP_CONFIG,
2866 GFP_KERNEL);
2867 else
2868 nlmsg_free(msg);
2869
2870 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002871}
2872
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002873static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2874{
2875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2876 struct net_device *dev = info->user_ptr[1];
2877 u16 noack_map;
2878
2879 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2880 return -EINVAL;
2881
2882 if (!rdev->ops->set_noack_map)
2883 return -EOPNOTSUPP;
2884
2885 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2886
Hila Gonene35e4d22012-06-27 17:19:42 +03002887 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002888}
2889
Johannes Berg41ade002007-12-19 02:03:29 +01002890struct get_key_cookie {
2891 struct sk_buff *msg;
2892 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002893 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002894};
2895
2896static void get_key_callback(void *c, struct key_params *params)
2897{
Johannes Bergb9454e82009-07-08 13:29:08 +02002898 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002899 struct get_key_cookie *cookie = c;
2900
David S. Miller9360ffd2012-03-29 04:41:26 -04002901 if ((params->key &&
2902 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2903 params->key_len, params->key)) ||
2904 (params->seq &&
2905 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2906 params->seq_len, params->seq)) ||
2907 (params->cipher &&
2908 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2909 params->cipher)))
2910 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002911
Johannes Bergb9454e82009-07-08 13:29:08 +02002912 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2913 if (!key)
2914 goto nla_put_failure;
2915
David S. Miller9360ffd2012-03-29 04:41:26 -04002916 if ((params->key &&
2917 nla_put(cookie->msg, NL80211_KEY_DATA,
2918 params->key_len, params->key)) ||
2919 (params->seq &&
2920 nla_put(cookie->msg, NL80211_KEY_SEQ,
2921 params->seq_len, params->seq)) ||
2922 (params->cipher &&
2923 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2924 params->cipher)))
2925 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002926
David S. Miller9360ffd2012-03-29 04:41:26 -04002927 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2928 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002929
2930 nla_nest_end(cookie->msg, key);
2931
Johannes Berg41ade002007-12-19 02:03:29 +01002932 return;
2933 nla_put_failure:
2934 cookie->error = 1;
2935}
2936
2937static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2938{
Johannes Berg4c476992010-10-04 21:36:35 +02002939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002940 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002941 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002942 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002943 const u8 *mac_addr = NULL;
2944 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002945 struct get_key_cookie cookie = {
2946 .error = 0,
2947 };
2948 void *hdr;
2949 struct sk_buff *msg;
2950
2951 if (info->attrs[NL80211_ATTR_KEY_IDX])
2952 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2953
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002954 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002955 return -EINVAL;
2956
2957 if (info->attrs[NL80211_ATTR_MAC])
2958 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2959
Johannes Berge31b8212010-10-05 19:39:30 +02002960 pairwise = !!mac_addr;
2961 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2962 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2963 if (kt >= NUM_NL80211_KEYTYPES)
2964 return -EINVAL;
2965 if (kt != NL80211_KEYTYPE_GROUP &&
2966 kt != NL80211_KEYTYPE_PAIRWISE)
2967 return -EINVAL;
2968 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2969 }
2970
Johannes Berg4c476992010-10-04 21:36:35 +02002971 if (!rdev->ops->get_key)
2972 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002973
Johannes Berg0fa7b392015-01-23 11:10:12 +01002974 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2975 return -ENOENT;
2976
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002977 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002978 if (!msg)
2979 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002980
Eric W. Biederman15e47302012-09-07 20:12:54 +00002981 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002982 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002983 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002984 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002985
2986 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002987 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002988
David S. Miller9360ffd2012-03-29 04:41:26 -04002989 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2990 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2991 goto nla_put_failure;
2992 if (mac_addr &&
2993 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2994 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002995
Hila Gonene35e4d22012-06-27 17:19:42 +03002996 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2997 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002998
2999 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003000 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003001
3002 if (cookie.error)
3003 goto nla_put_failure;
3004
3005 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003006 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003007
3008 nla_put_failure:
3009 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003010 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003011 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003012 return err;
3013}
3014
3015static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3016{
Johannes Berg4c476992010-10-04 21:36:35 +02003017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003018 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003019 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003020 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003021
Johannes Bergb9454e82009-07-08 13:29:08 +02003022 err = nl80211_parse_key(info, &key);
3023 if (err)
3024 return err;
3025
3026 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003027 return -EINVAL;
3028
Johannes Bergb9454e82009-07-08 13:29:08 +02003029 /* only support setting default key */
3030 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003031 return -EINVAL;
3032
Johannes Bergfffd0932009-07-08 14:22:54 +02003033 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003034
3035 if (key.def) {
3036 if (!rdev->ops->set_default_key) {
3037 err = -EOPNOTSUPP;
3038 goto out;
3039 }
3040
3041 err = nl80211_key_allowed(dev->ieee80211_ptr);
3042 if (err)
3043 goto out;
3044
Hila Gonene35e4d22012-06-27 17:19:42 +03003045 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003046 key.def_uni, key.def_multi);
3047
3048 if (err)
3049 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003050
Johannes Berg3d23e342009-09-29 23:27:28 +02003051#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003052 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003053#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003054 } else {
3055 if (key.def_uni || !key.def_multi) {
3056 err = -EINVAL;
3057 goto out;
3058 }
3059
3060 if (!rdev->ops->set_default_mgmt_key) {
3061 err = -EOPNOTSUPP;
3062 goto out;
3063 }
3064
3065 err = nl80211_key_allowed(dev->ieee80211_ptr);
3066 if (err)
3067 goto out;
3068
Hila Gonene35e4d22012-06-27 17:19:42 +03003069 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003070 if (err)
3071 goto out;
3072
3073#ifdef CONFIG_CFG80211_WEXT
3074 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3075#endif
3076 }
3077
3078 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003079 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003080
Johannes Berg41ade002007-12-19 02:03:29 +01003081 return err;
3082}
3083
3084static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3085{
Johannes Berg4c476992010-10-04 21:36:35 +02003086 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003087 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003088 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003089 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003090 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003091
Johannes Bergb9454e82009-07-08 13:29:08 +02003092 err = nl80211_parse_key(info, &key);
3093 if (err)
3094 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003095
Johannes Bergb9454e82009-07-08 13:29:08 +02003096 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003097 return -EINVAL;
3098
Johannes Berg41ade002007-12-19 02:03:29 +01003099 if (info->attrs[NL80211_ATTR_MAC])
3100 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3101
Johannes Berge31b8212010-10-05 19:39:30 +02003102 if (key.type == -1) {
3103 if (mac_addr)
3104 key.type = NL80211_KEYTYPE_PAIRWISE;
3105 else
3106 key.type = NL80211_KEYTYPE_GROUP;
3107 }
3108
3109 /* for now */
3110 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3111 key.type != NL80211_KEYTYPE_GROUP)
3112 return -EINVAL;
3113
Johannes Berg4c476992010-10-04 21:36:35 +02003114 if (!rdev->ops->add_key)
3115 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003116
Johannes Berge31b8212010-10-05 19:39:30 +02003117 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3118 key.type == NL80211_KEYTYPE_PAIRWISE,
3119 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003120 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003121
3122 wdev_lock(dev->ieee80211_ptr);
3123 err = nl80211_key_allowed(dev->ieee80211_ptr);
3124 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003125 err = rdev_add_key(rdev, dev, key.idx,
3126 key.type == NL80211_KEYTYPE_PAIRWISE,
3127 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003128 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003129
Johannes Berg41ade002007-12-19 02:03:29 +01003130 return err;
3131}
3132
3133static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3134{
Johannes Berg4c476992010-10-04 21:36:35 +02003135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003136 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003137 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003138 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003139 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003140
Johannes Bergb9454e82009-07-08 13:29:08 +02003141 err = nl80211_parse_key(info, &key);
3142 if (err)
3143 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003144
3145 if (info->attrs[NL80211_ATTR_MAC])
3146 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3147
Johannes Berge31b8212010-10-05 19:39:30 +02003148 if (key.type == -1) {
3149 if (mac_addr)
3150 key.type = NL80211_KEYTYPE_PAIRWISE;
3151 else
3152 key.type = NL80211_KEYTYPE_GROUP;
3153 }
3154
3155 /* for now */
3156 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3157 key.type != NL80211_KEYTYPE_GROUP)
3158 return -EINVAL;
3159
Johannes Berg4c476992010-10-04 21:36:35 +02003160 if (!rdev->ops->del_key)
3161 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003162
Johannes Bergfffd0932009-07-08 14:22:54 +02003163 wdev_lock(dev->ieee80211_ptr);
3164 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003165
Johannes Berg0fa7b392015-01-23 11:10:12 +01003166 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003167 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3168 err = -ENOENT;
3169
Johannes Bergfffd0932009-07-08 14:22:54 +02003170 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003171 err = rdev_del_key(rdev, dev, key.idx,
3172 key.type == NL80211_KEYTYPE_PAIRWISE,
3173 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003174
Johannes Berg3d23e342009-09-29 23:27:28 +02003175#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003176 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003177 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003178 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003179 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003180 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3181 }
3182#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003183 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003184
Johannes Berg41ade002007-12-19 02:03:29 +01003185 return err;
3186}
3187
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303188/* This function returns an error or the number of nested attributes */
3189static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3190{
3191 struct nlattr *attr;
3192 int n_entries = 0, tmp;
3193
3194 nla_for_each_nested(attr, nl_attr, tmp) {
3195 if (nla_len(attr) != ETH_ALEN)
3196 return -EINVAL;
3197
3198 n_entries++;
3199 }
3200
3201 return n_entries;
3202}
3203
3204/*
3205 * This function parses ACL information and allocates memory for ACL data.
3206 * On successful return, the calling function is responsible to free the
3207 * ACL buffer returned by this function.
3208 */
3209static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3210 struct genl_info *info)
3211{
3212 enum nl80211_acl_policy acl_policy;
3213 struct nlattr *attr;
3214 struct cfg80211_acl_data *acl;
3215 int i = 0, n_entries, tmp;
3216
3217 if (!wiphy->max_acl_mac_addrs)
3218 return ERR_PTR(-EOPNOTSUPP);
3219
3220 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3221 return ERR_PTR(-EINVAL);
3222
3223 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3224 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3225 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3226 return ERR_PTR(-EINVAL);
3227
3228 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3229 return ERR_PTR(-EINVAL);
3230
3231 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3232 if (n_entries < 0)
3233 return ERR_PTR(n_entries);
3234
3235 if (n_entries > wiphy->max_acl_mac_addrs)
3236 return ERR_PTR(-ENOTSUPP);
3237
3238 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3239 GFP_KERNEL);
3240 if (!acl)
3241 return ERR_PTR(-ENOMEM);
3242
3243 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3244 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3245 i++;
3246 }
3247
3248 acl->n_acl_entries = n_entries;
3249 acl->acl_policy = acl_policy;
3250
3251 return acl;
3252}
3253
3254static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3255{
3256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3257 struct net_device *dev = info->user_ptr[1];
3258 struct cfg80211_acl_data *acl;
3259 int err;
3260
3261 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3262 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3263 return -EOPNOTSUPP;
3264
3265 if (!dev->ieee80211_ptr->beacon_interval)
3266 return -EINVAL;
3267
3268 acl = parse_acl_data(&rdev->wiphy, info);
3269 if (IS_ERR(acl))
3270 return PTR_ERR(acl);
3271
3272 err = rdev_set_mac_acl(rdev, dev, acl);
3273
3274 kfree(acl);
3275
3276 return err;
3277}
3278
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003279static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003280 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003281{
Johannes Berg88600202012-02-13 15:17:18 +01003282 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003283
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003284 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3285 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3286 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3287 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003288 return -EINVAL;
3289
Johannes Berg88600202012-02-13 15:17:18 +01003290 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003291
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003292 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3293 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3294 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003295 if (!bcn->head_len)
3296 return -EINVAL;
3297 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003298 }
3299
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003300 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3301 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3302 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003303 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003304 }
3305
Johannes Berg4c476992010-10-04 21:36:35 +02003306 if (!haveinfo)
3307 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003308
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003309 if (attrs[NL80211_ATTR_IE]) {
3310 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3311 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003312 }
3313
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003314 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003315 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003316 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003317 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003318 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003319 }
3320
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003321 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003322 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003323 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003324 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003325 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003326 }
3327
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003328 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3329 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3330 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003331 }
3332
Johannes Berg88600202012-02-13 15:17:18 +01003333 return 0;
3334}
3335
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003336static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3337 struct cfg80211_ap_settings *params)
3338{
3339 struct wireless_dev *wdev;
3340 bool ret = false;
3341
Johannes Berg53873f12016-05-03 16:52:04 +03003342 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003343 if (wdev->iftype != NL80211_IFTYPE_AP &&
3344 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3345 continue;
3346
Johannes Berg683b6d32012-11-08 21:25:48 +01003347 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003348 continue;
3349
Johannes Berg683b6d32012-11-08 21:25:48 +01003350 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003351 ret = true;
3352 break;
3353 }
3354
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003355 return ret;
3356}
3357
Jouni Malinene39e5b52012-09-30 19:29:39 +03003358static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3359 enum nl80211_auth_type auth_type,
3360 enum nl80211_commands cmd)
3361{
3362 if (auth_type > NL80211_AUTHTYPE_MAX)
3363 return false;
3364
3365 switch (cmd) {
3366 case NL80211_CMD_AUTHENTICATE:
3367 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3368 auth_type == NL80211_AUTHTYPE_SAE)
3369 return false;
3370 return true;
3371 case NL80211_CMD_CONNECT:
3372 case NL80211_CMD_START_AP:
3373 /* SAE not supported yet */
3374 if (auth_type == NL80211_AUTHTYPE_SAE)
3375 return false;
3376 return true;
3377 default:
3378 return false;
3379 }
3380}
3381
Johannes Berg88600202012-02-13 15:17:18 +01003382static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3383{
3384 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3385 struct net_device *dev = info->user_ptr[1];
3386 struct wireless_dev *wdev = dev->ieee80211_ptr;
3387 struct cfg80211_ap_settings params;
3388 int err;
3389
3390 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3391 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3392 return -EOPNOTSUPP;
3393
3394 if (!rdev->ops->start_ap)
3395 return -EOPNOTSUPP;
3396
3397 if (wdev->beacon_interval)
3398 return -EALREADY;
3399
3400 memset(&params, 0, sizeof(params));
3401
3402 /* these are required for START_AP */
3403 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3404 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3405 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3406 return -EINVAL;
3407
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003408 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003409 if (err)
3410 return err;
3411
3412 params.beacon_interval =
3413 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3414 params.dtim_period =
3415 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3416
3417 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3418 if (err)
3419 return err;
3420
3421 /*
3422 * In theory, some of these attributes should be required here
3423 * but since they were not used when the command was originally
3424 * added, keep them optional for old user space programs to let
3425 * them continue to work with drivers that do not need the
3426 * additional information -- drivers must check!
3427 */
3428 if (info->attrs[NL80211_ATTR_SSID]) {
3429 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3430 params.ssid_len =
3431 nla_len(info->attrs[NL80211_ATTR_SSID]);
3432 if (params.ssid_len == 0 ||
3433 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3434 return -EINVAL;
3435 }
3436
3437 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3438 params.hidden_ssid = nla_get_u32(
3439 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3440 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3441 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3442 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3443 return -EINVAL;
3444 }
3445
3446 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3447
3448 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3449 params.auth_type = nla_get_u32(
3450 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003451 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3452 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003453 return -EINVAL;
3454 } else
3455 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3456
3457 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3458 NL80211_MAX_NR_CIPHER_SUITES);
3459 if (err)
3460 return err;
3461
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303462 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3463 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3464 return -EOPNOTSUPP;
3465 params.inactivity_timeout = nla_get_u16(
3466 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3467 }
3468
Johannes Berg53cabad2012-11-14 15:17:28 +01003469 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3470 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3471 return -EINVAL;
3472 params.p2p_ctwindow =
3473 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3474 if (params.p2p_ctwindow > 127)
3475 return -EINVAL;
3476 if (params.p2p_ctwindow != 0 &&
3477 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3478 return -EINVAL;
3479 }
3480
3481 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3482 u8 tmp;
3483
3484 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3485 return -EINVAL;
3486 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3487 if (tmp > 1)
3488 return -EINVAL;
3489 params.p2p_opp_ps = tmp;
3490 if (params.p2p_opp_ps != 0 &&
3491 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3492 return -EINVAL;
3493 }
3494
Johannes Bergaa430da2012-05-16 23:50:18 +02003495 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003496 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3497 if (err)
3498 return err;
3499 } else if (wdev->preset_chandef.chan) {
3500 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003501 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003502 return -EINVAL;
3503
Arik Nemtsov923b3522015-07-08 15:41:44 +03003504 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3505 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003506 return -EINVAL;
3507
Eliad Peller18998c32014-09-10 14:07:34 +03003508 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3509 params.smps_mode =
3510 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3511 switch (params.smps_mode) {
3512 case NL80211_SMPS_OFF:
3513 break;
3514 case NL80211_SMPS_STATIC:
3515 if (!(rdev->wiphy.features &
3516 NL80211_FEATURE_STATIC_SMPS))
3517 return -EINVAL;
3518 break;
3519 case NL80211_SMPS_DYNAMIC:
3520 if (!(rdev->wiphy.features &
3521 NL80211_FEATURE_DYNAMIC_SMPS))
3522 return -EINVAL;
3523 break;
3524 default:
3525 return -EINVAL;
3526 }
3527 } else {
3528 params.smps_mode = NL80211_SMPS_OFF;
3529 }
3530
Ola Olsson4baf6be2015-10-29 07:04:58 +01003531 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3532 params.acl = parse_acl_data(&rdev->wiphy, info);
3533 if (IS_ERR(params.acl))
3534 return PTR_ERR(params.acl);
3535 }
3536
Lior David34d50512016-01-28 10:58:25 +02003537 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02003538 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
Lior David34d50512016-01-28 10:58:25 +02003539 return -EOPNOTSUPP;
3540
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003541 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003542 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003543 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003544 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003545 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003546 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003547 wdev->ssid_len = params.ssid_len;
3548 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003549 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003550 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303551
3552 kfree(params.acl);
3553
Johannes Berg56d18932011-05-09 18:41:15 +02003554 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003555}
3556
Johannes Berg88600202012-02-13 15:17:18 +01003557static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3558{
3559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3560 struct net_device *dev = info->user_ptr[1];
3561 struct wireless_dev *wdev = dev->ieee80211_ptr;
3562 struct cfg80211_beacon_data params;
3563 int err;
3564
3565 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3566 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3567 return -EOPNOTSUPP;
3568
3569 if (!rdev->ops->change_beacon)
3570 return -EOPNOTSUPP;
3571
3572 if (!wdev->beacon_interval)
3573 return -EINVAL;
3574
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003575 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003576 if (err)
3577 return err;
3578
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003579 wdev_lock(wdev);
3580 err = rdev_change_beacon(rdev, dev, &params);
3581 wdev_unlock(wdev);
3582
3583 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003584}
3585
3586static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003587{
Johannes Berg4c476992010-10-04 21:36:35 +02003588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3589 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003590
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003591 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003592}
3593
Johannes Berg5727ef12007-12-19 02:03:34 +01003594static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3595 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3596 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3597 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003598 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003599 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003600 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003601};
3602
Johannes Bergeccb8e82009-05-11 21:57:56 +03003603static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003604 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003605 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003606{
3607 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003608 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003609 int flag;
3610
Johannes Bergeccb8e82009-05-11 21:57:56 +03003611 /*
3612 * Try parsing the new attribute first so userspace
3613 * can specify both for older kernels.
3614 */
3615 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3616 if (nla) {
3617 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003618
Johannes Bergeccb8e82009-05-11 21:57:56 +03003619 sta_flags = nla_data(nla);
3620 params->sta_flags_mask = sta_flags->mask;
3621 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003622 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003623 if ((params->sta_flags_mask |
3624 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3625 return -EINVAL;
3626 return 0;
3627 }
3628
3629 /* if present, parse the old attribute */
3630
3631 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003632 if (!nla)
3633 return 0;
3634
3635 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3636 nla, sta_flags_policy))
3637 return -EINVAL;
3638
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003639 /*
3640 * Only allow certain flags for interface types so that
3641 * other attributes are silently ignored. Remember that
3642 * this is backward compatibility code with old userspace
3643 * and shouldn't be hit in other cases anyway.
3644 */
3645 switch (iftype) {
3646 case NL80211_IFTYPE_AP:
3647 case NL80211_IFTYPE_AP_VLAN:
3648 case NL80211_IFTYPE_P2P_GO:
3649 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3650 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3651 BIT(NL80211_STA_FLAG_WME) |
3652 BIT(NL80211_STA_FLAG_MFP);
3653 break;
3654 case NL80211_IFTYPE_P2P_CLIENT:
3655 case NL80211_IFTYPE_STATION:
3656 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3657 BIT(NL80211_STA_FLAG_TDLS_PEER);
3658 break;
3659 case NL80211_IFTYPE_MESH_POINT:
3660 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3661 BIT(NL80211_STA_FLAG_MFP) |
3662 BIT(NL80211_STA_FLAG_AUTHORIZED);
3663 default:
3664 return -EINVAL;
3665 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003666
Johannes Berg3383b5a2012-05-10 20:14:43 +02003667 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3668 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003669 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003670
Johannes Berg3383b5a2012-05-10 20:14:43 +02003671 /* no longer support new API additions in old API */
3672 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3673 return -EINVAL;
3674 }
3675 }
3676
Johannes Berg5727ef12007-12-19 02:03:34 +01003677 return 0;
3678}
3679
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003680static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3681 int attr)
3682{
3683 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003684 u32 bitrate;
3685 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003686 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003687
3688 rate = nla_nest_start(msg, attr);
3689 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003690 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003691
3692 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3693 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003694 /* report 16-bit bitrate only if we can */
3695 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003696 if (bitrate > 0 &&
3697 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3698 return false;
3699 if (bitrate_compat > 0 &&
3700 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3701 return false;
3702
Johannes Bergb51f3be2015-01-15 16:14:02 +01003703 switch (info->bw) {
3704 case RATE_INFO_BW_5:
3705 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3706 break;
3707 case RATE_INFO_BW_10:
3708 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3709 break;
3710 default:
3711 WARN_ON(1);
3712 /* fall through */
3713 case RATE_INFO_BW_20:
3714 rate_flg = 0;
3715 break;
3716 case RATE_INFO_BW_40:
3717 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3718 break;
3719 case RATE_INFO_BW_80:
3720 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3721 break;
3722 case RATE_INFO_BW_160:
3723 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3724 break;
3725 }
3726
3727 if (rate_flg && nla_put_flag(msg, rate_flg))
3728 return false;
3729
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003730 if (info->flags & RATE_INFO_FLAGS_MCS) {
3731 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3732 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003733 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3734 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3735 return false;
3736 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3737 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3738 return false;
3739 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3740 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003741 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3742 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3743 return false;
3744 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003745
3746 nla_nest_end(msg, rate);
3747 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003748}
3749
Felix Fietkau119363c2013-04-22 16:29:30 +02003750static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3751 int id)
3752{
3753 void *attr;
3754 int i = 0;
3755
3756 if (!mask)
3757 return true;
3758
3759 attr = nla_nest_start(msg, id);
3760 if (!attr)
3761 return false;
3762
3763 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3764 if (!(mask & BIT(i)))
3765 continue;
3766
3767 if (nla_put_u8(msg, i, signal[i]))
3768 return false;
3769 }
3770
3771 nla_nest_end(msg, attr);
3772
3773 return true;
3774}
3775
Johannes Bergcf5ead82014-11-14 17:14:00 +01003776static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3777 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003778 struct cfg80211_registered_device *rdev,
3779 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003780 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003781{
3782 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003783 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003784
Johannes Bergcf5ead82014-11-14 17:14:00 +01003785 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003786 if (!hdr)
3787 return -1;
3788
David S. Miller9360ffd2012-03-29 04:41:26 -04003789 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3790 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3791 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3792 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003793
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003794 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3795 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003796 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003797
3798#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003799 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303800 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003801 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3802 sinfo->memb)) \
3803 goto nla_put_failure; \
3804 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003805#define PUT_SINFO_U64(attr, memb) do { \
3806 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3807 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3808 sinfo->memb, NL80211_STA_INFO_PAD)) \
3809 goto nla_put_failure; \
3810 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003811
3812 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3813 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3814
3815 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3816 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003817 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003818 (u32)sinfo->rx_bytes))
3819 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003820
3821 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3822 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003823 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3824 (u32)sinfo->tx_bytes))
3825 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003826
Johannes Bergd686b922016-04-26 09:54:11 +02003827 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3828 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003829 PUT_SINFO(LLID, llid, u16);
3830 PUT_SINFO(PLID, plid, u16);
3831 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003832 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003833
John W. Linville66266b32012-03-15 13:25:41 -04003834 switch (rdev->wiphy.signal_type) {
3835 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003836 PUT_SINFO(SIGNAL, signal, u8);
3837 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003838 break;
3839 default:
3840 break;
3841 }
Johannes Berg319090b2014-11-17 14:08:11 +01003842 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003843 if (!nl80211_put_signal(msg, sinfo->chains,
3844 sinfo->chain_signal,
3845 NL80211_STA_INFO_CHAIN_SIGNAL))
3846 goto nla_put_failure;
3847 }
Johannes Berg319090b2014-11-17 14:08:11 +01003848 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003849 if (!nl80211_put_signal(msg, sinfo->chains,
3850 sinfo->chain_signal_avg,
3851 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3852 goto nla_put_failure;
3853 }
Johannes Berg319090b2014-11-17 14:08:11 +01003854 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003855 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3856 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003857 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003858 }
Johannes Berg319090b2014-11-17 14:08:11 +01003859 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003860 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3861 NL80211_STA_INFO_RX_BITRATE))
3862 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003863 }
Johannes Berg319090b2014-11-17 14:08:11 +01003864
3865 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3866 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3867 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3868 PUT_SINFO(TX_FAILED, tx_failed, u32);
3869 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3870 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3871 PUT_SINFO(LOCAL_PM, local_pm, u32);
3872 PUT_SINFO(PEER_PM, peer_pm, u32);
3873 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3874
3875 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003876 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3877 if (!bss_param)
3878 goto nla_put_failure;
3879
David S. Miller9360ffd2012-03-29 04:41:26 -04003880 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3881 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3882 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3883 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3884 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3885 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3886 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3887 sinfo->bss_param.dtim_period) ||
3888 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3889 sinfo->bss_param.beacon_interval))
3890 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003891
3892 nla_nest_end(msg, bss_param);
3893 }
Johannes Berg319090b2014-11-17 14:08:11 +01003894 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003895 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3896 sizeof(struct nl80211_sta_flag_update),
3897 &sinfo->sta_flags))
3898 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003899
Johannes Bergd686b922016-04-26 09:54:11 +02003900 PUT_SINFO_U64(T_OFFSET, t_offset);
3901 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3902 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003903 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003904
3905#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003906#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003907
3908 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3909 struct nlattr *tidsattr;
3910 int tid;
3911
3912 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3913 if (!tidsattr)
3914 goto nla_put_failure;
3915
3916 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3917 struct cfg80211_tid_stats *tidstats;
3918 struct nlattr *tidattr;
3919
3920 tidstats = &sinfo->pertid[tid];
3921
3922 if (!tidstats->filled)
3923 continue;
3924
3925 tidattr = nla_nest_start(msg, tid + 1);
3926 if (!tidattr)
3927 goto nla_put_failure;
3928
Johannes Bergd686b922016-04-26 09:54:11 +02003929#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003930 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003931 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3932 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003933 goto nla_put_failure; \
3934 } while (0)
3935
Johannes Bergd686b922016-04-26 09:54:11 +02003936 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
3937 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
3938 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
3939 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01003940
Johannes Bergd686b922016-04-26 09:54:11 +02003941#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003942 nla_nest_end(msg, tidattr);
3943 }
3944
3945 nla_nest_end(msg, tidsattr);
3946 }
3947
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003948 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003949
Johannes Berg319090b2014-11-17 14:08:11 +01003950 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003951 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3952 sinfo->assoc_req_ies))
3953 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003954
Johannes Berg053c0952015-01-16 22:09:00 +01003955 genlmsg_end(msg, hdr);
3956 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003957
3958 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003959 genlmsg_cancel(msg, hdr);
3960 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003961}
3962
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003963static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003964 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003965{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003966 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003967 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003968 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003969 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003970 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003971 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003972
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003973 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003974 if (err)
3975 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003976
Johannes Berg97990a02013-04-19 01:02:55 +02003977 if (!wdev->netdev) {
3978 err = -EINVAL;
3979 goto out_err;
3980 }
3981
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003982 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003983 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003984 goto out_err;
3985 }
3986
Johannes Bergbba95fe2008-07-29 13:22:51 +02003987 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003988 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003989 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003990 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003991 if (err == -ENOENT)
3992 break;
3993 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003994 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003995
Johannes Bergcf5ead82014-11-14 17:14:00 +01003996 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003997 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003998 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003999 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004000 &sinfo) < 0)
4001 goto out;
4002
4003 sta_idx++;
4004 }
4005
4006
4007 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004008 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004009 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004010 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004011 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004012
4013 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004014}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004015
Johannes Berg5727ef12007-12-19 02:03:34 +01004016static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4017{
Johannes Berg4c476992010-10-04 21:36:35 +02004018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4019 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004020 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004021 struct sk_buff *msg;
4022 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004023 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004024
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004025 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004026
4027 if (!info->attrs[NL80211_ATTR_MAC])
4028 return -EINVAL;
4029
4030 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4031
Johannes Berg4c476992010-10-04 21:36:35 +02004032 if (!rdev->ops->get_station)
4033 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004034
Hila Gonene35e4d22012-06-27 17:19:42 +03004035 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004036 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004037 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004038
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004039 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004040 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004041 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004042
Johannes Bergcf5ead82014-11-14 17:14:00 +01004043 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4044 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004045 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004046 nlmsg_free(msg);
4047 return -ENOBUFS;
4048 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004049
Johannes Berg4c476992010-10-04 21:36:35 +02004050 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004051}
4052
Johannes Berg77ee7c82013-02-15 00:48:33 +01004053int cfg80211_check_station_change(struct wiphy *wiphy,
4054 struct station_parameters *params,
4055 enum cfg80211_station_type statype)
4056{
Ayala Bekere4208422015-10-23 11:20:06 +03004057 if (params->listen_interval != -1 &&
4058 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004059 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004060
Ayala Beker17b94242016-03-17 15:41:38 +02004061 if (params->support_p2p_ps != -1 &&
4062 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4063 return -EINVAL;
4064
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004065 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004066 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4067 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004068 return -EINVAL;
4069
4070 /* When you run into this, adjust the code below for the new flag */
4071 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4072
4073 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004074 case CFG80211_STA_MESH_PEER_KERNEL:
4075 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004076 /*
4077 * No ignoring the TDLS flag here -- the userspace mesh
4078 * code doesn't have the bug of including TDLS in the
4079 * mask everywhere.
4080 */
4081 if (params->sta_flags_mask &
4082 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4083 BIT(NL80211_STA_FLAG_MFP) |
4084 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4085 return -EINVAL;
4086 break;
4087 case CFG80211_STA_TDLS_PEER_SETUP:
4088 case CFG80211_STA_TDLS_PEER_ACTIVE:
4089 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4090 return -EINVAL;
4091 /* ignore since it can't change */
4092 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4093 break;
4094 default:
4095 /* disallow mesh-specific things */
4096 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4097 return -EINVAL;
4098 if (params->local_pm)
4099 return -EINVAL;
4100 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4101 return -EINVAL;
4102 }
4103
4104 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4105 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4106 /* TDLS can't be set, ... */
4107 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4108 return -EINVAL;
4109 /*
4110 * ... but don't bother the driver with it. This works around
4111 * a hostapd/wpa_supplicant issue -- it always includes the
4112 * TLDS_PEER flag in the mask even for AP mode.
4113 */
4114 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4115 }
4116
Ayala Beker47edb112015-09-21 15:49:53 +03004117 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4118 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004119 /* reject other things that can't change */
4120 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4121 return -EINVAL;
4122 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4123 return -EINVAL;
4124 if (params->supported_rates)
4125 return -EINVAL;
4126 if (params->ext_capab || params->ht_capa || params->vht_capa)
4127 return -EINVAL;
4128 }
4129
Ayala Beker47edb112015-09-21 15:49:53 +03004130 if (statype != CFG80211_STA_AP_CLIENT &&
4131 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004132 if (params->vlan)
4133 return -EINVAL;
4134 }
4135
4136 switch (statype) {
4137 case CFG80211_STA_AP_MLME_CLIENT:
4138 /* Use this only for authorizing/unauthorizing a station */
4139 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4140 return -EOPNOTSUPP;
4141 break;
4142 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004143 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004144 /* accept only the listed bits */
4145 if (params->sta_flags_mask &
4146 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4147 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4148 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4149 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4150 BIT(NL80211_STA_FLAG_WME) |
4151 BIT(NL80211_STA_FLAG_MFP)))
4152 return -EINVAL;
4153
4154 /* but authenticated/associated only if driver handles it */
4155 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4156 params->sta_flags_mask &
4157 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4158 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4159 return -EINVAL;
4160 break;
4161 case CFG80211_STA_IBSS:
4162 case CFG80211_STA_AP_STA:
4163 /* reject any changes other than AUTHORIZED */
4164 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4165 return -EINVAL;
4166 break;
4167 case CFG80211_STA_TDLS_PEER_SETUP:
4168 /* reject any changes other than AUTHORIZED or WME */
4169 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4170 BIT(NL80211_STA_FLAG_WME)))
4171 return -EINVAL;
4172 /* force (at least) rates when authorizing */
4173 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4174 !params->supported_rates)
4175 return -EINVAL;
4176 break;
4177 case CFG80211_STA_TDLS_PEER_ACTIVE:
4178 /* reject any changes */
4179 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004180 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004181 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4182 return -EINVAL;
4183 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004184 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004185 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4186 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004187 return -EINVAL;
4188 break;
4189 }
4190
4191 return 0;
4192}
4193EXPORT_SYMBOL(cfg80211_check_station_change);
4194
Johannes Berg5727ef12007-12-19 02:03:34 +01004195/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004196 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004197 */
Johannes Berg80b99892011-11-18 16:23:01 +01004198static struct net_device *get_vlan(struct genl_info *info,
4199 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004200{
Johannes Berg463d0182009-07-14 00:33:35 +02004201 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004202 struct net_device *v;
4203 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004204
Johannes Berg80b99892011-11-18 16:23:01 +01004205 if (!vlanattr)
4206 return NULL;
4207
4208 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4209 if (!v)
4210 return ERR_PTR(-ENODEV);
4211
4212 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4213 ret = -EINVAL;
4214 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004215 }
Johannes Berg80b99892011-11-18 16:23:01 +01004216
Johannes Berg77ee7c82013-02-15 00:48:33 +01004217 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4218 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4219 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4220 ret = -EINVAL;
4221 goto error;
4222 }
4223
Johannes Berg80b99892011-11-18 16:23:01 +01004224 if (!netif_running(v)) {
4225 ret = -ENETDOWN;
4226 goto error;
4227 }
4228
4229 return v;
4230 error:
4231 dev_put(v);
4232 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004233}
4234
Johannes Berg94e860f2014-01-20 23:58:15 +01004235static const struct nla_policy
4236nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004237 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4238 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4239};
4240
Johannes Bergff276692013-02-15 00:09:01 +01004241static int nl80211_parse_sta_wme(struct genl_info *info,
4242 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004243{
Jouni Malinendf881292013-02-14 21:10:54 +02004244 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4245 struct nlattr *nla;
4246 int err;
4247
Jouni Malinendf881292013-02-14 21:10:54 +02004248 /* parse WME attributes if present */
4249 if (!info->attrs[NL80211_ATTR_STA_WME])
4250 return 0;
4251
4252 nla = info->attrs[NL80211_ATTR_STA_WME];
4253 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4254 nl80211_sta_wme_policy);
4255 if (err)
4256 return err;
4257
4258 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4259 params->uapsd_queues = nla_get_u8(
4260 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4261 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4262 return -EINVAL;
4263
4264 if (tb[NL80211_STA_WME_MAX_SP])
4265 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4266
4267 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4268 return -EINVAL;
4269
4270 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4271
4272 return 0;
4273}
4274
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304275static int nl80211_parse_sta_channel_info(struct genl_info *info,
4276 struct station_parameters *params)
4277{
4278 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4279 params->supported_channels =
4280 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4281 params->supported_channels_len =
4282 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4283 /*
4284 * Need to include at least one (first channel, number of
4285 * channels) tuple for each subband, and must have proper
4286 * tuples for the rest of the data as well.
4287 */
4288 if (params->supported_channels_len < 2)
4289 return -EINVAL;
4290 if (params->supported_channels_len % 2)
4291 return -EINVAL;
4292 }
4293
4294 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4295 params->supported_oper_classes =
4296 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4297 params->supported_oper_classes_len =
4298 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4299 /*
4300 * The value of the Length field of the Supported Operating
4301 * Classes element is between 2 and 253.
4302 */
4303 if (params->supported_oper_classes_len < 2 ||
4304 params->supported_oper_classes_len > 253)
4305 return -EINVAL;
4306 }
4307 return 0;
4308}
4309
Johannes Bergff276692013-02-15 00:09:01 +01004310static int nl80211_set_station_tdls(struct genl_info *info,
4311 struct station_parameters *params)
4312{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304313 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004314 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004315 if (info->attrs[NL80211_ATTR_PEER_AID])
4316 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004317 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4318 params->ht_capa =
4319 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4320 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4321 params->vht_capa =
4322 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4323
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304324 err = nl80211_parse_sta_channel_info(info, params);
4325 if (err)
4326 return err;
4327
Johannes Bergff276692013-02-15 00:09:01 +01004328 return nl80211_parse_sta_wme(info, params);
4329}
4330
Johannes Berg5727ef12007-12-19 02:03:34 +01004331static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4332{
Johannes Berg4c476992010-10-04 21:36:35 +02004333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004334 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004335 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004336 u8 *mac_addr;
4337 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004338
4339 memset(&params, 0, sizeof(params));
4340
Johannes Berg77ee7c82013-02-15 00:48:33 +01004341 if (!rdev->ops->change_station)
4342 return -EOPNOTSUPP;
4343
Ayala Bekere4208422015-10-23 11:20:06 +03004344 /*
4345 * AID and listen_interval properties can be set only for unassociated
4346 * station. Include these parameters here and will check them in
4347 * cfg80211_check_station_change().
4348 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004349 if (info->attrs[NL80211_ATTR_STA_AID])
4350 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004351
4352 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4353 params.listen_interval =
4354 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4355 else
4356 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004357
Ayala Beker17b94242016-03-17 15:41:38 +02004358 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4359 u8 tmp;
4360
4361 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4362 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4363 return -EINVAL;
4364
4365 params.support_p2p_ps = tmp;
4366 } else {
4367 params.support_p2p_ps = -1;
4368 }
4369
Johannes Berg5727ef12007-12-19 02:03:34 +01004370 if (!info->attrs[NL80211_ATTR_MAC])
4371 return -EINVAL;
4372
4373 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4374
4375 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4376 params.supported_rates =
4377 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4378 params.supported_rates_len =
4379 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4380 }
4381
Jouni Malinen9d62a982013-02-14 21:10:13 +02004382 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4383 params.capability =
4384 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4385 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4386 }
4387
4388 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4389 params.ext_capab =
4390 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4391 params.ext_capab_len =
4392 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4393 }
4394
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004395 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004396 return -EINVAL;
4397
Johannes Bergf8bacc22013-02-14 23:27:01 +01004398 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004399 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004400 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4401 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4402 return -EINVAL;
4403 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004404
Johannes Bergf8bacc22013-02-14 23:27:01 +01004405 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004406 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004407 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4408 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4409 return -EINVAL;
4410 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4411 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004412
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004413 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4414 enum nl80211_mesh_power_mode pm = nla_get_u32(
4415 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4416
4417 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4418 pm > NL80211_MESH_POWER_MAX)
4419 return -EINVAL;
4420
4421 params.local_pm = pm;
4422 }
4423
Johannes Berg77ee7c82013-02-15 00:48:33 +01004424 /* Include parameters for TDLS peer (will check later) */
4425 err = nl80211_set_station_tdls(info, &params);
4426 if (err)
4427 return err;
4428
4429 params.vlan = get_vlan(info, rdev);
4430 if (IS_ERR(params.vlan))
4431 return PTR_ERR(params.vlan);
4432
Johannes Berga97f4422009-06-18 17:23:43 +02004433 switch (dev->ieee80211_ptr->iftype) {
4434 case NL80211_IFTYPE_AP:
4435 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004436 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004437 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004438 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004439 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004440 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004441 break;
4442 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004443 err = -EOPNOTSUPP;
4444 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004445 }
4446
Johannes Berg77ee7c82013-02-15 00:48:33 +01004447 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004448 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004449
Johannes Berg77ee7c82013-02-15 00:48:33 +01004450 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004451 if (params.vlan)
4452 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004453
Johannes Berg5727ef12007-12-19 02:03:34 +01004454 return err;
4455}
4456
4457static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4458{
Johannes Berg4c476992010-10-04 21:36:35 +02004459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004460 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004461 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004462 struct station_parameters params;
4463 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004464 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4465 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004466
4467 memset(&params, 0, sizeof(params));
4468
Johannes Berg984c3112013-02-14 23:43:25 +01004469 if (!rdev->ops->add_station)
4470 return -EOPNOTSUPP;
4471
Johannes Berg5727ef12007-12-19 02:03:34 +01004472 if (!info->attrs[NL80211_ATTR_MAC])
4473 return -EINVAL;
4474
Johannes Berg5727ef12007-12-19 02:03:34 +01004475 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4476 return -EINVAL;
4477
4478 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4479 return -EINVAL;
4480
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004481 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4482 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004483 return -EINVAL;
4484
Johannes Berg5727ef12007-12-19 02:03:34 +01004485 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4486 params.supported_rates =
4487 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4488 params.supported_rates_len =
4489 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4490 params.listen_interval =
4491 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004492
Ayala Beker17b94242016-03-17 15:41:38 +02004493 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4494 u8 tmp;
4495
4496 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4497 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4498 return -EINVAL;
4499
4500 params.support_p2p_ps = tmp;
4501 } else {
4502 /*
4503 * if not specified, assume it's supported for P2P GO interface,
4504 * and is NOT supported for AP interface
4505 */
4506 params.support_p2p_ps =
4507 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4508 }
4509
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004510 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004511 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004512 else
4513 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004514 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4515 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004516
Jouni Malinen9d62a982013-02-14 21:10:13 +02004517 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4518 params.capability =
4519 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4520 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4521 }
4522
4523 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4524 params.ext_capab =
4525 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4526 params.ext_capab_len =
4527 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4528 }
4529
Jouni Malinen36aedc902008-08-25 11:58:58 +03004530 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4531 params.ht_capa =
4532 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004533
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004534 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4535 params.vht_capa =
4536 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4537
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004538 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4539 params.opmode_notif_used = true;
4540 params.opmode_notif =
4541 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4542 }
4543
Johannes Bergf8bacc22013-02-14 23:27:01 +01004544 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004545 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004546 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4547 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4548 return -EINVAL;
4549 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004550
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304551 err = nl80211_parse_sta_channel_info(info, &params);
4552 if (err)
4553 return err;
4554
Johannes Bergff276692013-02-15 00:09:01 +01004555 err = nl80211_parse_sta_wme(info, &params);
4556 if (err)
4557 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004558
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004559 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004560 return -EINVAL;
4561
Johannes Berg496fcc22015-03-12 08:53:27 +02004562 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4563 * as userspace might just pass through the capabilities from the IEs
4564 * directly, rather than enforcing this restriction and returning an
4565 * error in this case.
4566 */
4567 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4568 params.ht_capa = NULL;
4569 params.vht_capa = NULL;
4570 }
4571
Johannes Berg77ee7c82013-02-15 00:48:33 +01004572 /* When you run into this, adjust the code below for the new flag */
4573 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4574
Johannes Bergbdd90d52011-12-14 12:20:27 +01004575 switch (dev->ieee80211_ptr->iftype) {
4576 case NL80211_IFTYPE_AP:
4577 case NL80211_IFTYPE_AP_VLAN:
4578 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004579 /* ignore WME attributes if iface/sta is not capable */
4580 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4581 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4582 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004583
Johannes Bergbdd90d52011-12-14 12:20:27 +01004584 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004585 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4586 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004587 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004588 /* but don't bother the driver with it */
4589 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004590
Johannes Bergd582cff2012-10-26 17:53:44 +02004591 /* allow authenticated/associated only if driver handles it */
4592 if (!(rdev->wiphy.features &
4593 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004594 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004595 return -EINVAL;
4596
Johannes Bergbda95eb2015-11-26 16:26:13 +01004597 /* Older userspace, or userspace wanting to be compatible with
4598 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4599 * and assoc flags in the mask, but assumes the station will be
4600 * added as associated anyway since this was the required driver
4601 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4602 * introduced.
4603 * In order to not bother drivers with this quirk in the API
4604 * set the flags in both the mask and set for new stations in
4605 * this case.
4606 */
4607 if (!(params.sta_flags_mask & auth_assoc)) {
4608 params.sta_flags_mask |= auth_assoc;
4609 params.sta_flags_set |= auth_assoc;
4610 }
4611
Johannes Bergbdd90d52011-12-14 12:20:27 +01004612 /* must be last in here for error handling */
4613 params.vlan = get_vlan(info, rdev);
4614 if (IS_ERR(params.vlan))
4615 return PTR_ERR(params.vlan);
4616 break;
4617 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004618 /* ignore uAPSD data */
4619 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4620
Johannes Bergd582cff2012-10-26 17:53:44 +02004621 /* associated is disallowed */
4622 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4623 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004624 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004625 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4626 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004627 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004628 break;
4629 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004630 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004631 /* ignore uAPSD data */
4632 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4633
Johannes Berg77ee7c82013-02-15 00:48:33 +01004634 /* these are disallowed */
4635 if (params.sta_flags_mask &
4636 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4637 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004638 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004639 /* Only TDLS peers can be added */
4640 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4641 return -EINVAL;
4642 /* Can only add if TDLS ... */
4643 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4644 return -EOPNOTSUPP;
4645 /* ... with external setup is supported */
4646 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4647 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004648 /*
4649 * Older wpa_supplicant versions always mark the TDLS peer
4650 * as authorized, but it shouldn't yet be.
4651 */
4652 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004653 break;
4654 default:
4655 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004656 }
4657
Johannes Bergbdd90d52011-12-14 12:20:27 +01004658 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004659
Hila Gonene35e4d22012-06-27 17:19:42 +03004660 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004661
Johannes Berg5727ef12007-12-19 02:03:34 +01004662 if (params.vlan)
4663 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004664 return err;
4665}
4666
4667static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4668{
Johannes Berg4c476992010-10-04 21:36:35 +02004669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4670 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004671 struct station_del_parameters params;
4672
4673 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004674
4675 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004676 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004677
Johannes Berge80cf852009-05-11 14:43:13 +02004678 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004679 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004680 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004681 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4682 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004683
Johannes Berg4c476992010-10-04 21:36:35 +02004684 if (!rdev->ops->del_station)
4685 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004686
Jouni Malinen98856862014-10-20 13:20:45 +03004687 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4688 params.subtype =
4689 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4690 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4691 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4692 return -EINVAL;
4693 } else {
4694 /* Default to Deauthentication frame */
4695 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4696 }
4697
4698 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4699 params.reason_code =
4700 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4701 if (params.reason_code == 0)
4702 return -EINVAL; /* 0 is reserved */
4703 } else {
4704 /* Default to reason code 2 */
4705 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4706 }
4707
Jouni Malinen89c771e2014-10-10 20:52:40 +03004708 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004709}
4710
Eric W. Biederman15e47302012-09-07 20:12:54 +00004711static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004712 int flags, struct net_device *dev,
4713 u8 *dst, u8 *next_hop,
4714 struct mpath_info *pinfo)
4715{
4716 void *hdr;
4717 struct nlattr *pinfoattr;
4718
Henning Rogge1ef4c852014-11-04 16:14:58 +01004719 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004720 if (!hdr)
4721 return -1;
4722
David S. Miller9360ffd2012-03-29 04:41:26 -04004723 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4724 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4725 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4726 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4727 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004728
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004729 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4730 if (!pinfoattr)
4731 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004732 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4733 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4734 pinfo->frame_qlen))
4735 goto nla_put_failure;
4736 if (((pinfo->filled & MPATH_INFO_SN) &&
4737 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4738 ((pinfo->filled & MPATH_INFO_METRIC) &&
4739 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4740 pinfo->metric)) ||
4741 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4742 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4743 pinfo->exptime)) ||
4744 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4745 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4746 pinfo->flags)) ||
4747 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4748 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4749 pinfo->discovery_timeout)) ||
4750 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4751 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4752 pinfo->discovery_retries)))
4753 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004754
4755 nla_nest_end(msg, pinfoattr);
4756
Johannes Berg053c0952015-01-16 22:09:00 +01004757 genlmsg_end(msg, hdr);
4758 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004759
4760 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004761 genlmsg_cancel(msg, hdr);
4762 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004763}
4764
4765static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004766 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004767{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004768 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004769 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004770 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004771 u8 dst[ETH_ALEN];
4772 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004773 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004774 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004775
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004776 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004777 if (err)
4778 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004779
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004780 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004781 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004782 goto out_err;
4783 }
4784
Johannes Berg97990a02013-04-19 01:02:55 +02004785 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004786 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004787 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004788 }
4789
Johannes Bergbba95fe2008-07-29 13:22:51 +02004790 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004791 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004792 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004793 if (err == -ENOENT)
4794 break;
4795 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004796 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004797
Eric W. Biederman15e47302012-09-07 20:12:54 +00004798 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004799 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004800 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004801 &pinfo) < 0)
4802 goto out;
4803
4804 path_idx++;
4805 }
4806
4807
4808 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004809 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004810 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004811 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004812 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004813 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004814}
4815
4816static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4817{
Johannes Berg4c476992010-10-04 21:36:35 +02004818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004819 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004820 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004821 struct mpath_info pinfo;
4822 struct sk_buff *msg;
4823 u8 *dst = NULL;
4824 u8 next_hop[ETH_ALEN];
4825
4826 memset(&pinfo, 0, sizeof(pinfo));
4827
4828 if (!info->attrs[NL80211_ATTR_MAC])
4829 return -EINVAL;
4830
4831 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4832
Johannes Berg4c476992010-10-04 21:36:35 +02004833 if (!rdev->ops->get_mpath)
4834 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004835
Johannes Berg4c476992010-10-04 21:36:35 +02004836 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4837 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004838
Hila Gonene35e4d22012-06-27 17:19:42 +03004839 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004840 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004841 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004842
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004843 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004844 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004845 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004846
Eric W. Biederman15e47302012-09-07 20:12:54 +00004847 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004848 dev, dst, next_hop, &pinfo) < 0) {
4849 nlmsg_free(msg);
4850 return -ENOBUFS;
4851 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004852
Johannes Berg4c476992010-10-04 21:36:35 +02004853 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004854}
4855
4856static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4857{
Johannes Berg4c476992010-10-04 21:36:35 +02004858 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4859 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004860 u8 *dst = NULL;
4861 u8 *next_hop = NULL;
4862
4863 if (!info->attrs[NL80211_ATTR_MAC])
4864 return -EINVAL;
4865
4866 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4867 return -EINVAL;
4868
4869 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4870 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4871
Johannes Berg4c476992010-10-04 21:36:35 +02004872 if (!rdev->ops->change_mpath)
4873 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004874
Johannes Berg4c476992010-10-04 21:36:35 +02004875 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4876 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004877
Hila Gonene35e4d22012-06-27 17:19:42 +03004878 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004879}
Johannes Berg4c476992010-10-04 21:36:35 +02004880
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004881static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4882{
Johannes Berg4c476992010-10-04 21:36:35 +02004883 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4884 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004885 u8 *dst = NULL;
4886 u8 *next_hop = NULL;
4887
4888 if (!info->attrs[NL80211_ATTR_MAC])
4889 return -EINVAL;
4890
4891 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4892 return -EINVAL;
4893
4894 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4895 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4896
Johannes Berg4c476992010-10-04 21:36:35 +02004897 if (!rdev->ops->add_mpath)
4898 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004899
Johannes Berg4c476992010-10-04 21:36:35 +02004900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4901 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004902
Hila Gonene35e4d22012-06-27 17:19:42 +03004903 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004904}
4905
4906static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4907{
Johannes Berg4c476992010-10-04 21:36:35 +02004908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4909 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004910 u8 *dst = NULL;
4911
4912 if (info->attrs[NL80211_ATTR_MAC])
4913 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4914
Johannes Berg4c476992010-10-04 21:36:35 +02004915 if (!rdev->ops->del_mpath)
4916 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004917
Hila Gonene35e4d22012-06-27 17:19:42 +03004918 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004919}
4920
Henning Rogge66be7d22014-09-12 08:58:49 +02004921static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4922{
4923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4924 int err;
4925 struct net_device *dev = info->user_ptr[1];
4926 struct mpath_info pinfo;
4927 struct sk_buff *msg;
4928 u8 *dst = NULL;
4929 u8 mpp[ETH_ALEN];
4930
4931 memset(&pinfo, 0, sizeof(pinfo));
4932
4933 if (!info->attrs[NL80211_ATTR_MAC])
4934 return -EINVAL;
4935
4936 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4937
4938 if (!rdev->ops->get_mpp)
4939 return -EOPNOTSUPP;
4940
4941 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4942 return -EOPNOTSUPP;
4943
4944 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4945 if (err)
4946 return err;
4947
4948 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4949 if (!msg)
4950 return -ENOMEM;
4951
4952 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4953 dev, dst, mpp, &pinfo) < 0) {
4954 nlmsg_free(msg);
4955 return -ENOBUFS;
4956 }
4957
4958 return genlmsg_reply(msg, info);
4959}
4960
4961static int nl80211_dump_mpp(struct sk_buff *skb,
4962 struct netlink_callback *cb)
4963{
4964 struct mpath_info pinfo;
4965 struct cfg80211_registered_device *rdev;
4966 struct wireless_dev *wdev;
4967 u8 dst[ETH_ALEN];
4968 u8 mpp[ETH_ALEN];
4969 int path_idx = cb->args[2];
4970 int err;
4971
4972 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4973 if (err)
4974 return err;
4975
4976 if (!rdev->ops->dump_mpp) {
4977 err = -EOPNOTSUPP;
4978 goto out_err;
4979 }
4980
4981 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4982 err = -EOPNOTSUPP;
4983 goto out_err;
4984 }
4985
4986 while (1) {
4987 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4988 mpp, &pinfo);
4989 if (err == -ENOENT)
4990 break;
4991 if (err)
4992 goto out_err;
4993
4994 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4995 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4996 wdev->netdev, dst, mpp,
4997 &pinfo) < 0)
4998 goto out;
4999
5000 path_idx++;
5001 }
5002
5003 out:
5004 cb->args[2] = path_idx;
5005 err = skb->len;
5006 out_err:
5007 nl80211_finish_wdev_dump(rdev);
5008 return err;
5009}
5010
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005011static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5012{
Johannes Berg4c476992010-10-04 21:36:35 +02005013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5014 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005015 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005016 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005017 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005018
5019 memset(&params, 0, sizeof(params));
5020 /* default to not changing parameters */
5021 params.use_cts_prot = -1;
5022 params.use_short_preamble = -1;
5023 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005024 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005025 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005026 params.p2p_ctwindow = -1;
5027 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005028
5029 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5030 params.use_cts_prot =
5031 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5032 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5033 params.use_short_preamble =
5034 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5035 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5036 params.use_short_slot_time =
5037 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005038 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5039 params.basic_rates =
5040 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5041 params.basic_rates_len =
5042 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5043 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005044 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5045 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005046 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5047 params.ht_opmode =
5048 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005049
Johannes Berg53cabad2012-11-14 15:17:28 +01005050 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5051 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5052 return -EINVAL;
5053 params.p2p_ctwindow =
5054 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5055 if (params.p2p_ctwindow < 0)
5056 return -EINVAL;
5057 if (params.p2p_ctwindow != 0 &&
5058 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5059 return -EINVAL;
5060 }
5061
5062 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5063 u8 tmp;
5064
5065 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5066 return -EINVAL;
5067 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5068 if (tmp > 1)
5069 return -EINVAL;
5070 params.p2p_opp_ps = tmp;
5071 if (params.p2p_opp_ps &&
5072 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5073 return -EINVAL;
5074 }
5075
Johannes Berg4c476992010-10-04 21:36:35 +02005076 if (!rdev->ops->change_bss)
5077 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005078
Johannes Berg074ac8d2010-09-16 14:58:22 +02005079 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005080 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5081 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005082
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005083 wdev_lock(wdev);
5084 err = rdev_change_bss(rdev, dev, &params);
5085 wdev_unlock(wdev);
5086
5087 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005088}
5089
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005090static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5091{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005092 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005093 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005094 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005095 u32 owner_nlportid;
5096
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005097
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005098 /*
5099 * You should only get this when cfg80211 hasn't yet initialized
5100 * completely when built-in to the kernel right between the time
5101 * window between nl80211_init() and regulatory_init(), if that is
5102 * even possible.
5103 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005104 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005105 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005106
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005107 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5108 user_reg_hint_type =
5109 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5110 else
5111 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5112
5113 switch (user_reg_hint_type) {
5114 case NL80211_USER_REG_HINT_USER:
5115 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005116 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5117 return -EINVAL;
5118
5119 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5120 return regulatory_hint_user(data, user_reg_hint_type);
5121 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005122 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5123 owner_nlportid = info->snd_portid;
5124 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5125 } else {
5126 owner_nlportid = 0;
5127 is_indoor = true;
5128 }
5129
5130 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005131 default:
5132 return -EINVAL;
5133 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005134}
5135
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005136static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005137 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005138{
Johannes Berg4c476992010-10-04 21:36:35 +02005139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005140 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005141 struct wireless_dev *wdev = dev->ieee80211_ptr;
5142 struct mesh_config cur_params;
5143 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005144 void *hdr;
5145 struct nlattr *pinfoattr;
5146 struct sk_buff *msg;
5147
Johannes Berg29cbe682010-12-03 09:20:44 +01005148 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5149 return -EOPNOTSUPP;
5150
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005151 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005152 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005153
Johannes Berg29cbe682010-12-03 09:20:44 +01005154 wdev_lock(wdev);
5155 /* If not connected, get default parameters */
5156 if (!wdev->mesh_id_len)
5157 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5158 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005159 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005160 wdev_unlock(wdev);
5161
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005162 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005163 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005164
5165 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005166 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005167 if (!msg)
5168 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005169 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005170 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005171 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005172 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005173 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005174 if (!pinfoattr)
5175 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005176 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5177 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5178 cur_params.dot11MeshRetryTimeout) ||
5179 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5180 cur_params.dot11MeshConfirmTimeout) ||
5181 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5182 cur_params.dot11MeshHoldingTimeout) ||
5183 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5184 cur_params.dot11MeshMaxPeerLinks) ||
5185 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5186 cur_params.dot11MeshMaxRetries) ||
5187 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5188 cur_params.dot11MeshTTL) ||
5189 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5190 cur_params.element_ttl) ||
5191 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5192 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005193 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5194 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005195 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5196 cur_params.dot11MeshHWMPmaxPREQretries) ||
5197 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5198 cur_params.path_refresh_time) ||
5199 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5200 cur_params.min_discovery_timeout) ||
5201 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5202 cur_params.dot11MeshHWMPactivePathTimeout) ||
5203 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5204 cur_params.dot11MeshHWMPpreqMinInterval) ||
5205 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5206 cur_params.dot11MeshHWMPperrMinInterval) ||
5207 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5208 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5209 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5210 cur_params.dot11MeshHWMPRootMode) ||
5211 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5212 cur_params.dot11MeshHWMPRannInterval) ||
5213 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5214 cur_params.dot11MeshGateAnnouncementProtocol) ||
5215 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5216 cur_params.dot11MeshForwarding) ||
5217 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005218 cur_params.rssi_threshold) ||
5219 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005220 cur_params.ht_opmode) ||
5221 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5222 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5223 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005224 cur_params.dot11MeshHWMProotInterval) ||
5225 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005226 cur_params.dot11MeshHWMPconfirmationInterval) ||
5227 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5228 cur_params.power_mode) ||
5229 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005230 cur_params.dot11MeshAwakeWindowDuration) ||
5231 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5232 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005233 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005234 nla_nest_end(msg, pinfoattr);
5235 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005236 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005237
Johannes Berg3b858752009-03-12 09:55:09 +01005238 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005239 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005240 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005241 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005242 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005243}
5244
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005245static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005246 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5247 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5248 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5249 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5250 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5251 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005252 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005253 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005254 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005255 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5256 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5257 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5258 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5259 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005260 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005261 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005262 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005263 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005264 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005265 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005266 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5267 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005268 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5269 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005270 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005271 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5272 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005273 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005274};
5275
Javier Cardonac80d5452010-12-16 17:37:49 -08005276static const struct nla_policy
5277 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005278 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005279 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5280 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005281 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005282 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005283 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005284 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005285 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005286 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005287};
5288
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005289static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005290 struct mesh_config *cfg,
5291 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005292{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005293 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005294 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005295
Marco Porschea54fba2013-01-07 16:04:48 +01005296#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5297do { \
5298 if (tb[attr]) { \
5299 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5300 return -EINVAL; \
5301 cfg->param = fn(tb[attr]); \
5302 mask |= (1 << (attr - 1)); \
5303 } \
5304} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005305
5306
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005307 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005308 return -EINVAL;
5309 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005310 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005311 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005312 return -EINVAL;
5313
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005314 /* This makes sure that there aren't more than 32 mesh config
5315 * parameters (otherwise our bitfield scheme would not work.) */
5316 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5317
5318 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005319 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005320 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5321 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005322 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005323 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5324 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005325 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005326 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5327 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005328 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005329 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5330 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005331 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005332 mask, NL80211_MESHCONF_MAX_RETRIES,
5333 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005334 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005335 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005336 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005337 mask, NL80211_MESHCONF_ELEMENT_TTL,
5338 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005340 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5341 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005342 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5343 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005344 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5345 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005346 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005347 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5348 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005349 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005350 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5351 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005352 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005353 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5354 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005355 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5356 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005357 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5358 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005359 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005360 1, 65535, mask,
5361 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005362 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005363 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005364 1, 65535, mask,
5365 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005366 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005367 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005368 dot11MeshHWMPnetDiameterTraversalTime,
5369 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005370 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5371 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005372 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5373 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5374 nla_get_u8);
5375 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5376 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005377 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005379 dot11MeshGateAnnouncementProtocol, 0, 1,
5380 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005381 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005382 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005383 mask, NL80211_MESHCONF_FORWARDING,
5384 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005385 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005386 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005387 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005388 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005389 mask, NL80211_MESHCONF_HT_OPMODE,
5390 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005391 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005392 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005393 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5394 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005395 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005396 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5397 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005398 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005399 dot11MeshHWMPconfirmationInterval,
5400 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005401 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5402 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005403 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5404 NL80211_MESH_POWER_ACTIVE,
5405 NL80211_MESH_POWER_MAX,
5406 mask, NL80211_MESHCONF_POWER_MODE,
5407 nla_get_u32);
5408 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5409 0, 65535, mask,
5410 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005412 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5413 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005414 if (mask_out)
5415 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005416
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005417 return 0;
5418
5419#undef FILL_IN_MESH_PARAM_IF_SET
5420}
5421
Javier Cardonac80d5452010-12-16 17:37:49 -08005422static int nl80211_parse_mesh_setup(struct genl_info *info,
5423 struct mesh_setup *setup)
5424{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005426 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5427
5428 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5429 return -EINVAL;
5430 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5431 info->attrs[NL80211_ATTR_MESH_SETUP],
5432 nl80211_mesh_setup_params_policy))
5433 return -EINVAL;
5434
Javier Cardonad299a1f2012-03-31 11:31:33 -07005435 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5436 setup->sync_method =
5437 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5438 IEEE80211_SYNC_METHOD_VENDOR :
5439 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5440
Javier Cardonac80d5452010-12-16 17:37:49 -08005441 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5442 setup->path_sel_proto =
5443 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5444 IEEE80211_PATH_PROTOCOL_VENDOR :
5445 IEEE80211_PATH_PROTOCOL_HWMP;
5446
5447 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5448 setup->path_metric =
5449 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5450 IEEE80211_PATH_METRIC_VENDOR :
5451 IEEE80211_PATH_METRIC_AIRTIME;
5452
Javier Cardona581a8b02011-04-07 15:08:27 -07005453
5454 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005455 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005456 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005457 if (!is_valid_ie_attr(ieattr))
5458 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005459 setup->ie = nla_data(ieattr);
5460 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005461 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005462 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5463 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5464 return -EINVAL;
5465 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005466 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5467 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005468 if (setup->is_secure)
5469 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005470
Colleen Twitty6e16d902013-05-08 11:45:59 -07005471 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5472 if (!setup->user_mpm)
5473 return -EINVAL;
5474 setup->auth_id =
5475 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5476 }
5477
Javier Cardonac80d5452010-12-16 17:37:49 -08005478 return 0;
5479}
5480
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005481static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005482 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005483{
5484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5485 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005486 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005487 struct mesh_config cfg;
5488 u32 mask;
5489 int err;
5490
Johannes Berg29cbe682010-12-03 09:20:44 +01005491 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5492 return -EOPNOTSUPP;
5493
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005494 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005495 return -EOPNOTSUPP;
5496
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005497 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005498 if (err)
5499 return err;
5500
Johannes Berg29cbe682010-12-03 09:20:44 +01005501 wdev_lock(wdev);
5502 if (!wdev->mesh_id_len)
5503 err = -ENOLINK;
5504
5505 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005506 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005507
5508 wdev_unlock(wdev);
5509
5510 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005511}
5512
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005513static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5514 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005515{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005516 struct nlattr *nl_reg_rules;
5517 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005518
Johannes Berg458f4f92012-12-06 15:47:38 +01005519 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5520 (regdom->dfs_region &&
5521 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005522 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005523
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005524 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5525 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005526 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005527
Johannes Berg458f4f92012-12-06 15:47:38 +01005528 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005529 struct nlattr *nl_reg_rule;
5530 const struct ieee80211_reg_rule *reg_rule;
5531 const struct ieee80211_freq_range *freq_range;
5532 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005533 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005534
Johannes Berg458f4f92012-12-06 15:47:38 +01005535 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005536 freq_range = &reg_rule->freq_range;
5537 power_rule = &reg_rule->power_rule;
5538
5539 nl_reg_rule = nla_nest_start(msg, i);
5540 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005541 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005542
Janusz Dziedzic97524822014-01-30 09:52:20 +01005543 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5544 if (!max_bandwidth_khz)
5545 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5546 reg_rule);
5547
David S. Miller9360ffd2012-03-29 04:41:26 -04005548 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5549 reg_rule->flags) ||
5550 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5551 freq_range->start_freq_khz) ||
5552 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5553 freq_range->end_freq_khz) ||
5554 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005555 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005556 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5557 power_rule->max_antenna_gain) ||
5558 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005559 power_rule->max_eirp) ||
5560 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5561 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005562 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005563
5564 nla_nest_end(msg, nl_reg_rule);
5565 }
5566
5567 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005568 return 0;
5569
5570nla_put_failure:
5571 return -EMSGSIZE;
5572}
5573
5574static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5575{
5576 const struct ieee80211_regdomain *regdom = NULL;
5577 struct cfg80211_registered_device *rdev;
5578 struct wiphy *wiphy = NULL;
5579 struct sk_buff *msg;
5580 void *hdr;
5581
5582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5583 if (!msg)
5584 return -ENOBUFS;
5585
5586 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5587 NL80211_CMD_GET_REG);
5588 if (!hdr)
5589 goto put_failure;
5590
5591 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005592 bool self_managed;
5593
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005594 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5595 if (IS_ERR(rdev)) {
5596 nlmsg_free(msg);
5597 return PTR_ERR(rdev);
5598 }
5599
5600 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005601 self_managed = wiphy->regulatory_flags &
5602 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005603 regdom = get_wiphy_regdom(wiphy);
5604
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005605 /* a self-managed-reg device must have a private regdom */
5606 if (WARN_ON(!regdom && self_managed)) {
5607 nlmsg_free(msg);
5608 return -EINVAL;
5609 }
5610
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005611 if (regdom &&
5612 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5613 goto nla_put_failure;
5614 }
5615
5616 if (!wiphy && reg_last_request_cell_base() &&
5617 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5618 NL80211_USER_REG_HINT_CELL_BASE))
5619 goto nla_put_failure;
5620
5621 rcu_read_lock();
5622
5623 if (!regdom)
5624 regdom = rcu_dereference(cfg80211_regdomain);
5625
5626 if (nl80211_put_regdom(regdom, msg))
5627 goto nla_put_failure_rcu;
5628
5629 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005630
5631 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005632 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005633
Johannes Berg458f4f92012-12-06 15:47:38 +01005634nla_put_failure_rcu:
5635 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005636nla_put_failure:
5637 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005638put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005639 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005640 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005641}
5642
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005643static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5644 u32 seq, int flags, struct wiphy *wiphy,
5645 const struct ieee80211_regdomain *regdom)
5646{
5647 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5648 NL80211_CMD_GET_REG);
5649
5650 if (!hdr)
5651 return -1;
5652
5653 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5654
5655 if (nl80211_put_regdom(regdom, msg))
5656 goto nla_put_failure;
5657
5658 if (!wiphy && reg_last_request_cell_base() &&
5659 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5660 NL80211_USER_REG_HINT_CELL_BASE))
5661 goto nla_put_failure;
5662
5663 if (wiphy &&
5664 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5665 goto nla_put_failure;
5666
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005667 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5668 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5669 goto nla_put_failure;
5670
Johannes Berg053c0952015-01-16 22:09:00 +01005671 genlmsg_end(msg, hdr);
5672 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005673
5674nla_put_failure:
5675 genlmsg_cancel(msg, hdr);
5676 return -EMSGSIZE;
5677}
5678
5679static int nl80211_get_reg_dump(struct sk_buff *skb,
5680 struct netlink_callback *cb)
5681{
5682 const struct ieee80211_regdomain *regdom = NULL;
5683 struct cfg80211_registered_device *rdev;
5684 int err, reg_idx, start = cb->args[2];
5685
5686 rtnl_lock();
5687
5688 if (cfg80211_regdomain && start == 0) {
5689 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5690 NLM_F_MULTI, NULL,
5691 rtnl_dereference(cfg80211_regdomain));
5692 if (err < 0)
5693 goto out_err;
5694 }
5695
5696 /* the global regdom is idx 0 */
5697 reg_idx = 1;
5698 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5699 regdom = get_wiphy_regdom(&rdev->wiphy);
5700 if (!regdom)
5701 continue;
5702
5703 if (++reg_idx <= start)
5704 continue;
5705
5706 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5707 NLM_F_MULTI, &rdev->wiphy, regdom);
5708 if (err < 0) {
5709 reg_idx--;
5710 break;
5711 }
5712 }
5713
5714 cb->args[2] = reg_idx;
5715 err = skb->len;
5716out_err:
5717 rtnl_unlock();
5718 return err;
5719}
5720
Johannes Bergb6863032015-10-15 09:25:18 +02005721#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5722static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5723 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5724 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5725 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5726 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5727 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5728 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5729 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5730};
5731
5732static int parse_reg_rule(struct nlattr *tb[],
5733 struct ieee80211_reg_rule *reg_rule)
5734{
5735 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5736 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5737
5738 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5739 return -EINVAL;
5740 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5741 return -EINVAL;
5742 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5743 return -EINVAL;
5744 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5745 return -EINVAL;
5746 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5747 return -EINVAL;
5748
5749 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5750
5751 freq_range->start_freq_khz =
5752 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5753 freq_range->end_freq_khz =
5754 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5755 freq_range->max_bandwidth_khz =
5756 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5757
5758 power_rule->max_eirp =
5759 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5760
5761 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5762 power_rule->max_antenna_gain =
5763 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5764
5765 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5766 reg_rule->dfs_cac_ms =
5767 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5768
5769 return 0;
5770}
5771
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005772static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5773{
5774 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5775 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005776 char *alpha2;
5777 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005778 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005779 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005780 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005781
5782 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5783 return -EINVAL;
5784
5785 if (!info->attrs[NL80211_ATTR_REG_RULES])
5786 return -EINVAL;
5787
5788 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5789
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005790 if (info->attrs[NL80211_ATTR_DFS_REGION])
5791 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5792
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005793 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005794 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005795 num_rules++;
5796 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005797 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005798 }
5799
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005800 if (!reg_is_valid_request(alpha2))
5801 return -EINVAL;
5802
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005803 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005804 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005805
5806 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005807 if (!rd)
5808 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005809
5810 rd->n_reg_rules = num_rules;
5811 rd->alpha2[0] = alpha2[0];
5812 rd->alpha2[1] = alpha2[1];
5813
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005814 /*
5815 * Disable DFS master mode if the DFS region was
5816 * not supported or known on this kernel.
5817 */
5818 if (reg_supported_dfs_region(dfs_region))
5819 rd->dfs_region = dfs_region;
5820
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005821 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005822 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005823 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5824 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5825 reg_rule_policy);
5826 if (r)
5827 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005828 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5829 if (r)
5830 goto bad_reg;
5831
5832 rule_idx++;
5833
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005834 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5835 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005836 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005837 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005838 }
5839
Ilan peerc37722b2015-03-30 15:15:49 +03005840 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005841 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005842 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005843
Johannes Bergd2372b32008-10-24 20:32:20 +02005844 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005845 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005846 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005847}
Johannes Bergb6863032015-10-15 09:25:18 +02005848#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005849
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005850static int validate_scan_freqs(struct nlattr *freqs)
5851{
5852 struct nlattr *attr1, *attr2;
5853 int n_channels = 0, tmp1, tmp2;
5854
5855 nla_for_each_nested(attr1, freqs, tmp1) {
5856 n_channels++;
5857 /*
5858 * Some hardware has a limited channel list for
5859 * scanning, and it is pretty much nonsensical
5860 * to scan for a channel twice, so disallow that
5861 * and don't require drivers to check that the
5862 * channel list they get isn't longer than what
5863 * they can scan, as long as they can scan all
5864 * the channels they registered at once.
5865 */
5866 nla_for_each_nested(attr2, freqs, tmp2)
5867 if (attr1 != attr2 &&
5868 nla_get_u32(attr1) == nla_get_u32(attr2))
5869 return 0;
5870 }
5871
5872 return n_channels;
5873}
5874
Johannes Berg57fbcce2016-04-12 15:56:15 +02005875static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005876{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005877 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005878}
5879
5880static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5881 struct cfg80211_bss_selection *bss_select)
5882{
5883 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5884 struct nlattr *nest;
5885 int err;
5886 bool found = false;
5887 int i;
5888
5889 /* only process one nested attribute */
5890 nest = nla_data(nla);
5891 if (!nla_ok(nest, nla_len(nest)))
5892 return -EINVAL;
5893
5894 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5895 nla_len(nest), nl80211_bss_select_policy);
5896 if (err)
5897 return err;
5898
5899 /* only one attribute may be given */
5900 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
5901 if (attr[i]) {
5902 if (found)
5903 return -EINVAL;
5904 found = true;
5905 }
5906 }
5907
5908 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
5909
5910 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
5911 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
5912
5913 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
5914 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
5915 bss_select->param.band_pref =
5916 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
5917 if (!is_band_valid(wiphy, bss_select->param.band_pref))
5918 return -EINVAL;
5919 }
5920
5921 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
5922 struct nl80211_bss_select_rssi_adjust *adj_param;
5923
5924 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
5925 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
5926 bss_select->param.adjust.band = adj_param->band;
5927 bss_select->param.adjust.delta = adj_param->delta;
5928 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
5929 return -EINVAL;
5930 }
5931
5932 /* user-space did not provide behaviour attribute */
5933 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
5934 return -EINVAL;
5935
5936 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
5937 return -EINVAL;
5938
5939 return 0;
5940}
5941
Johannes Bergad2b26a2014-06-12 21:39:05 +02005942static int nl80211_parse_random_mac(struct nlattr **attrs,
5943 u8 *mac_addr, u8 *mac_addr_mask)
5944{
5945 int i;
5946
5947 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005948 eth_zero_addr(mac_addr);
5949 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005950 mac_addr[0] = 0x2;
5951 mac_addr_mask[0] = 0x3;
5952
5953 return 0;
5954 }
5955
5956 /* need both or none */
5957 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5958 return -EINVAL;
5959
5960 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5961 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5962
5963 /* don't allow or configure an mcast address */
5964 if (!is_multicast_ether_addr(mac_addr_mask) ||
5965 is_multicast_ether_addr(mac_addr))
5966 return -EINVAL;
5967
5968 /*
5969 * allow users to pass a MAC address that has bits set outside
5970 * of the mask, but don't bother drivers with having to deal
5971 * with such bits
5972 */
5973 for (i = 0; i < ETH_ALEN; i++)
5974 mac_addr[i] &= mac_addr_mask[i];
5975
5976 return 0;
5977}
5978
Johannes Berg2a519312009-02-10 21:25:55 +01005979static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5980{
Johannes Berg4c476992010-10-04 21:36:35 +02005981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005982 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005983 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005984 struct nlattr *attr;
5985 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005986 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005987 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005988
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005989 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5990 return -EINVAL;
5991
Johannes Berg79c97e92009-07-07 03:56:12 +02005992 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005993
Johannes Berg4c476992010-10-04 21:36:35 +02005994 if (!rdev->ops->scan)
5995 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005996
Johannes Bergf9d15d12014-01-22 11:14:19 +02005997 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005998 err = -EBUSY;
5999 goto unlock;
6000 }
Johannes Berg2a519312009-02-10 21:25:55 +01006001
6002 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006003 n_channels = validate_scan_freqs(
6004 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006005 if (!n_channels) {
6006 err = -EINVAL;
6007 goto unlock;
6008 }
Johannes Berg2a519312009-02-10 21:25:55 +01006009 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006010 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006011 }
6012
6013 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6014 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6015 n_ssids++;
6016
Johannes Bergf9f47522013-03-19 15:04:07 +01006017 if (n_ssids > wiphy->max_scan_ssids) {
6018 err = -EINVAL;
6019 goto unlock;
6020 }
Johannes Berg2a519312009-02-10 21:25:55 +01006021
Jouni Malinen70692ad2009-02-16 19:39:13 +02006022 if (info->attrs[NL80211_ATTR_IE])
6023 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6024 else
6025 ie_len = 0;
6026
Johannes Bergf9f47522013-03-19 15:04:07 +01006027 if (ie_len > wiphy->max_scan_ie_len) {
6028 err = -EINVAL;
6029 goto unlock;
6030 }
Johannes Berg18a83652009-03-31 12:12:05 +02006031
Johannes Berg2a519312009-02-10 21:25:55 +01006032 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006033 + sizeof(*request->ssids) * n_ssids
6034 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006035 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006036 if (!request) {
6037 err = -ENOMEM;
6038 goto unlock;
6039 }
Johannes Berg2a519312009-02-10 21:25:55 +01006040
Johannes Berg2a519312009-02-10 21:25:55 +01006041 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006042 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006043 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006044 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006045 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006046 request->ie = (void *)(request->ssids + n_ssids);
6047 else
6048 request->ie = (void *)(request->channels + n_channels);
6049 }
Johannes Berg2a519312009-02-10 21:25:55 +01006050
Johannes Berg584991d2009-11-02 13:32:03 +01006051 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006052 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6053 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006054 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006055 struct ieee80211_channel *chan;
6056
6057 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6058
6059 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006060 err = -EINVAL;
6061 goto out_free;
6062 }
Johannes Berg584991d2009-11-02 13:32:03 +01006063
6064 /* ignore disabled channels */
6065 if (chan->flags & IEEE80211_CHAN_DISABLED)
6066 continue;
6067
6068 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006069 i++;
6070 }
6071 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006072 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006073
Johannes Berg2a519312009-02-10 21:25:55 +01006074 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006075 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006076 int j;
6077 if (!wiphy->bands[band])
6078 continue;
6079 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006080 struct ieee80211_channel *chan;
6081
6082 chan = &wiphy->bands[band]->channels[j];
6083
6084 if (chan->flags & IEEE80211_CHAN_DISABLED)
6085 continue;
6086
6087 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006088 i++;
6089 }
6090 }
6091 }
6092
Johannes Berg584991d2009-11-02 13:32:03 +01006093 if (!i) {
6094 err = -EINVAL;
6095 goto out_free;
6096 }
6097
6098 request->n_channels = i;
6099
Johannes Berg2a519312009-02-10 21:25:55 +01006100 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006101 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006102 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006103 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006104 err = -EINVAL;
6105 goto out_free;
6106 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006107 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006108 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006109 i++;
6110 }
6111 }
6112
Jouni Malinen70692ad2009-02-16 19:39:13 +02006113 if (info->attrs[NL80211_ATTR_IE]) {
6114 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006115 memcpy((void *)request->ie,
6116 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006117 request->ie_len);
6118 }
6119
Johannes Berg57fbcce2016-04-12 15:56:15 +02006120 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006121 if (wiphy->bands[i])
6122 request->rates[i] =
6123 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006124
6125 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6126 nla_for_each_nested(attr,
6127 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6128 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006129 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006130
Johannes Berg57fbcce2016-04-12 15:56:15 +02006131 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006132 err = -EINVAL;
6133 goto out_free;
6134 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006135
6136 if (!wiphy->bands[band])
6137 continue;
6138
Johannes Berg34850ab2011-07-18 18:08:35 +02006139 err = ieee80211_get_ratemask(wiphy->bands[band],
6140 nla_data(attr),
6141 nla_len(attr),
6142 &request->rates[band]);
6143 if (err)
6144 goto out_free;
6145 }
6146 }
6147
Sam Leffler46856bb2012-10-11 21:03:32 -07006148 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006149 request->flags = nla_get_u32(
6150 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006151 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6152 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006153 err = -EOPNOTSUPP;
6154 goto out_free;
6155 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006156
6157 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6158 if (!(wiphy->features &
6159 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6160 err = -EOPNOTSUPP;
6161 goto out_free;
6162 }
6163
6164 if (wdev->current_bss) {
6165 err = -EOPNOTSUPP;
6166 goto out_free;
6167 }
6168
6169 err = nl80211_parse_random_mac(info->attrs,
6170 request->mac_addr,
6171 request->mac_addr_mask);
6172 if (err)
6173 goto out_free;
6174 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006175 }
Sam Lefflered4737712012-10-11 21:03:31 -07006176
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306177 request->no_cck =
6178 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6179
Jouni Malinen818965d2016-02-26 22:12:47 +02006180 if (info->attrs[NL80211_ATTR_MAC])
6181 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6182 ETH_ALEN);
6183 else
6184 eth_broadcast_addr(request->bssid);
6185
Johannes Bergfd014282012-06-18 19:17:03 +02006186 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006187 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006188 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006189
Johannes Berg79c97e92009-07-07 03:56:12 +02006190 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006191 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006192
Johannes Berg463d0182009-07-14 00:33:35 +02006193 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006194 nl80211_send_scan_start(rdev, wdev);
6195 if (wdev->netdev)
6196 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006197 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006198 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006199 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006200 kfree(request);
6201 }
Johannes Berg3b858752009-03-12 09:55:09 +01006202
Johannes Bergf9f47522013-03-19 15:04:07 +01006203 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006204 return err;
6205}
6206
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306207static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6208{
6209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6210 struct wireless_dev *wdev = info->user_ptr[1];
6211
6212 if (!rdev->ops->abort_scan)
6213 return -EOPNOTSUPP;
6214
6215 if (rdev->scan_msg)
6216 return 0;
6217
6218 if (!rdev->scan_req)
6219 return -ENOENT;
6220
6221 rdev_abort_scan(rdev, wdev);
6222 return 0;
6223}
6224
Avraham Stern3b06d272015-10-12 09:51:34 +03006225static int
6226nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6227 struct cfg80211_sched_scan_request *request,
6228 struct nlattr **attrs)
6229{
6230 int tmp, err, i = 0;
6231 struct nlattr *attr;
6232
6233 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6234 u32 interval;
6235
6236 /*
6237 * If scan plans are not specified,
6238 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6239 * case one scan plan will be set with the specified scan
6240 * interval and infinite number of iterations.
6241 */
6242 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6243 return -EINVAL;
6244
6245 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6246 if (!interval)
6247 return -EINVAL;
6248
6249 request->scan_plans[0].interval =
6250 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6251 if (!request->scan_plans[0].interval)
6252 return -EINVAL;
6253
6254 if (request->scan_plans[0].interval >
6255 wiphy->max_sched_scan_plan_interval)
6256 request->scan_plans[0].interval =
6257 wiphy->max_sched_scan_plan_interval;
6258
6259 return 0;
6260 }
6261
6262 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6263 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6264
6265 if (WARN_ON(i >= n_plans))
6266 return -EINVAL;
6267
6268 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6269 nla_data(attr), nla_len(attr),
6270 nl80211_plan_policy);
6271 if (err)
6272 return err;
6273
6274 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6275 return -EINVAL;
6276
6277 request->scan_plans[i].interval =
6278 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6279 if (!request->scan_plans[i].interval ||
6280 request->scan_plans[i].interval >
6281 wiphy->max_sched_scan_plan_interval)
6282 return -EINVAL;
6283
6284 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6285 request->scan_plans[i].iterations =
6286 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6287 if (!request->scan_plans[i].iterations ||
6288 (request->scan_plans[i].iterations >
6289 wiphy->max_sched_scan_plan_iterations))
6290 return -EINVAL;
6291 } else if (i < n_plans - 1) {
6292 /*
6293 * All scan plans but the last one must specify
6294 * a finite number of iterations
6295 */
6296 return -EINVAL;
6297 }
6298
6299 i++;
6300 }
6301
6302 /*
6303 * The last scan plan must not specify the number of
6304 * iterations, it is supposed to run infinitely
6305 */
6306 if (request->scan_plans[n_plans - 1].iterations)
6307 return -EINVAL;
6308
6309 return 0;
6310}
6311
Luciano Coelho256da022014-11-10 16:13:46 +02006312static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006313nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006314 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006315{
6316 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006317 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006318 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006319 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006320 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006321 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006322 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006323
Luciano Coelho256da022014-11-10 16:13:46 +02006324 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6325 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006326
Luciano Coelho256da022014-11-10 16:13:46 +02006327 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006328 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006329 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006330 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006331 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006332 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006333 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006334 }
6335
Luciano Coelho256da022014-11-10 16:13:46 +02006336 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6337 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006338 tmp)
6339 n_ssids++;
6340
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006341 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006342 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006343
Johannes Bergea73cbc2014-01-24 10:53:53 +01006344 /*
6345 * First, count the number of 'real' matchsets. Due to an issue with
6346 * the old implementation, matchsets containing only the RSSI attribute
6347 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6348 * RSSI for all matchsets, rather than their own matchset for reporting
6349 * all APs with a strong RSSI. This is needed to be compatible with
6350 * older userspace that treated a matchset with only the RSSI as the
6351 * global RSSI for all other matchsets - if there are other matchsets.
6352 */
Luciano Coelho256da022014-11-10 16:13:46 +02006353 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006354 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006355 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006356 tmp) {
6357 struct nlattr *rssi;
6358
6359 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6360 nla_data(attr), nla_len(attr),
6361 nl80211_match_policy);
6362 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006363 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006364 /* add other standalone attributes here */
6365 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6366 n_match_sets++;
6367 continue;
6368 }
6369 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6370 if (rssi)
6371 default_match_rssi = nla_get_s32(rssi);
6372 }
6373 }
6374
6375 /* However, if there's no other matchset, add the RSSI one */
6376 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6377 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006378
6379 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006380 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006381
Luciano Coelho256da022014-11-10 16:13:46 +02006382 if (attrs[NL80211_ATTR_IE])
6383 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006384 else
6385 ie_len = 0;
6386
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006387 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006388 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006389
Avraham Stern3b06d272015-10-12 09:51:34 +03006390 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6391 /*
6392 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6393 * each scan plan already specifies its own interval
6394 */
6395 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6396 return ERR_PTR(-EINVAL);
6397
6398 nla_for_each_nested(attr,
6399 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6400 n_plans++;
6401 } else {
6402 /*
6403 * The scan interval attribute is kept for backward
6404 * compatibility. If no scan plans are specified and sched scan
6405 * interval is specified, one scan plan will be set with this
6406 * scan interval and infinite number of iterations.
6407 */
6408 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6409 return ERR_PTR(-EINVAL);
6410
6411 n_plans = 1;
6412 }
6413
6414 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6415 return ERR_PTR(-EINVAL);
6416
Luciano Coelho807f8a82011-05-11 17:09:35 +03006417 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006418 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006419 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006420 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006421 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006422 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006423 if (!request)
6424 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006425
6426 if (n_ssids)
6427 request->ssids = (void *)&request->channels[n_channels];
6428 request->n_ssids = n_ssids;
6429 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006430 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006431 request->ie = (void *)(request->ssids + n_ssids);
6432 else
6433 request->ie = (void *)(request->channels + n_channels);
6434 }
6435
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006436 if (n_match_sets) {
6437 if (request->ie)
6438 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006439 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006440 request->match_sets =
6441 (void *)(request->ssids + n_ssids);
6442 else
6443 request->match_sets =
6444 (void *)(request->channels + n_channels);
6445 }
6446 request->n_match_sets = n_match_sets;
6447
Avraham Stern3b06d272015-10-12 09:51:34 +03006448 if (n_match_sets)
6449 request->scan_plans = (void *)(request->match_sets +
6450 n_match_sets);
6451 else if (request->ie)
6452 request->scan_plans = (void *)(request->ie + ie_len);
6453 else if (n_ssids)
6454 request->scan_plans = (void *)(request->ssids + n_ssids);
6455 else
6456 request->scan_plans = (void *)(request->channels + n_channels);
6457
6458 request->n_scan_plans = n_plans;
6459
Luciano Coelho807f8a82011-05-11 17:09:35 +03006460 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006461 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006462 /* user specified, bail out if channel not found */
6463 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006464 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006465 tmp) {
6466 struct ieee80211_channel *chan;
6467
6468 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6469
6470 if (!chan) {
6471 err = -EINVAL;
6472 goto out_free;
6473 }
6474
6475 /* ignore disabled channels */
6476 if (chan->flags & IEEE80211_CHAN_DISABLED)
6477 continue;
6478
6479 request->channels[i] = chan;
6480 i++;
6481 }
6482 } else {
6483 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006484 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006485 int j;
6486 if (!wiphy->bands[band])
6487 continue;
6488 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6489 struct ieee80211_channel *chan;
6490
6491 chan = &wiphy->bands[band]->channels[j];
6492
6493 if (chan->flags & IEEE80211_CHAN_DISABLED)
6494 continue;
6495
6496 request->channels[i] = chan;
6497 i++;
6498 }
6499 }
6500 }
6501
6502 if (!i) {
6503 err = -EINVAL;
6504 goto out_free;
6505 }
6506
6507 request->n_channels = i;
6508
6509 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006510 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006511 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006512 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006513 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006514 err = -EINVAL;
6515 goto out_free;
6516 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006517 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006518 memcpy(request->ssids[i].ssid, nla_data(attr),
6519 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006520 i++;
6521 }
6522 }
6523
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006524 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006525 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006526 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006527 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006528 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006529 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006530
Johannes Bergae811e22014-01-24 10:17:47 +01006531 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6532 nla_data(attr), nla_len(attr),
6533 nl80211_match_policy);
6534 if (err)
6535 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006536 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006537 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006538 if (WARN_ON(i >= n_match_sets)) {
6539 /* this indicates a programming error,
6540 * the loop above should have verified
6541 * things properly
6542 */
6543 err = -EINVAL;
6544 goto out_free;
6545 }
6546
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006547 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6548 err = -EINVAL;
6549 goto out_free;
6550 }
6551 memcpy(request->match_sets[i].ssid.ssid,
6552 nla_data(ssid), nla_len(ssid));
6553 request->match_sets[i].ssid.ssid_len =
6554 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006555 /* special attribute - old implemenation w/a */
6556 request->match_sets[i].rssi_thold =
6557 default_match_rssi;
6558 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6559 if (rssi)
6560 request->match_sets[i].rssi_thold =
6561 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006562 }
6563 i++;
6564 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006565
6566 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006567 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006568 request->match_sets[0].rssi_thold = default_match_rssi;
6569
6570 request->min_rssi_thold = INT_MAX;
6571 for (i = 0; i < n_match_sets; i++)
6572 request->min_rssi_thold =
6573 min(request->match_sets[i].rssi_thold,
6574 request->min_rssi_thold);
6575 } else {
6576 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006577 }
6578
Johannes Berg9900e482014-02-04 21:01:25 +01006579 if (ie_len) {
6580 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006581 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006582 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006583 request->ie_len);
6584 }
6585
Luciano Coelho256da022014-11-10 16:13:46 +02006586 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006587 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006588 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006589 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6590 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006591 err = -EOPNOTSUPP;
6592 goto out_free;
6593 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006594
6595 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6596 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6597
6598 if (!wdev) /* must be net-detect */
6599 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6600
6601 if (!(wiphy->features & flg)) {
6602 err = -EOPNOTSUPP;
6603 goto out_free;
6604 }
6605
6606 if (wdev && wdev->current_bss) {
6607 err = -EOPNOTSUPP;
6608 goto out_free;
6609 }
6610
6611 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6612 request->mac_addr_mask);
6613 if (err)
6614 goto out_free;
6615 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006616 }
Sam Lefflered4737712012-10-11 21:03:31 -07006617
Luciano Coelho9c748932015-01-16 16:04:09 +02006618 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6619 request->delay =
6620 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6621
Avraham Stern3b06d272015-10-12 09:51:34 +03006622 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6623 if (err)
6624 goto out_free;
6625
Sam Leffler15d60302012-10-11 21:03:34 -07006626 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006627
Luciano Coelho256da022014-11-10 16:13:46 +02006628 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006629
6630out_free:
6631 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006632 return ERR_PTR(err);
6633}
6634
6635static int nl80211_start_sched_scan(struct sk_buff *skb,
6636 struct genl_info *info)
6637{
6638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6639 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006640 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006641 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006642 int err;
6643
6644 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6645 !rdev->ops->sched_scan_start)
6646 return -EOPNOTSUPP;
6647
6648 if (rdev->sched_scan_req)
6649 return -EINPROGRESS;
6650
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006651 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6652 info->attrs);
6653
6654 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006655 if (err)
6656 goto out_err;
6657
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006658 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006659 if (err)
6660 goto out_free;
6661
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006662 sched_scan_req->dev = dev;
6663 sched_scan_req->wiphy = &rdev->wiphy;
6664
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006665 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6666 sched_scan_req->owner_nlportid = info->snd_portid;
6667
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006668 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006669
6670 nl80211_send_sched_scan(rdev, dev,
6671 NL80211_CMD_START_SCHED_SCAN);
6672 return 0;
6673
6674out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006675 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006676out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006677 return err;
6678}
6679
6680static int nl80211_stop_sched_scan(struct sk_buff *skb,
6681 struct genl_info *info)
6682{
6683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6684
6685 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6686 !rdev->ops->sched_scan_stop)
6687 return -EOPNOTSUPP;
6688
Johannes Berg5fe231e2013-05-08 21:45:15 +02006689 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006690}
6691
Simon Wunderlich04f39042013-02-08 18:16:19 +01006692static int nl80211_start_radar_detection(struct sk_buff *skb,
6693 struct genl_info *info)
6694{
6695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6696 struct net_device *dev = info->user_ptr[1];
6697 struct wireless_dev *wdev = dev->ieee80211_ptr;
6698 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006699 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006700 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006701 int err;
6702
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006703 dfs_region = reg_get_dfs_region(wdev->wiphy);
6704 if (dfs_region == NL80211_DFS_UNSET)
6705 return -EINVAL;
6706
Simon Wunderlich04f39042013-02-08 18:16:19 +01006707 err = nl80211_parse_chandef(rdev, info, &chandef);
6708 if (err)
6709 return err;
6710
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006711 if (netif_carrier_ok(dev))
6712 return -EBUSY;
6713
Simon Wunderlich04f39042013-02-08 18:16:19 +01006714 if (wdev->cac_started)
6715 return -EBUSY;
6716
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006717 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006718 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006719 if (err < 0)
6720 return err;
6721
6722 if (err == 0)
6723 return -EINVAL;
6724
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006725 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006726 return -EINVAL;
6727
6728 if (!rdev->ops->start_radar_detection)
6729 return -EOPNOTSUPP;
6730
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006731 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6732 if (WARN_ON(!cac_time_ms))
6733 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6734
Ilan Peera1056b12015-10-22 22:27:46 +03006735 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006736 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006737 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006738 wdev->cac_started = true;
6739 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006740 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006741 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006742 return err;
6743}
6744
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006745static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6746{
6747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6748 struct net_device *dev = info->user_ptr[1];
6749 struct wireless_dev *wdev = dev->ieee80211_ptr;
6750 struct cfg80211_csa_settings params;
6751 /* csa_attrs is defined static to avoid waste of stack size - this
6752 * function is called under RTNL lock, so this should not be a problem.
6753 */
6754 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006755 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006756 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006757 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006758 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006759
6760 if (!rdev->ops->channel_switch ||
6761 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6762 return -EOPNOTSUPP;
6763
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006764 switch (dev->ieee80211_ptr->iftype) {
6765 case NL80211_IFTYPE_AP:
6766 case NL80211_IFTYPE_P2P_GO:
6767 need_new_beacon = true;
6768
6769 /* useless if AP is not running */
6770 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006771 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006772 break;
6773 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006774 if (!wdev->ssid_len)
6775 return -ENOTCONN;
6776 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006777 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006778 if (!wdev->mesh_id_len)
6779 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006780 break;
6781 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006782 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006783 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006784
6785 memset(&params, 0, sizeof(params));
6786
6787 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6788 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6789 return -EINVAL;
6790
6791 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006792 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006793 return -EINVAL;
6794
Luciano Coelho252e07c2014-10-08 09:48:34 +03006795 /* Even though the attribute is u32, the specification says
6796 * u8, so let's make sure we don't overflow.
6797 */
6798 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6799 if (cs_count > 255)
6800 return -EINVAL;
6801
6802 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006803
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006804 if (!need_new_beacon)
6805 goto skip_beacons;
6806
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006807 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6808 if (err)
6809 return err;
6810
6811 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6812 info->attrs[NL80211_ATTR_CSA_IES],
6813 nl80211_policy);
6814 if (err)
6815 return err;
6816
6817 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6818 if (err)
6819 return err;
6820
6821 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6822 return -EINVAL;
6823
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006824 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6825 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006826 return -EINVAL;
6827
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006828 params.n_counter_offsets_beacon = len / sizeof(u16);
6829 if (rdev->wiphy.max_num_csa_counters &&
6830 (params.n_counter_offsets_beacon >
6831 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006832 return -EINVAL;
6833
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006834 params.counter_offsets_beacon =
6835 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6836
6837 /* sanity checks - counters should fit and be the same */
6838 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6839 u16 offset = params.counter_offsets_beacon[i];
6840
6841 if (offset >= params.beacon_csa.tail_len)
6842 return -EINVAL;
6843
6844 if (params.beacon_csa.tail[offset] != params.count)
6845 return -EINVAL;
6846 }
6847
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006848 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006849 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6850 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006851 return -EINVAL;
6852
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006853 params.n_counter_offsets_presp = len / sizeof(u16);
6854 if (rdev->wiphy.max_num_csa_counters &&
6855 (params.n_counter_offsets_beacon >
6856 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006857 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006858
6859 params.counter_offsets_presp =
6860 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6861
6862 /* sanity checks - counters should fit and be the same */
6863 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6864 u16 offset = params.counter_offsets_presp[i];
6865
6866 if (offset >= params.beacon_csa.probe_resp_len)
6867 return -EINVAL;
6868
6869 if (params.beacon_csa.probe_resp[offset] !=
6870 params.count)
6871 return -EINVAL;
6872 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006873 }
6874
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006875skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006876 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6877 if (err)
6878 return err;
6879
Arik Nemtsov923b3522015-07-08 15:41:44 +03006880 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6881 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006882 return -EINVAL;
6883
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006884 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6885 &params.chandef,
6886 wdev->iftype);
6887 if (err < 0)
6888 return err;
6889
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006890 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006891 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006892
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006893 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6894 params.block_tx = true;
6895
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006896 wdev_lock(wdev);
6897 err = rdev_channel_switch(rdev, dev, &params);
6898 wdev_unlock(wdev);
6899
6900 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006901}
6902
Johannes Berg9720bb32011-06-21 09:45:33 +02006903static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6904 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006905 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006906 struct wireless_dev *wdev,
6907 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006908{
Johannes Berg48ab9052009-07-10 18:42:31 +02006909 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006910 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006911 void *hdr;
6912 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006913
6914 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006915
Eric W. Biederman15e47302012-09-07 20:12:54 +00006916 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006917 NL80211_CMD_NEW_SCAN_RESULTS);
6918 if (!hdr)
6919 return -1;
6920
Johannes Berg9720bb32011-06-21 09:45:33 +02006921 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6922
Johannes Berg97990a02013-04-19 01:02:55 +02006923 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6924 goto nla_put_failure;
6925 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006926 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6927 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006928 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
6929 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02006930 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006931
6932 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6933 if (!bss)
6934 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006935 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006936 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006937 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006938
6939 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006940 /* indicate whether we have probe response data or not */
6941 if (rcu_access_pointer(res->proberesp_ies) &&
6942 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6943 goto fail_unlock_rcu;
6944
6945 /* this pointer prefers to be pointed to probe response data
6946 * but is always valid
6947 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006948 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006949 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006950 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
6951 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006952 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006953 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6954 ies->len, ies->data))
6955 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006956 }
Johannes Berg0e227082014-08-12 20:34:30 +02006957
6958 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006959 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006960 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006961 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
6962 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006963 goto fail_unlock_rcu;
6964 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6965 ies->len, ies->data))
6966 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006967 }
6968 rcu_read_unlock();
6969
David S. Miller9360ffd2012-03-29 04:41:26 -04006970 if (res->beacon_interval &&
6971 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6972 goto nla_put_failure;
6973 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6974 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006975 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006976 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6977 jiffies_to_msecs(jiffies - intbss->ts)))
6978 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006979
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006980 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006981 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6982 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006983 goto nla_put_failure;
6984
Johannes Berg77965c92009-02-18 18:45:06 +01006985 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006986 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006987 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6988 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006989 break;
6990 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006991 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6992 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006993 break;
6994 default:
6995 break;
6996 }
6997
Johannes Berg48ab9052009-07-10 18:42:31 +02006998 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006999 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007000 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007001 if (intbss == wdev->current_bss &&
7002 nla_put_u32(msg, NL80211_BSS_STATUS,
7003 NL80211_BSS_STATUS_ASSOCIATED))
7004 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007005 break;
7006 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007007 if (intbss == wdev->current_bss &&
7008 nla_put_u32(msg, NL80211_BSS_STATUS,
7009 NL80211_BSS_STATUS_IBSS_JOINED))
7010 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007011 break;
7012 default:
7013 break;
7014 }
7015
Johannes Berg2a519312009-02-10 21:25:55 +01007016 nla_nest_end(msg, bss);
7017
Johannes Berg053c0952015-01-16 22:09:00 +01007018 genlmsg_end(msg, hdr);
7019 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007020
Johannes Berg8cef2c92013-02-05 16:54:31 +01007021 fail_unlock_rcu:
7022 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007023 nla_put_failure:
7024 genlmsg_cancel(msg, hdr);
7025 return -EMSGSIZE;
7026}
7027
Johannes Berg97990a02013-04-19 01:02:55 +02007028static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007029{
Johannes Berg48ab9052009-07-10 18:42:31 +02007030 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007031 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007032 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007033 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007034 int err;
7035
Johannes Berg97990a02013-04-19 01:02:55 +02007036 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007037 if (err)
7038 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007039
Johannes Berg48ab9052009-07-10 18:42:31 +02007040 wdev_lock(wdev);
7041 spin_lock_bh(&rdev->bss_lock);
7042 cfg80211_bss_expire(rdev);
7043
Johannes Berg9720bb32011-06-21 09:45:33 +02007044 cb->seq = rdev->bss_generation;
7045
Johannes Berg48ab9052009-07-10 18:42:31 +02007046 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007047 if (++idx <= start)
7048 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007049 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007050 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007051 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007052 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007053 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007054 }
7055 }
7056
Johannes Berg48ab9052009-07-10 18:42:31 +02007057 spin_unlock_bh(&rdev->bss_lock);
7058 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007059
Johannes Berg97990a02013-04-19 01:02:55 +02007060 cb->args[2] = idx;
7061 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007062
Johannes Berg67748892010-10-04 21:14:06 +02007063 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007064}
7065
Eric W. Biederman15e47302012-09-07 20:12:54 +00007066static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007067 int flags, struct net_device *dev,
7068 bool allow_radio_stats,
7069 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007070{
7071 void *hdr;
7072 struct nlattr *infoattr;
7073
Johannes Berg11f78ac2014-11-14 16:43:50 +01007074 /* skip radio stats if userspace didn't request them */
7075 if (!survey->channel && !allow_radio_stats)
7076 return 0;
7077
Eric W. Biederman15e47302012-09-07 20:12:54 +00007078 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007079 NL80211_CMD_NEW_SURVEY_RESULTS);
7080 if (!hdr)
7081 return -ENOMEM;
7082
David S. Miller9360ffd2012-03-29 04:41:26 -04007083 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7084 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007085
7086 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7087 if (!infoattr)
7088 goto nla_put_failure;
7089
Johannes Berg11f78ac2014-11-14 16:43:50 +01007090 if (survey->channel &&
7091 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007092 survey->channel->center_freq))
7093 goto nla_put_failure;
7094
7095 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7096 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7097 goto nla_put_failure;
7098 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7099 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7100 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007101 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007102 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7103 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007104 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007105 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007106 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7107 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007108 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007109 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007110 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7111 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007112 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007113 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007114 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7115 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007116 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007117 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007118 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7119 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007120 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007121 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007122 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7123 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007124 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007125
7126 nla_nest_end(msg, infoattr);
7127
Johannes Berg053c0952015-01-16 22:09:00 +01007128 genlmsg_end(msg, hdr);
7129 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007130
7131 nla_put_failure:
7132 genlmsg_cancel(msg, hdr);
7133 return -EMSGSIZE;
7134}
7135
Johannes Berg11f78ac2014-11-14 16:43:50 +01007136static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007137{
7138 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007139 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007140 struct wireless_dev *wdev;
7141 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007142 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007143 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007144
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007145 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007146 if (res)
7147 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007148
Johannes Berg11f78ac2014-11-14 16:43:50 +01007149 /* prepare_wdev_dump parsed the attributes */
7150 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7151
Johannes Berg97990a02013-04-19 01:02:55 +02007152 if (!wdev->netdev) {
7153 res = -EINVAL;
7154 goto out_err;
7155 }
7156
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007157 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007158 res = -EOPNOTSUPP;
7159 goto out_err;
7160 }
7161
7162 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007163 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007164 if (res == -ENOENT)
7165 break;
7166 if (res)
7167 goto out_err;
7168
Johannes Berg11f78ac2014-11-14 16:43:50 +01007169 /* don't send disabled channels, but do send non-channel data */
7170 if (survey.channel &&
7171 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007172 survey_idx++;
7173 continue;
7174 }
7175
Holger Schurig61fa7132009-11-11 12:25:40 +01007176 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007177 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007178 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007179 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007180 goto out;
7181 survey_idx++;
7182 }
7183
7184 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007185 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007186 res = skb->len;
7187 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007188 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007189 return res;
7190}
7191
Samuel Ortizb23aa672009-07-01 21:26:54 +02007192static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7193{
7194 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7195 NL80211_WPA_VERSION_2));
7196}
7197
Jouni Malinen636a5d32009-03-19 13:39:22 +02007198static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7199{
Johannes Berg4c476992010-10-04 21:36:35 +02007200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7201 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007202 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007203 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7204 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007205 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007206 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007207 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007208
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007209 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7210 return -EINVAL;
7211
7212 if (!info->attrs[NL80211_ATTR_MAC])
7213 return -EINVAL;
7214
Jouni Malinen17780922009-03-27 20:52:47 +02007215 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7216 return -EINVAL;
7217
Johannes Berg19957bb2009-07-02 17:20:43 +02007218 if (!info->attrs[NL80211_ATTR_SSID])
7219 return -EINVAL;
7220
7221 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7222 return -EINVAL;
7223
Johannes Bergfffd0932009-07-08 14:22:54 +02007224 err = nl80211_parse_key(info, &key);
7225 if (err)
7226 return err;
7227
7228 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007229 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7230 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007231 if (!key.p.key || !key.p.key_len)
7232 return -EINVAL;
7233 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7234 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7235 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7236 key.p.key_len != WLAN_KEY_LEN_WEP104))
7237 return -EINVAL;
7238 if (key.idx > 4)
7239 return -EINVAL;
7240 } else {
7241 key.p.key_len = 0;
7242 key.p.key = NULL;
7243 }
7244
Johannes Bergafea0b72010-08-10 09:46:42 +02007245 if (key.idx >= 0) {
7246 int i;
7247 bool ok = false;
7248 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7249 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7250 ok = true;
7251 break;
7252 }
7253 }
Johannes Berg4c476992010-10-04 21:36:35 +02007254 if (!ok)
7255 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007256 }
7257
Johannes Berg4c476992010-10-04 21:36:35 +02007258 if (!rdev->ops->auth)
7259 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007260
Johannes Berg074ac8d2010-09-16 14:58:22 +02007261 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007262 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7263 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007264
Johannes Berg19957bb2009-07-02 17:20:43 +02007265 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007266 chan = nl80211_get_valid_chan(&rdev->wiphy,
7267 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7268 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007269 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007270
Johannes Berg19957bb2009-07-02 17:20:43 +02007271 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7272 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7273
7274 if (info->attrs[NL80211_ATTR_IE]) {
7275 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7276 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7277 }
7278
7279 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007280 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007281 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007282
Jouni Malinene39e5b52012-09-30 19:29:39 +03007283 if (auth_type == NL80211_AUTHTYPE_SAE &&
7284 !info->attrs[NL80211_ATTR_SAE_DATA])
7285 return -EINVAL;
7286
7287 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7288 if (auth_type != NL80211_AUTHTYPE_SAE)
7289 return -EINVAL;
7290 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7291 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7292 /* need to include at least Auth Transaction and Status Code */
7293 if (sae_data_len < 4)
7294 return -EINVAL;
7295 }
7296
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007297 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7298
Johannes Berg95de8172012-01-20 13:55:25 +01007299 /*
7300 * Since we no longer track auth state, ignore
7301 * requests to only change local state.
7302 */
7303 if (local_state_change)
7304 return 0;
7305
Johannes Berg91bf9b22013-05-15 17:44:01 +02007306 wdev_lock(dev->ieee80211_ptr);
7307 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7308 ssid, ssid_len, ie, ie_len,
7309 key.p.key, key.p.key_len, key.idx,
7310 sae_data, sae_data_len);
7311 wdev_unlock(dev->ieee80211_ptr);
7312 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007313}
7314
Johannes Bergc0692b82010-08-27 14:26:53 +03007315static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7316 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007317 struct cfg80211_crypto_settings *settings,
7318 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007319{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007320 memset(settings, 0, sizeof(*settings));
7321
Samuel Ortizb23aa672009-07-01 21:26:54 +02007322 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7323
Johannes Bergc0692b82010-08-27 14:26:53 +03007324 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7325 u16 proto;
7326 proto = nla_get_u16(
7327 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7328 settings->control_port_ethertype = cpu_to_be16(proto);
7329 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7330 proto != ETH_P_PAE)
7331 return -EINVAL;
7332 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7333 settings->control_port_no_encrypt = true;
7334 } else
7335 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7336
Samuel Ortizb23aa672009-07-01 21:26:54 +02007337 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7338 void *data;
7339 int len, i;
7340
7341 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7342 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7343 settings->n_ciphers_pairwise = len / sizeof(u32);
7344
7345 if (len % sizeof(u32))
7346 return -EINVAL;
7347
Johannes Berg3dc27d22009-07-02 21:36:37 +02007348 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007349 return -EINVAL;
7350
7351 memcpy(settings->ciphers_pairwise, data, len);
7352
7353 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007354 if (!cfg80211_supported_cipher_suite(
7355 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007356 settings->ciphers_pairwise[i]))
7357 return -EINVAL;
7358 }
7359
7360 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7361 settings->cipher_group =
7362 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007363 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7364 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007365 return -EINVAL;
7366 }
7367
7368 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7369 settings->wpa_versions =
7370 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7371 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7372 return -EINVAL;
7373 }
7374
7375 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7376 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007377 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007378
7379 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7380 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7381 settings->n_akm_suites = len / sizeof(u32);
7382
7383 if (len % sizeof(u32))
7384 return -EINVAL;
7385
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007386 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7387 return -EINVAL;
7388
Samuel Ortizb23aa672009-07-01 21:26:54 +02007389 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007390 }
7391
7392 return 0;
7393}
7394
Jouni Malinen636a5d32009-03-19 13:39:22 +02007395static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7396{
Johannes Berg4c476992010-10-04 21:36:35 +02007397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7398 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007399 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007400 struct cfg80211_assoc_request req = {};
7401 const u8 *bssid, *ssid;
7402 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007403
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007404 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7405 return -EINVAL;
7406
7407 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007408 !info->attrs[NL80211_ATTR_SSID] ||
7409 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007410 return -EINVAL;
7411
Johannes Berg4c476992010-10-04 21:36:35 +02007412 if (!rdev->ops->assoc)
7413 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007414
Johannes Berg074ac8d2010-09-16 14:58:22 +02007415 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007416 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7417 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007418
Johannes Berg19957bb2009-07-02 17:20:43 +02007419 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007420
Jouni Malinen664834d2014-01-15 00:01:44 +02007421 chan = nl80211_get_valid_chan(&rdev->wiphy,
7422 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7423 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007424 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007425
Johannes Berg19957bb2009-07-02 17:20:43 +02007426 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7427 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007428
7429 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007430 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7431 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007432 }
7433
Jouni Malinendc6382c2009-05-06 22:09:37 +03007434 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007435 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007436 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007437 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007438 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007439 else if (mfp != NL80211_MFP_NO)
7440 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007441 }
7442
Johannes Berg3e5d7642009-07-07 14:37:26 +02007443 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007444 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007445
Ben Greear7e7c8922011-11-18 11:31:59 -08007446 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007447 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007448
7449 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007450 memcpy(&req.ht_capa_mask,
7451 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7452 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007453
7454 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007455 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007456 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007457 memcpy(&req.ht_capa,
7458 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7459 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007460 }
7461
Johannes Bergee2aca32013-02-21 17:36:01 +01007462 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007463 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007464
7465 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007466 memcpy(&req.vht_capa_mask,
7467 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7468 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007469
7470 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007471 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007472 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007473 memcpy(&req.vht_capa,
7474 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7475 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007476 }
7477
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007478 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007479 if (!((rdev->wiphy.features &
7480 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7481 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7482 !wiphy_ext_feature_isset(&rdev->wiphy,
7483 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007484 return -EINVAL;
7485 req.flags |= ASSOC_REQ_USE_RRM;
7486 }
7487
Johannes Bergf62fab72013-02-21 20:09:09 +01007488 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007489 if (!err) {
7490 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007491 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7492 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007493 wdev_unlock(dev->ieee80211_ptr);
7494 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007495
Jouni Malinen636a5d32009-03-19 13:39:22 +02007496 return err;
7497}
7498
7499static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7500{
Johannes Berg4c476992010-10-04 21:36:35 +02007501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7502 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007503 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007504 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007505 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007506 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007507
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007508 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7509 return -EINVAL;
7510
7511 if (!info->attrs[NL80211_ATTR_MAC])
7512 return -EINVAL;
7513
7514 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7515 return -EINVAL;
7516
Johannes Berg4c476992010-10-04 21:36:35 +02007517 if (!rdev->ops->deauth)
7518 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007519
Johannes Berg074ac8d2010-09-16 14:58:22 +02007520 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007521 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7522 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007523
Johannes Berg19957bb2009-07-02 17:20:43 +02007524 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007525
Johannes Berg19957bb2009-07-02 17:20:43 +02007526 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7527 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007528 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007529 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007530 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007531
7532 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007533 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7534 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007535 }
7536
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007537 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7538
Johannes Berg91bf9b22013-05-15 17:44:01 +02007539 wdev_lock(dev->ieee80211_ptr);
7540 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7541 local_state_change);
7542 wdev_unlock(dev->ieee80211_ptr);
7543 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007544}
7545
7546static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7547{
Johannes Berg4c476992010-10-04 21:36:35 +02007548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7549 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007550 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007551 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007552 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007553 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007554
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007555 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7556 return -EINVAL;
7557
7558 if (!info->attrs[NL80211_ATTR_MAC])
7559 return -EINVAL;
7560
7561 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7562 return -EINVAL;
7563
Johannes Berg4c476992010-10-04 21:36:35 +02007564 if (!rdev->ops->disassoc)
7565 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007566
Johannes Berg074ac8d2010-09-16 14:58:22 +02007567 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007568 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7569 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007570
Johannes Berg19957bb2009-07-02 17:20:43 +02007571 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007572
Johannes Berg19957bb2009-07-02 17:20:43 +02007573 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7574 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007575 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007576 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007577 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007578
7579 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007580 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7581 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007582 }
7583
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007584 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7585
Johannes Berg91bf9b22013-05-15 17:44:01 +02007586 wdev_lock(dev->ieee80211_ptr);
7587 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7588 local_state_change);
7589 wdev_unlock(dev->ieee80211_ptr);
7590 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007591}
7592
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007593static bool
7594nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007595 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007596 int rateval)
7597{
7598 struct wiphy *wiphy = &rdev->wiphy;
7599 bool found = false;
7600 int band, i;
7601
Johannes Berg57fbcce2016-04-12 15:56:15 +02007602 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007603 struct ieee80211_supported_band *sband;
7604
7605 sband = wiphy->bands[band];
7606 if (!sband)
7607 continue;
7608
7609 for (i = 0; i < sband->n_bitrates; i++) {
7610 if (sband->bitrates[i].bitrate == rateval) {
7611 mcast_rate[band] = i + 1;
7612 found = true;
7613 break;
7614 }
7615 }
7616 }
7617
7618 return found;
7619}
7620
Johannes Berg04a773a2009-04-19 21:24:32 +02007621static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7622{
Johannes Berg4c476992010-10-04 21:36:35 +02007623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7624 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007625 struct cfg80211_ibss_params ibss;
7626 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007627 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007628 int err;
7629
Johannes Berg8e30bc52009-04-22 17:45:38 +02007630 memset(&ibss, 0, sizeof(ibss));
7631
Johannes Berg04a773a2009-04-19 21:24:32 +02007632 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7633 return -EINVAL;
7634
Johannes Berg683b6d32012-11-08 21:25:48 +01007635 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007636 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7637 return -EINVAL;
7638
Johannes Berg8e30bc52009-04-22 17:45:38 +02007639 ibss.beacon_interval = 100;
7640
7641 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7642 ibss.beacon_interval =
7643 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7644 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7645 return -EINVAL;
7646 }
7647
Johannes Berg4c476992010-10-04 21:36:35 +02007648 if (!rdev->ops->join_ibss)
7649 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007650
Johannes Berg4c476992010-10-04 21:36:35 +02007651 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7652 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007653
Johannes Berg79c97e92009-07-07 03:56:12 +02007654 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007655
Johannes Berg39193492011-09-16 13:45:25 +02007656 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007657 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007658
7659 if (!is_valid_ether_addr(ibss.bssid))
7660 return -EINVAL;
7661 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007662 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7663 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7664
7665 if (info->attrs[NL80211_ATTR_IE]) {
7666 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7667 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7668 }
7669
Johannes Berg683b6d32012-11-08 21:25:48 +01007670 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7671 if (err)
7672 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007673
Ilan Peer174e0cd2014-02-23 09:13:01 +02007674 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7675 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007676 return -EINVAL;
7677
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007678 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007679 case NL80211_CHAN_WIDTH_5:
7680 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007681 case NL80211_CHAN_WIDTH_20_NOHT:
7682 break;
7683 case NL80211_CHAN_WIDTH_20:
7684 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007685 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7686 return -EINVAL;
7687 break;
7688 case NL80211_CHAN_WIDTH_80:
7689 case NL80211_CHAN_WIDTH_80P80:
7690 case NL80211_CHAN_WIDTH_160:
7691 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7692 return -EINVAL;
7693 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7694 NL80211_EXT_FEATURE_VHT_IBSS))
7695 return -EINVAL;
7696 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007697 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007698 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007699 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007700
Johannes Berg04a773a2009-04-19 21:24:32 +02007701 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007702 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007703
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007704 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7705 u8 *rates =
7706 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7707 int n_rates =
7708 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7709 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007710 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007711
Johannes Berg34850ab2011-07-18 18:08:35 +02007712 err = ieee80211_get_ratemask(sband, rates, n_rates,
7713 &ibss.basic_rates);
7714 if (err)
7715 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007716 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007717
Simon Wunderlich803768f2013-06-28 10:39:58 +02007718 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7719 memcpy(&ibss.ht_capa_mask,
7720 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7721 sizeof(ibss.ht_capa_mask));
7722
7723 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7724 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7725 return -EINVAL;
7726 memcpy(&ibss.ht_capa,
7727 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7728 sizeof(ibss.ht_capa));
7729 }
7730
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007731 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7732 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7733 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7734 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007735
Johannes Berg4c476992010-10-04 21:36:35 +02007736 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307737 bool no_ht = false;
7738
Johannes Berg4c476992010-10-04 21:36:35 +02007739 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307740 info->attrs[NL80211_ATTR_KEYS],
7741 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007742 if (IS_ERR(connkeys))
7743 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307744
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007745 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7746 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007747 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307748 return -EINVAL;
7749 }
Johannes Berg4c476992010-10-04 21:36:35 +02007750 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007751
Antonio Quartulli267335d2012-01-31 20:25:47 +01007752 ibss.control_port =
7753 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7754
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007755 ibss.userspace_handles_dfs =
7756 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7757
Johannes Berg4c476992010-10-04 21:36:35 +02007758 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007759 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007760 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007761 return err;
7762}
7763
7764static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7765{
Johannes Berg4c476992010-10-04 21:36:35 +02007766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7767 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007768
Johannes Berg4c476992010-10-04 21:36:35 +02007769 if (!rdev->ops->leave_ibss)
7770 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007771
Johannes Berg4c476992010-10-04 21:36:35 +02007772 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7773 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007774
Johannes Berg4c476992010-10-04 21:36:35 +02007775 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007776}
7777
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007778static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7779{
7780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7781 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007782 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007783 u32 nla_rate;
7784 int err;
7785
7786 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007787 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7788 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007789 return -EOPNOTSUPP;
7790
7791 if (!rdev->ops->set_mcast_rate)
7792 return -EOPNOTSUPP;
7793
7794 memset(mcast_rate, 0, sizeof(mcast_rate));
7795
7796 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7797 return -EINVAL;
7798
7799 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7800 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7801 return -EINVAL;
7802
Ilan Peera1056b12015-10-22 22:27:46 +03007803 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007804
7805 return err;
7806}
7807
Johannes Bergad7e7182013-11-13 13:37:47 +01007808static struct sk_buff *
7809__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007810 struct wireless_dev *wdev, int approxlen,
7811 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007812 enum nl80211_attrs attr,
7813 const struct nl80211_vendor_cmd_info *info,
7814 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007815{
7816 struct sk_buff *skb;
7817 void *hdr;
7818 struct nlattr *data;
7819
7820 skb = nlmsg_new(approxlen + 100, gfp);
7821 if (!skb)
7822 return NULL;
7823
7824 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7825 if (!hdr) {
7826 kfree_skb(skb);
7827 return NULL;
7828 }
7829
7830 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7831 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007832
7833 if (info) {
7834 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7835 info->vendor_id))
7836 goto nla_put_failure;
7837 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7838 info->subcmd))
7839 goto nla_put_failure;
7840 }
7841
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007842 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007843 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7844 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007845 goto nla_put_failure;
7846 if (wdev->netdev &&
7847 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7848 wdev->netdev->ifindex))
7849 goto nla_put_failure;
7850 }
7851
Johannes Bergad7e7182013-11-13 13:37:47 +01007852 data = nla_nest_start(skb, attr);
7853
7854 ((void **)skb->cb)[0] = rdev;
7855 ((void **)skb->cb)[1] = hdr;
7856 ((void **)skb->cb)[2] = data;
7857
7858 return skb;
7859
7860 nla_put_failure:
7861 kfree_skb(skb);
7862 return NULL;
7863}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007864
Johannes Berge03ad6e2014-01-01 17:22:30 +01007865struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007866 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007867 enum nl80211_commands cmd,
7868 enum nl80211_attrs attr,
7869 int vendor_event_idx,
7870 int approxlen, gfp_t gfp)
7871{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007872 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007873 const struct nl80211_vendor_cmd_info *info;
7874
7875 switch (cmd) {
7876 case NL80211_CMD_TESTMODE:
7877 if (WARN_ON(vendor_event_idx != -1))
7878 return NULL;
7879 info = NULL;
7880 break;
7881 case NL80211_CMD_VENDOR:
7882 if (WARN_ON(vendor_event_idx < 0 ||
7883 vendor_event_idx >= wiphy->n_vendor_events))
7884 return NULL;
7885 info = &wiphy->vendor_events[vendor_event_idx];
7886 break;
7887 default:
7888 WARN_ON(1);
7889 return NULL;
7890 }
7891
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007892 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007893 cmd, attr, info, gfp);
7894}
7895EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7896
7897void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7898{
7899 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7900 void *hdr = ((void **)skb->cb)[1];
7901 struct nlattr *data = ((void **)skb->cb)[2];
7902 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7903
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007904 /* clear CB data for netlink core to own from now on */
7905 memset(skb->cb, 0, sizeof(skb->cb));
7906
Johannes Berge03ad6e2014-01-01 17:22:30 +01007907 nla_nest_end(skb, data);
7908 genlmsg_end(skb, hdr);
7909
7910 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7911 mcgrp = NL80211_MCGRP_VENDOR;
7912
7913 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7914 mcgrp, gfp);
7915}
7916EXPORT_SYMBOL(__cfg80211_send_event_skb);
7917
Johannes Bergaff89a92009-07-01 21:26:51 +02007918#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007919static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7920{
Johannes Berg4c476992010-10-04 21:36:35 +02007921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007922 struct wireless_dev *wdev =
7923 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007924 int err;
7925
David Spinadelfc73f112013-07-31 18:04:15 +03007926 if (!rdev->ops->testmode_cmd)
7927 return -EOPNOTSUPP;
7928
7929 if (IS_ERR(wdev)) {
7930 err = PTR_ERR(wdev);
7931 if (err != -EINVAL)
7932 return err;
7933 wdev = NULL;
7934 } else if (wdev->wiphy != &rdev->wiphy) {
7935 return -EINVAL;
7936 }
7937
Johannes Bergaff89a92009-07-01 21:26:51 +02007938 if (!info->attrs[NL80211_ATTR_TESTDATA])
7939 return -EINVAL;
7940
Johannes Bergad7e7182013-11-13 13:37:47 +01007941 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007942 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007943 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7944 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007945 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007946
Johannes Bergaff89a92009-07-01 21:26:51 +02007947 return err;
7948}
7949
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007950static int nl80211_testmode_dump(struct sk_buff *skb,
7951 struct netlink_callback *cb)
7952{
Johannes Berg00918d32011-12-13 17:22:05 +01007953 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007954 int err;
7955 long phy_idx;
7956 void *data = NULL;
7957 int data_len = 0;
7958
Johannes Berg5fe231e2013-05-08 21:45:15 +02007959 rtnl_lock();
7960
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007961 if (cb->args[0]) {
7962 /*
7963 * 0 is a valid index, but not valid for args[0],
7964 * so we need to offset by 1.
7965 */
7966 phy_idx = cb->args[0] - 1;
7967 } else {
7968 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7969 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7970 nl80211_policy);
7971 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007972 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007973
Johannes Berg2bd7e352012-06-15 14:23:16 +02007974 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7975 nl80211_fam.attrbuf);
7976 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007977 err = PTR_ERR(rdev);
7978 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007979 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007980 phy_idx = rdev->wiphy_idx;
7981 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007982
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007983 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7984 cb->args[1] =
7985 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7986 }
7987
7988 if (cb->args[1]) {
7989 data = nla_data((void *)cb->args[1]);
7990 data_len = nla_len((void *)cb->args[1]);
7991 }
7992
Johannes Berg00918d32011-12-13 17:22:05 +01007993 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7994 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007995 err = -ENOENT;
7996 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007997 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007998
Johannes Berg00918d32011-12-13 17:22:05 +01007999 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008000 err = -EOPNOTSUPP;
8001 goto out_err;
8002 }
8003
8004 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008005 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008006 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8007 NL80211_CMD_TESTMODE);
8008 struct nlattr *tmdata;
8009
Dan Carpentercb35fba2013-08-14 14:50:01 +03008010 if (!hdr)
8011 break;
8012
David S. Miller9360ffd2012-03-29 04:41:26 -04008013 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008014 genlmsg_cancel(skb, hdr);
8015 break;
8016 }
8017
8018 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8019 if (!tmdata) {
8020 genlmsg_cancel(skb, hdr);
8021 break;
8022 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008023 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008024 nla_nest_end(skb, tmdata);
8025
8026 if (err == -ENOBUFS || err == -ENOENT) {
8027 genlmsg_cancel(skb, hdr);
8028 break;
8029 } else if (err) {
8030 genlmsg_cancel(skb, hdr);
8031 goto out_err;
8032 }
8033
8034 genlmsg_end(skb, hdr);
8035 }
8036
8037 err = skb->len;
8038 /* see above */
8039 cb->args[0] = phy_idx + 1;
8040 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008041 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008042 return err;
8043}
Johannes Bergaff89a92009-07-01 21:26:51 +02008044#endif
8045
Samuel Ortizb23aa672009-07-01 21:26:54 +02008046static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8047{
Johannes Berg4c476992010-10-04 21:36:35 +02008048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8049 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008050 struct cfg80211_connect_params connect;
8051 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008052 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008053 int err;
8054
8055 memset(&connect, 0, sizeof(connect));
8056
8057 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8058 return -EINVAL;
8059
8060 if (!info->attrs[NL80211_ATTR_SSID] ||
8061 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8062 return -EINVAL;
8063
8064 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8065 connect.auth_type =
8066 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008067 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8068 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008069 return -EINVAL;
8070 } else
8071 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8072
8073 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8074
Johannes Bergc0692b82010-08-27 14:26:53 +03008075 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008076 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008077 if (err)
8078 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008079
Johannes Berg074ac8d2010-09-16 14:58:22 +02008080 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008081 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8082 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008083
Johannes Berg79c97e92009-07-07 03:56:12 +02008084 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008085
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308086 connect.bg_scan_period = -1;
8087 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8088 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8089 connect.bg_scan_period =
8090 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8091 }
8092
Samuel Ortizb23aa672009-07-01 21:26:54 +02008093 if (info->attrs[NL80211_ATTR_MAC])
8094 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008095 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8096 connect.bssid_hint =
8097 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008098 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8099 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8100
8101 if (info->attrs[NL80211_ATTR_IE]) {
8102 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8103 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8104 }
8105
Jouni Malinencee00a92013-01-15 17:15:57 +02008106 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8107 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8108 if (connect.mfp != NL80211_MFP_REQUIRED &&
8109 connect.mfp != NL80211_MFP_NO)
8110 return -EINVAL;
8111 } else {
8112 connect.mfp = NL80211_MFP_NO;
8113 }
8114
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008115 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8116 connect.prev_bssid =
8117 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8118
Samuel Ortizb23aa672009-07-01 21:26:54 +02008119 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008120 connect.channel = nl80211_get_valid_chan(
8121 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8122 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008123 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008124 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008125 connect.channel_hint = nl80211_get_valid_chan(
8126 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8127 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008128 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008129 }
8130
Johannes Bergfffd0932009-07-08 14:22:54 +02008131 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8132 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308133 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008134 if (IS_ERR(connkeys))
8135 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008136 }
8137
Ben Greear7e7c8922011-11-18 11:31:59 -08008138 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8139 connect.flags |= ASSOC_REQ_DISABLE_HT;
8140
8141 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8142 memcpy(&connect.ht_capa_mask,
8143 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8144 sizeof(connect.ht_capa_mask));
8145
8146 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008147 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008148 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008149 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008150 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008151 memcpy(&connect.ht_capa,
8152 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8153 sizeof(connect.ht_capa));
8154 }
8155
Johannes Bergee2aca32013-02-21 17:36:01 +01008156 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8157 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8158
8159 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8160 memcpy(&connect.vht_capa_mask,
8161 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8162 sizeof(connect.vht_capa_mask));
8163
8164 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8165 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008166 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008167 return -EINVAL;
8168 }
8169 memcpy(&connect.vht_capa,
8170 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8171 sizeof(connect.vht_capa));
8172 }
8173
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008174 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008175 if (!((rdev->wiphy.features &
8176 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8177 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8178 !wiphy_ext_feature_isset(&rdev->wiphy,
8179 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008180 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008181 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008182 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008183 connect.flags |= ASSOC_REQ_USE_RRM;
8184 }
8185
Lior David34d50512016-01-28 10:58:25 +02008186 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008187 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008188 kzfree(connkeys);
8189 return -EOPNOTSUPP;
8190 }
8191
Arend van Spriel38de03d2016-03-02 20:37:18 +01008192 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8193 /* bss selection makes no sense if bssid is set */
8194 if (connect.bssid) {
8195 kzfree(connkeys);
8196 return -EINVAL;
8197 }
8198
8199 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8200 wiphy, &connect.bss_select);
8201 if (err) {
8202 kzfree(connkeys);
8203 return err;
8204 }
8205 }
8206
Johannes Berg83739b02013-05-15 17:44:01 +02008207 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008208 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8209 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008210 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008211 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008212 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008213 return err;
8214}
8215
8216static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8217{
Johannes Berg4c476992010-10-04 21:36:35 +02008218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8219 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008220 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008221 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008222
8223 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8224 reason = WLAN_REASON_DEAUTH_LEAVING;
8225 else
8226 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8227
8228 if (reason == 0)
8229 return -EINVAL;
8230
Johannes Berg074ac8d2010-09-16 14:58:22 +02008231 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008232 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8233 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008234
Johannes Berg83739b02013-05-15 17:44:01 +02008235 wdev_lock(dev->ieee80211_ptr);
8236 ret = cfg80211_disconnect(rdev, dev, reason, true);
8237 wdev_unlock(dev->ieee80211_ptr);
8238 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008239}
8240
Johannes Berg463d0182009-07-14 00:33:35 +02008241static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8242{
Johannes Berg4c476992010-10-04 21:36:35 +02008243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008244 struct net *net;
8245 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008246
Vadim Kochan4b681c82015-01-12 16:34:05 +02008247 if (info->attrs[NL80211_ATTR_PID]) {
8248 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8249
8250 net = get_net_ns_by_pid(pid);
8251 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8252 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8253
8254 net = get_net_ns_by_fd(fd);
8255 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008256 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008257 }
Johannes Berg463d0182009-07-14 00:33:35 +02008258
Johannes Berg4c476992010-10-04 21:36:35 +02008259 if (IS_ERR(net))
8260 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008261
8262 err = 0;
8263
8264 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008265 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8266 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008267
Johannes Berg463d0182009-07-14 00:33:35 +02008268 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008269 return err;
8270}
8271
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008272static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8273{
Johannes Berg4c476992010-10-04 21:36:35 +02008274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008275 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8276 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008277 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008278 struct cfg80211_pmksa pmksa;
8279
8280 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8281
8282 if (!info->attrs[NL80211_ATTR_MAC])
8283 return -EINVAL;
8284
8285 if (!info->attrs[NL80211_ATTR_PMKID])
8286 return -EINVAL;
8287
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008288 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8289 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8290
Johannes Berg074ac8d2010-09-16 14:58:22 +02008291 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008292 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8293 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008294
8295 switch (info->genlhdr->cmd) {
8296 case NL80211_CMD_SET_PMKSA:
8297 rdev_ops = rdev->ops->set_pmksa;
8298 break;
8299 case NL80211_CMD_DEL_PMKSA:
8300 rdev_ops = rdev->ops->del_pmksa;
8301 break;
8302 default:
8303 WARN_ON(1);
8304 break;
8305 }
8306
Johannes Berg4c476992010-10-04 21:36:35 +02008307 if (!rdev_ops)
8308 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008309
Johannes Berg4c476992010-10-04 21:36:35 +02008310 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008311}
8312
8313static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8314{
Johannes Berg4c476992010-10-04 21:36:35 +02008315 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8316 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008317
Johannes Berg074ac8d2010-09-16 14:58:22 +02008318 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008319 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8320 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008321
Johannes Berg4c476992010-10-04 21:36:35 +02008322 if (!rdev->ops->flush_pmksa)
8323 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008324
Hila Gonene35e4d22012-06-27 17:19:42 +03008325 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008326}
8327
Arik Nemtsov109086c2011-09-28 14:12:50 +03008328static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8329{
8330 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8331 struct net_device *dev = info->user_ptr[1];
8332 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308333 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008334 u16 status_code;
8335 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008336 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008337
8338 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8339 !rdev->ops->tdls_mgmt)
8340 return -EOPNOTSUPP;
8341
8342 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8343 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8344 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8345 !info->attrs[NL80211_ATTR_IE] ||
8346 !info->attrs[NL80211_ATTR_MAC])
8347 return -EINVAL;
8348
8349 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8350 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8351 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8352 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008353 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308354 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8355 peer_capability =
8356 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008357
Hila Gonene35e4d22012-06-27 17:19:42 +03008358 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308359 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008360 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008361 nla_data(info->attrs[NL80211_ATTR_IE]),
8362 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008363}
8364
8365static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8366{
8367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8368 struct net_device *dev = info->user_ptr[1];
8369 enum nl80211_tdls_operation operation;
8370 u8 *peer;
8371
8372 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8373 !rdev->ops->tdls_oper)
8374 return -EOPNOTSUPP;
8375
8376 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8377 !info->attrs[NL80211_ATTR_MAC])
8378 return -EINVAL;
8379
8380 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8381 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8382
Hila Gonene35e4d22012-06-27 17:19:42 +03008383 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008384}
8385
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008386static int nl80211_remain_on_channel(struct sk_buff *skb,
8387 struct genl_info *info)
8388{
Johannes Berg4c476992010-10-04 21:36:35 +02008389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008390 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008391 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008392 struct sk_buff *msg;
8393 void *hdr;
8394 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008395 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008396 int err;
8397
8398 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8399 !info->attrs[NL80211_ATTR_DURATION])
8400 return -EINVAL;
8401
8402 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8403
Johannes Berg7c4ef712011-11-18 15:33:48 +01008404 if (!rdev->ops->remain_on_channel ||
8405 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008406 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008407
Johannes Bergebf348f2012-06-01 12:50:54 +02008408 /*
8409 * We should be on that channel for at least a minimum amount of
8410 * time (10ms) but no longer than the driver supports.
8411 */
8412 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8413 duration > rdev->wiphy.max_remain_on_channel_duration)
8414 return -EINVAL;
8415
Johannes Berg683b6d32012-11-08 21:25:48 +01008416 err = nl80211_parse_chandef(rdev, info, &chandef);
8417 if (err)
8418 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008419
8420 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008421 if (!msg)
8422 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008423
Eric W. Biederman15e47302012-09-07 20:12:54 +00008424 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008425 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008426 if (!hdr) {
8427 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008428 goto free_msg;
8429 }
8430
Johannes Berg683b6d32012-11-08 21:25:48 +01008431 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8432 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008433
8434 if (err)
8435 goto free_msg;
8436
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008437 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8438 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008439 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008440
8441 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008442
8443 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008444
8445 nla_put_failure:
8446 err = -ENOBUFS;
8447 free_msg:
8448 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008449 return err;
8450}
8451
8452static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8453 struct genl_info *info)
8454{
Johannes Berg4c476992010-10-04 21:36:35 +02008455 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008456 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008457 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008458
8459 if (!info->attrs[NL80211_ATTR_COOKIE])
8460 return -EINVAL;
8461
Johannes Berg4c476992010-10-04 21:36:35 +02008462 if (!rdev->ops->cancel_remain_on_channel)
8463 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008464
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008465 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8466
Hila Gonene35e4d22012-06-27 17:19:42 +03008467 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008468}
8469
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008470static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8471 u8 *rates, u8 rates_len)
8472{
8473 u8 i;
8474 u32 mask = 0;
8475
8476 for (i = 0; i < rates_len; i++) {
8477 int rate = (rates[i] & 0x7f) * 5;
8478 int ridx;
8479 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8480 struct ieee80211_rate *srate =
8481 &sband->bitrates[ridx];
8482 if (rate == srate->bitrate) {
8483 mask |= 1 << ridx;
8484 break;
8485 }
8486 }
8487 if (ridx == sband->n_bitrates)
8488 return 0; /* rate not found */
8489 }
8490
8491 return mask;
8492}
8493
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008494static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8495 u8 *rates, u8 rates_len,
8496 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8497{
8498 u8 i;
8499
8500 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8501
8502 for (i = 0; i < rates_len; i++) {
8503 int ridx, rbit;
8504
8505 ridx = rates[i] / 8;
8506 rbit = BIT(rates[i] % 8);
8507
8508 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008509 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008510 return false;
8511
8512 /* check availability */
8513 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8514 mcs[ridx] |= rbit;
8515 else
8516 return false;
8517 }
8518
8519 return true;
8520}
8521
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008522static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8523{
8524 u16 mcs_mask = 0;
8525
8526 switch (vht_mcs_map) {
8527 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8528 break;
8529 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8530 mcs_mask = 0x00FF;
8531 break;
8532 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8533 mcs_mask = 0x01FF;
8534 break;
8535 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8536 mcs_mask = 0x03FF;
8537 break;
8538 default:
8539 break;
8540 }
8541
8542 return mcs_mask;
8543}
8544
8545static void vht_build_mcs_mask(u16 vht_mcs_map,
8546 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8547{
8548 u8 nss;
8549
8550 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8551 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8552 vht_mcs_map >>= 2;
8553 }
8554}
8555
8556static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8557 struct nl80211_txrate_vht *txrate,
8558 u16 mcs[NL80211_VHT_NSS_MAX])
8559{
8560 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8561 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8562 u8 i;
8563
8564 if (!sband->vht_cap.vht_supported)
8565 return false;
8566
8567 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8568
8569 /* Build vht_mcs_mask from VHT capabilities */
8570 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8571
8572 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8573 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8574 mcs[i] = txrate->mcs[i];
8575 else
8576 return false;
8577 }
8578
8579 return true;
8580}
8581
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008582static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008583 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8584 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008585 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8586 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008587 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008588 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008589};
8590
8591static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8592 struct genl_info *info)
8593{
8594 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008596 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008597 int rem, i;
8598 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008599 struct nlattr *tx_rates;
8600 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008601 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008602
Johannes Berg4c476992010-10-04 21:36:35 +02008603 if (!rdev->ops->set_bitrate_mask)
8604 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008605
8606 memset(&mask, 0, sizeof(mask));
8607 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008608 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008609 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008610
8611 if (!sband)
8612 continue;
8613
8614 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008615 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008616 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008617 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008618
8619 if (!sband->vht_cap.vht_supported)
8620 continue;
8621
8622 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8623 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008624 }
8625
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008626 /* if no rates are given set it back to the defaults */
8627 if (!info->attrs[NL80211_ATTR_TX_RATES])
8628 goto out;
8629
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008630 /*
8631 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008632 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008633 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008634 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008635 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008636 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008637 int err;
8638
Johannes Berg57fbcce2016-04-12 15:56:15 +02008639 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008640 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008641 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008642 if (sband == NULL)
8643 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008644 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8645 nla_len(tx_rates), nl80211_txattr_policy);
8646 if (err)
8647 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008648 if (tb[NL80211_TXRATE_LEGACY]) {
8649 mask.control[band].legacy = rateset_to_mask(
8650 sband,
8651 nla_data(tb[NL80211_TXRATE_LEGACY]),
8652 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308653 if ((mask.control[band].legacy == 0) &&
8654 nla_len(tb[NL80211_TXRATE_LEGACY]))
8655 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008656 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008657 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008658 if (!ht_rateset_to_mask(
8659 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008660 nla_data(tb[NL80211_TXRATE_HT]),
8661 nla_len(tb[NL80211_TXRATE_HT]),
8662 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008663 return -EINVAL;
8664 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008665 if (tb[NL80211_TXRATE_VHT]) {
8666 if (!vht_set_mcs_mask(
8667 sband,
8668 nla_data(tb[NL80211_TXRATE_VHT]),
8669 mask.control[band].vht_mcs))
8670 return -EINVAL;
8671 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008672 if (tb[NL80211_TXRATE_GI]) {
8673 mask.control[band].gi =
8674 nla_get_u8(tb[NL80211_TXRATE_GI]);
8675 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8676 return -EINVAL;
8677 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008678
8679 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008680 /* don't allow empty legacy rates if HT or VHT
8681 * are not even supported.
8682 */
8683 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8684 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008685 return -EINVAL;
8686
8687 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008688 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008689 goto out;
8690
8691 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8692 if (mask.control[band].vht_mcs[i])
8693 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008694
8695 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008696 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008697 }
8698 }
8699
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008700out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008701 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008702}
8703
Johannes Berg2e161f72010-08-12 15:38:38 +02008704static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008705{
Johannes Berg4c476992010-10-04 21:36:35 +02008706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008707 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008708 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008709
8710 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8711 return -EINVAL;
8712
Johannes Berg2e161f72010-08-12 15:38:38 +02008713 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8714 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008715
Johannes Berg71bbc992012-06-15 15:30:18 +02008716 switch (wdev->iftype) {
8717 case NL80211_IFTYPE_STATION:
8718 case NL80211_IFTYPE_ADHOC:
8719 case NL80211_IFTYPE_P2P_CLIENT:
8720 case NL80211_IFTYPE_AP:
8721 case NL80211_IFTYPE_AP_VLAN:
8722 case NL80211_IFTYPE_MESH_POINT:
8723 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008724 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008725 break;
8726 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008727 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008728 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008729
8730 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008731 if (!rdev->ops->mgmt_tx)
8732 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008733
Eric W. Biederman15e47302012-09-07 20:12:54 +00008734 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008735 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8736 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008737}
8738
Johannes Berg2e161f72010-08-12 15:38:38 +02008739static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008740{
Johannes Berg4c476992010-10-04 21:36:35 +02008741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008742 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008743 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008744 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008745 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008746 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008747 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008748 struct cfg80211_mgmt_tx_params params = {
8749 .dont_wait_for_ack =
8750 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8751 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008752
Johannes Berg683b6d32012-11-08 21:25:48 +01008753 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008754 return -EINVAL;
8755
Johannes Berg4c476992010-10-04 21:36:35 +02008756 if (!rdev->ops->mgmt_tx)
8757 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008758
Johannes Berg71bbc992012-06-15 15:30:18 +02008759 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008760 case NL80211_IFTYPE_P2P_DEVICE:
8761 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8762 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008763 case NL80211_IFTYPE_STATION:
8764 case NL80211_IFTYPE_ADHOC:
8765 case NL80211_IFTYPE_P2P_CLIENT:
8766 case NL80211_IFTYPE_AP:
8767 case NL80211_IFTYPE_AP_VLAN:
8768 case NL80211_IFTYPE_MESH_POINT:
8769 case NL80211_IFTYPE_P2P_GO:
8770 break;
8771 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008772 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008773 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008774
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008775 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008776 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008777 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008778 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008779
8780 /*
8781 * We should wait on the channel for at least a minimum amount
8782 * of time (10ms) but no longer than the driver supports.
8783 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008784 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8785 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008786 return -EINVAL;
8787
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008788 }
8789
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008790 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008791
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008792 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008793 return -EINVAL;
8794
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008795 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308796
Antonio Quartulliea141b752013-06-11 14:20:03 +02008797 /* get the channel if any has been specified, otherwise pass NULL to
8798 * the driver. The latter will use the current one
8799 */
8800 chandef.chan = NULL;
8801 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8802 err = nl80211_parse_chandef(rdev, info, &chandef);
8803 if (err)
8804 return err;
8805 }
8806
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008807 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008808 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008809
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008810 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8811 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8812
8813 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8814 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8815 int i;
8816
8817 if (len % sizeof(u16))
8818 return -EINVAL;
8819
8820 params.n_csa_offsets = len / sizeof(u16);
8821 params.csa_offsets =
8822 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8823
8824 /* check that all the offsets fit the frame */
8825 for (i = 0; i < params.n_csa_offsets; i++) {
8826 if (params.csa_offsets[i] >= params.len)
8827 return -EINVAL;
8828 }
8829 }
8830
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008831 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008832 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8833 if (!msg)
8834 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008835
Eric W. Biederman15e47302012-09-07 20:12:54 +00008836 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008837 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008838 if (!hdr) {
8839 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008840 goto free_msg;
8841 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008842 }
Johannes Berge247bd902011-11-04 11:18:21 +01008843
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008844 params.chan = chandef.chan;
8845 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008846 if (err)
8847 goto free_msg;
8848
Johannes Berge247bd902011-11-04 11:18:21 +01008849 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008850 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8851 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008852 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008853
Johannes Berge247bd902011-11-04 11:18:21 +01008854 genlmsg_end(msg, hdr);
8855 return genlmsg_reply(msg, info);
8856 }
8857
8858 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008859
8860 nla_put_failure:
8861 err = -ENOBUFS;
8862 free_msg:
8863 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008864 return err;
8865}
8866
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008867static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8868{
8869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008870 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008871 u64 cookie;
8872
8873 if (!info->attrs[NL80211_ATTR_COOKIE])
8874 return -EINVAL;
8875
8876 if (!rdev->ops->mgmt_tx_cancel_wait)
8877 return -EOPNOTSUPP;
8878
Johannes Berg71bbc992012-06-15 15:30:18 +02008879 switch (wdev->iftype) {
8880 case NL80211_IFTYPE_STATION:
8881 case NL80211_IFTYPE_ADHOC:
8882 case NL80211_IFTYPE_P2P_CLIENT:
8883 case NL80211_IFTYPE_AP:
8884 case NL80211_IFTYPE_AP_VLAN:
8885 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008886 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008887 break;
8888 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008889 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008890 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008891
8892 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8893
Hila Gonene35e4d22012-06-27 17:19:42 +03008894 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008895}
8896
Kalle Valoffb9eb32010-02-17 17:58:10 +02008897static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8898{
Johannes Berg4c476992010-10-04 21:36:35 +02008899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008900 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008901 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008902 u8 ps_state;
8903 bool state;
8904 int err;
8905
Johannes Berg4c476992010-10-04 21:36:35 +02008906 if (!info->attrs[NL80211_ATTR_PS_STATE])
8907 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008908
8909 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8910
Johannes Berg4c476992010-10-04 21:36:35 +02008911 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8912 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008913
8914 wdev = dev->ieee80211_ptr;
8915
Johannes Berg4c476992010-10-04 21:36:35 +02008916 if (!rdev->ops->set_power_mgmt)
8917 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008918
8919 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8920
8921 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008922 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008923
Hila Gonene35e4d22012-06-27 17:19:42 +03008924 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008925 if (!err)
8926 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008927 return err;
8928}
8929
8930static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8931{
Johannes Berg4c476992010-10-04 21:36:35 +02008932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008933 enum nl80211_ps_state ps_state;
8934 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008935 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008936 struct sk_buff *msg;
8937 void *hdr;
8938 int err;
8939
Kalle Valoffb9eb32010-02-17 17:58:10 +02008940 wdev = dev->ieee80211_ptr;
8941
Johannes Berg4c476992010-10-04 21:36:35 +02008942 if (!rdev->ops->set_power_mgmt)
8943 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008944
8945 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008946 if (!msg)
8947 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008948
Eric W. Biederman15e47302012-09-07 20:12:54 +00008949 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008950 NL80211_CMD_GET_POWER_SAVE);
8951 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008952 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008953 goto free_msg;
8954 }
8955
8956 if (wdev->ps)
8957 ps_state = NL80211_PS_ENABLED;
8958 else
8959 ps_state = NL80211_PS_DISABLED;
8960
David S. Miller9360ffd2012-03-29 04:41:26 -04008961 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8962 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008963
8964 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008965 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008966
Johannes Berg4c476992010-10-04 21:36:35 +02008967 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008968 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008969 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008970 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008971 return err;
8972}
8973
Johannes Berg94e860f2014-01-20 23:58:15 +01008974static const struct nla_policy
8975nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008976 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8977 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8978 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008979 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8980 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8981 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008982};
8983
Thomas Pedersen84f10702012-07-12 16:17:33 -07008984static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008985 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008986{
8987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008988 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008989 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008990
Johannes Bergd9d8b012012-11-26 12:51:52 +01008991 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008992 return -EINVAL;
8993
Thomas Pedersen84f10702012-07-12 16:17:33 -07008994 if (!rdev->ops->set_cqm_txe_config)
8995 return -EOPNOTSUPP;
8996
8997 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8998 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8999 return -EOPNOTSUPP;
9000
Hila Gonene35e4d22012-06-27 17:19:42 +03009001 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009002}
9003
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009004static int nl80211_set_cqm_rssi(struct genl_info *info,
9005 s32 threshold, u32 hysteresis)
9006{
Johannes Berg4c476992010-10-04 21:36:35 +02009007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009008 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009009 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009010
9011 if (threshold > 0)
9012 return -EINVAL;
9013
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009014 /* disabling - hysteresis should also be zero then */
9015 if (threshold == 0)
9016 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009017
Johannes Berg4c476992010-10-04 21:36:35 +02009018 if (!rdev->ops->set_cqm_rssi_config)
9019 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009020
Johannes Berg074ac8d2010-09-16 14:58:22 +02009021 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009022 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9023 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009024
Hila Gonene35e4d22012-06-27 17:19:42 +03009025 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009026}
9027
9028static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9029{
9030 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9031 struct nlattr *cqm;
9032 int err;
9033
9034 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009035 if (!cqm)
9036 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009037
9038 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9039 nl80211_attr_cqm_policy);
9040 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009041 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009042
9043 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9044 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009045 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9046 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009047
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009048 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9049 }
9050
9051 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9052 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9053 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9054 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9055 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9056 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9057
9058 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9059 }
9060
9061 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009062}
9063
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009064static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9065{
9066 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9067 struct net_device *dev = info->user_ptr[1];
9068 struct ocb_setup setup = {};
9069 int err;
9070
9071 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9072 if (err)
9073 return err;
9074
9075 return cfg80211_join_ocb(rdev, dev, &setup);
9076}
9077
9078static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9079{
9080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9081 struct net_device *dev = info->user_ptr[1];
9082
9083 return cfg80211_leave_ocb(rdev, dev);
9084}
9085
Johannes Berg29cbe682010-12-03 09:20:44 +01009086static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9087{
9088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9089 struct net_device *dev = info->user_ptr[1];
9090 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009091 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009092 int err;
9093
9094 /* start with default */
9095 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009096 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009097
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009098 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009099 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009100 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009101 if (err)
9102 return err;
9103 }
9104
9105 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9106 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9107 return -EINVAL;
9108
Javier Cardonac80d5452010-12-16 17:37:49 -08009109 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9110 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9111
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009112 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9113 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9114 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9115 return -EINVAL;
9116
Marco Porsch9bdbf042013-01-07 16:04:51 +01009117 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9118 setup.beacon_interval =
9119 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9120 if (setup.beacon_interval < 10 ||
9121 setup.beacon_interval > 10000)
9122 return -EINVAL;
9123 }
9124
9125 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9126 setup.dtim_period =
9127 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9128 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9129 return -EINVAL;
9130 }
9131
Javier Cardonac80d5452010-12-16 17:37:49 -08009132 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9133 /* parse additional setup parameters if given */
9134 err = nl80211_parse_mesh_setup(info, &setup);
9135 if (err)
9136 return err;
9137 }
9138
Thomas Pedersend37bb182013-03-04 13:06:13 -08009139 if (setup.user_mpm)
9140 cfg.auto_open_plinks = false;
9141
Johannes Bergcc1d2802012-05-16 23:50:20 +02009142 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009143 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9144 if (err)
9145 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009146 } else {
9147 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009148 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009149 }
9150
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009151 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9152 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9153 int n_rates =
9154 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9155 struct ieee80211_supported_band *sband;
9156
9157 if (!setup.chandef.chan)
9158 return -EINVAL;
9159
9160 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9161
9162 err = ieee80211_get_ratemask(sband, rates, n_rates,
9163 &setup.basic_rates);
9164 if (err)
9165 return err;
9166 }
9167
Javier Cardonac80d5452010-12-16 17:37:49 -08009168 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009169}
9170
9171static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9172{
9173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9174 struct net_device *dev = info->user_ptr[1];
9175
9176 return cfg80211_leave_mesh(rdev, dev);
9177}
9178
Johannes Bergdfb89c52012-06-27 09:23:48 +02009179#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009180static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9181 struct cfg80211_registered_device *rdev)
9182{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009183 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009184 struct nlattr *nl_pats, *nl_pat;
9185 int i, pat_len;
9186
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009187 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009188 return 0;
9189
9190 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9191 if (!nl_pats)
9192 return -ENOBUFS;
9193
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009194 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009195 nl_pat = nla_nest_start(msg, i + 1);
9196 if (!nl_pat)
9197 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009198 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009199 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009200 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009201 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9202 wowlan->patterns[i].pattern) ||
9203 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009204 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009205 return -ENOBUFS;
9206 nla_nest_end(msg, nl_pat);
9207 }
9208 nla_nest_end(msg, nl_pats);
9209
9210 return 0;
9211}
9212
Johannes Berg2a0e0472013-01-23 22:57:40 +01009213static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9214 struct cfg80211_wowlan_tcp *tcp)
9215{
9216 struct nlattr *nl_tcp;
9217
9218 if (!tcp)
9219 return 0;
9220
9221 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9222 if (!nl_tcp)
9223 return -ENOBUFS;
9224
Jiri Benc930345e2015-03-29 16:59:25 +02009225 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9226 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009227 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9228 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9229 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9230 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9231 tcp->payload_len, tcp->payload) ||
9232 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9233 tcp->data_interval) ||
9234 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9235 tcp->wake_len, tcp->wake_data) ||
9236 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9237 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9238 return -ENOBUFS;
9239
9240 if (tcp->payload_seq.len &&
9241 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9242 sizeof(tcp->payload_seq), &tcp->payload_seq))
9243 return -ENOBUFS;
9244
9245 if (tcp->payload_tok.len &&
9246 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9247 sizeof(tcp->payload_tok) + tcp->tokens_size,
9248 &tcp->payload_tok))
9249 return -ENOBUFS;
9250
Johannes Berge248ad32013-05-16 10:24:28 +02009251 nla_nest_end(msg, nl_tcp);
9252
Johannes Berg2a0e0472013-01-23 22:57:40 +01009253 return 0;
9254}
9255
Luciano Coelho75453cc2015-01-09 14:06:37 +02009256static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9257 struct cfg80211_sched_scan_request *req)
9258{
Avraham Stern3b06d272015-10-12 09:51:34 +03009259 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009260 int i;
9261
9262 if (!req)
9263 return 0;
9264
9265 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9266 if (!nd)
9267 return -ENOBUFS;
9268
Avraham Stern3b06d272015-10-12 09:51:34 +03009269 if (req->n_scan_plans == 1 &&
9270 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9271 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009272 return -ENOBUFS;
9273
Luciano Coelho21fea562015-03-17 16:36:01 +02009274 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9275 return -ENOBUFS;
9276
Luciano Coelho75453cc2015-01-09 14:06:37 +02009277 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9278 if (!freqs)
9279 return -ENOBUFS;
9280
9281 for (i = 0; i < req->n_channels; i++)
9282 nla_put_u32(msg, i, req->channels[i]->center_freq);
9283
9284 nla_nest_end(msg, freqs);
9285
9286 if (req->n_match_sets) {
9287 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9288 for (i = 0; i < req->n_match_sets; i++) {
9289 match = nla_nest_start(msg, i);
9290 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9291 req->match_sets[i].ssid.ssid_len,
9292 req->match_sets[i].ssid.ssid);
9293 nla_nest_end(msg, match);
9294 }
9295 nla_nest_end(msg, matches);
9296 }
9297
Avraham Stern3b06d272015-10-12 09:51:34 +03009298 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9299 if (!scan_plans)
9300 return -ENOBUFS;
9301
9302 for (i = 0; i < req->n_scan_plans; i++) {
9303 scan_plan = nla_nest_start(msg, i + 1);
9304 if (!scan_plan ||
9305 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9306 req->scan_plans[i].interval) ||
9307 (req->scan_plans[i].iterations &&
9308 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9309 req->scan_plans[i].iterations)))
9310 return -ENOBUFS;
9311 nla_nest_end(msg, scan_plan);
9312 }
9313 nla_nest_end(msg, scan_plans);
9314
Luciano Coelho75453cc2015-01-09 14:06:37 +02009315 nla_nest_end(msg, nd);
9316
9317 return 0;
9318}
9319
Johannes Bergff1b6e62011-05-04 15:37:28 +02009320static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9321{
9322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9323 struct sk_buff *msg;
9324 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009325 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009326
Johannes Berg964dc9e2013-06-03 17:25:34 +02009327 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009328 return -EOPNOTSUPP;
9329
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009330 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009331 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009332 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9333 rdev->wiphy.wowlan_config->tcp->payload_len +
9334 rdev->wiphy.wowlan_config->tcp->wake_len +
9335 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009336 }
9337
9338 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009339 if (!msg)
9340 return -ENOMEM;
9341
Eric W. Biederman15e47302012-09-07 20:12:54 +00009342 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009343 NL80211_CMD_GET_WOWLAN);
9344 if (!hdr)
9345 goto nla_put_failure;
9346
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009347 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009348 struct nlattr *nl_wowlan;
9349
9350 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9351 if (!nl_wowlan)
9352 goto nla_put_failure;
9353
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009354 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009355 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009356 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009357 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009358 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009359 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009360 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009361 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009362 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009363 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009364 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009365 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009366 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009367 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9368 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009369
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009370 if (nl80211_send_wowlan_patterns(msg, rdev))
9371 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009372
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009373 if (nl80211_send_wowlan_tcp(msg,
9374 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009375 goto nla_put_failure;
9376
Luciano Coelho75453cc2015-01-09 14:06:37 +02009377 if (nl80211_send_wowlan_nd(
9378 msg,
9379 rdev->wiphy.wowlan_config->nd_config))
9380 goto nla_put_failure;
9381
Johannes Bergff1b6e62011-05-04 15:37:28 +02009382 nla_nest_end(msg, nl_wowlan);
9383 }
9384
9385 genlmsg_end(msg, hdr);
9386 return genlmsg_reply(msg, info);
9387
9388nla_put_failure:
9389 nlmsg_free(msg);
9390 return -ENOBUFS;
9391}
9392
Johannes Berg2a0e0472013-01-23 22:57:40 +01009393static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9394 struct nlattr *attr,
9395 struct cfg80211_wowlan *trig)
9396{
9397 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9398 struct cfg80211_wowlan_tcp *cfg;
9399 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9400 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9401 u32 size;
9402 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9403 int err, port;
9404
Johannes Berg964dc9e2013-06-03 17:25:34 +02009405 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009406 return -EINVAL;
9407
9408 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9409 nla_data(attr), nla_len(attr),
9410 nl80211_wowlan_tcp_policy);
9411 if (err)
9412 return err;
9413
9414 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9415 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9416 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9417 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9418 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9419 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9420 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9421 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9422 return -EINVAL;
9423
9424 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009425 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009426 return -EINVAL;
9427
9428 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009429 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009430 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009431 return -EINVAL;
9432
9433 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009434 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009435 return -EINVAL;
9436
9437 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9438 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9439 return -EINVAL;
9440
9441 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9442 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9443
9444 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9445 tokens_size = tokln - sizeof(*tok);
9446
9447 if (!tok->len || tokens_size % tok->len)
9448 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009449 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009450 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009451 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009452 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009453 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009454 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009455 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009456 return -EINVAL;
9457 if (tok->offset + tok->len > data_size)
9458 return -EINVAL;
9459 }
9460
9461 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9462 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009463 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009464 return -EINVAL;
9465 if (seq->len == 0 || seq->len > 4)
9466 return -EINVAL;
9467 if (seq->len + seq->offset > data_size)
9468 return -EINVAL;
9469 }
9470
9471 size = sizeof(*cfg);
9472 size += data_size;
9473 size += wake_size + wake_mask_size;
9474 size += tokens_size;
9475
9476 cfg = kzalloc(size, GFP_KERNEL);
9477 if (!cfg)
9478 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009479 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9480 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009481 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9482 ETH_ALEN);
9483 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9484 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9485 else
9486 port = 0;
9487#ifdef CONFIG_INET
9488 /* allocate a socket and port for it and use it */
9489 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9490 IPPROTO_TCP, &cfg->sock, 1);
9491 if (err) {
9492 kfree(cfg);
9493 return err;
9494 }
9495 if (inet_csk_get_port(cfg->sock->sk, port)) {
9496 sock_release(cfg->sock);
9497 kfree(cfg);
9498 return -EADDRINUSE;
9499 }
9500 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9501#else
9502 if (!port) {
9503 kfree(cfg);
9504 return -EINVAL;
9505 }
9506 cfg->src_port = port;
9507#endif
9508
9509 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9510 cfg->payload_len = data_size;
9511 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9512 memcpy((void *)cfg->payload,
9513 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9514 data_size);
9515 if (seq)
9516 cfg->payload_seq = *seq;
9517 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9518 cfg->wake_len = wake_size;
9519 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9520 memcpy((void *)cfg->wake_data,
9521 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9522 wake_size);
9523 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9524 data_size + wake_size;
9525 memcpy((void *)cfg->wake_mask,
9526 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9527 wake_mask_size);
9528 if (tok) {
9529 cfg->tokens_size = tokens_size;
9530 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9531 }
9532
9533 trig->tcp = cfg;
9534
9535 return 0;
9536}
9537
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009538static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9539 const struct wiphy_wowlan_support *wowlan,
9540 struct nlattr *attr,
9541 struct cfg80211_wowlan *trig)
9542{
9543 struct nlattr **tb;
9544 int err;
9545
9546 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9547 if (!tb)
9548 return -ENOMEM;
9549
9550 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9551 err = -EOPNOTSUPP;
9552 goto out;
9553 }
9554
9555 err = nla_parse(tb, NL80211_ATTR_MAX,
9556 nla_data(attr), nla_len(attr),
9557 nl80211_policy);
9558 if (err)
9559 goto out;
9560
Johannes Bergad2b26a2014-06-12 21:39:05 +02009561 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009562 err = PTR_ERR_OR_ZERO(trig->nd_config);
9563 if (err)
9564 trig->nd_config = NULL;
9565
9566out:
9567 kfree(tb);
9568 return err;
9569}
9570
Johannes Bergff1b6e62011-05-04 15:37:28 +02009571static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9572{
9573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9574 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009575 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009576 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009577 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009578 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009579 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009580 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009581
Johannes Berg964dc9e2013-06-03 17:25:34 +02009582 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009583 return -EOPNOTSUPP;
9584
Johannes Bergae33bd82012-07-12 16:25:02 +02009585 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9586 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009587 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009588 goto set_wakeup;
9589 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009590
9591 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9592 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9593 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9594 nl80211_wowlan_policy);
9595 if (err)
9596 return err;
9597
9598 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9599 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9600 return -EINVAL;
9601 new_triggers.any = true;
9602 }
9603
9604 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9605 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9606 return -EINVAL;
9607 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009608 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009609 }
9610
9611 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9612 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9613 return -EINVAL;
9614 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009615 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009616 }
9617
Johannes Berg77dbbb12011-07-13 10:48:55 +02009618 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9619 return -EINVAL;
9620
9621 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9622 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9623 return -EINVAL;
9624 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009625 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009626 }
9627
9628 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9629 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9630 return -EINVAL;
9631 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009632 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009633 }
9634
9635 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9636 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9637 return -EINVAL;
9638 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009639 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009640 }
9641
9642 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9643 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9644 return -EINVAL;
9645 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009646 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009647 }
9648
Johannes Bergff1b6e62011-05-04 15:37:28 +02009649 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9650 struct nlattr *pat;
9651 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009652 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009653 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009654
Johannes Berg98fc4382015-03-01 09:10:13 +02009655 regular = true;
9656
Johannes Bergff1b6e62011-05-04 15:37:28 +02009657 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9658 rem)
9659 n_patterns++;
9660 if (n_patterns > wowlan->n_patterns)
9661 return -EINVAL;
9662
9663 new_triggers.patterns = kcalloc(n_patterns,
9664 sizeof(new_triggers.patterns[0]),
9665 GFP_KERNEL);
9666 if (!new_triggers.patterns)
9667 return -ENOMEM;
9668
9669 new_triggers.n_patterns = n_patterns;
9670 i = 0;
9671
9672 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9673 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009674 u8 *mask_pat;
9675
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009676 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9677 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009678 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009679 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9680 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009681 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009682 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009683 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009684 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009685 goto error;
9686 if (pat_len > wowlan->pattern_max_len ||
9687 pat_len < wowlan->pattern_min_len)
9688 goto error;
9689
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009690 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009691 pkt_offset = 0;
9692 else
9693 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009694 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009695 if (pkt_offset > wowlan->max_pkt_offset)
9696 goto error;
9697 new_triggers.patterns[i].pkt_offset = pkt_offset;
9698
Johannes Berg922bd802014-05-19 17:59:50 +02009699 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9700 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009701 err = -ENOMEM;
9702 goto error;
9703 }
Johannes Berg922bd802014-05-19 17:59:50 +02009704 new_triggers.patterns[i].mask = mask_pat;
9705 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009706 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009707 mask_pat += mask_len;
9708 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009709 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009710 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009711 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009712 pat_len);
9713 i++;
9714 }
9715 }
9716
Johannes Berg2a0e0472013-01-23 22:57:40 +01009717 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009718 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009719 err = nl80211_parse_wowlan_tcp(
9720 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9721 &new_triggers);
9722 if (err)
9723 goto error;
9724 }
9725
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009726 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009727 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009728 err = nl80211_parse_wowlan_nd(
9729 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9730 &new_triggers);
9731 if (err)
9732 goto error;
9733 }
9734
Johannes Berg98fc4382015-03-01 09:10:13 +02009735 /* The 'any' trigger means the device continues operating more or less
9736 * as in its normal operation mode and wakes up the host on most of the
9737 * normal interrupts (like packet RX, ...)
9738 * It therefore makes little sense to combine with the more constrained
9739 * wakeup trigger modes.
9740 */
9741 if (new_triggers.any && regular) {
9742 err = -EINVAL;
9743 goto error;
9744 }
9745
Johannes Bergae33bd82012-07-12 16:25:02 +02009746 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9747 if (!ntrig) {
9748 err = -ENOMEM;
9749 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009750 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009751 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009752 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009753
Johannes Bergae33bd82012-07-12 16:25:02 +02009754 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009755 if (rdev->ops->set_wakeup &&
9756 prev_enabled != !!rdev->wiphy.wowlan_config)
9757 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009758
Johannes Bergff1b6e62011-05-04 15:37:28 +02009759 return 0;
9760 error:
9761 for (i = 0; i < new_triggers.n_patterns; i++)
9762 kfree(new_triggers.patterns[i].mask);
9763 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009764 if (new_triggers.tcp && new_triggers.tcp->sock)
9765 sock_release(new_triggers.tcp->sock);
9766 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009767 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009768 return err;
9769}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009770#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009771
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009772static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9773 struct cfg80211_registered_device *rdev)
9774{
9775 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9776 int i, j, pat_len;
9777 struct cfg80211_coalesce_rules *rule;
9778
9779 if (!rdev->coalesce->n_rules)
9780 return 0;
9781
9782 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9783 if (!nl_rules)
9784 return -ENOBUFS;
9785
9786 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9787 nl_rule = nla_nest_start(msg, i + 1);
9788 if (!nl_rule)
9789 return -ENOBUFS;
9790
9791 rule = &rdev->coalesce->rules[i];
9792 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9793 rule->delay))
9794 return -ENOBUFS;
9795
9796 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9797 rule->condition))
9798 return -ENOBUFS;
9799
9800 nl_pats = nla_nest_start(msg,
9801 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9802 if (!nl_pats)
9803 return -ENOBUFS;
9804
9805 for (j = 0; j < rule->n_patterns; j++) {
9806 nl_pat = nla_nest_start(msg, j + 1);
9807 if (!nl_pat)
9808 return -ENOBUFS;
9809 pat_len = rule->patterns[j].pattern_len;
9810 if (nla_put(msg, NL80211_PKTPAT_MASK,
9811 DIV_ROUND_UP(pat_len, 8),
9812 rule->patterns[j].mask) ||
9813 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9814 rule->patterns[j].pattern) ||
9815 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9816 rule->patterns[j].pkt_offset))
9817 return -ENOBUFS;
9818 nla_nest_end(msg, nl_pat);
9819 }
9820 nla_nest_end(msg, nl_pats);
9821 nla_nest_end(msg, nl_rule);
9822 }
9823 nla_nest_end(msg, nl_rules);
9824
9825 return 0;
9826}
9827
9828static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9829{
9830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9831 struct sk_buff *msg;
9832 void *hdr;
9833
9834 if (!rdev->wiphy.coalesce)
9835 return -EOPNOTSUPP;
9836
9837 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9838 if (!msg)
9839 return -ENOMEM;
9840
9841 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9842 NL80211_CMD_GET_COALESCE);
9843 if (!hdr)
9844 goto nla_put_failure;
9845
9846 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9847 goto nla_put_failure;
9848
9849 genlmsg_end(msg, hdr);
9850 return genlmsg_reply(msg, info);
9851
9852nla_put_failure:
9853 nlmsg_free(msg);
9854 return -ENOBUFS;
9855}
9856
9857void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9858{
9859 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9860 int i, j;
9861 struct cfg80211_coalesce_rules *rule;
9862
9863 if (!coalesce)
9864 return;
9865
9866 for (i = 0; i < coalesce->n_rules; i++) {
9867 rule = &coalesce->rules[i];
9868 for (j = 0; j < rule->n_patterns; j++)
9869 kfree(rule->patterns[j].mask);
9870 kfree(rule->patterns);
9871 }
9872 kfree(coalesce->rules);
9873 kfree(coalesce);
9874 rdev->coalesce = NULL;
9875}
9876
9877static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9878 struct nlattr *rule,
9879 struct cfg80211_coalesce_rules *new_rule)
9880{
9881 int err, i;
9882 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9883 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9884 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9885 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9886
9887 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9888 nla_len(rule), nl80211_coalesce_policy);
9889 if (err)
9890 return err;
9891
9892 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9893 new_rule->delay =
9894 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9895 if (new_rule->delay > coalesce->max_delay)
9896 return -EINVAL;
9897
9898 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9899 new_rule->condition =
9900 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9901 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9902 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9903 return -EINVAL;
9904
9905 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9906 return -EINVAL;
9907
9908 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9909 rem)
9910 n_patterns++;
9911 if (n_patterns > coalesce->n_patterns)
9912 return -EINVAL;
9913
9914 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9915 GFP_KERNEL);
9916 if (!new_rule->patterns)
9917 return -ENOMEM;
9918
9919 new_rule->n_patterns = n_patterns;
9920 i = 0;
9921
9922 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9923 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009924 u8 *mask_pat;
9925
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009926 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9927 nla_len(pat), NULL);
9928 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9929 !pat_tb[NL80211_PKTPAT_PATTERN])
9930 return -EINVAL;
9931 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9932 mask_len = DIV_ROUND_UP(pat_len, 8);
9933 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9934 return -EINVAL;
9935 if (pat_len > coalesce->pattern_max_len ||
9936 pat_len < coalesce->pattern_min_len)
9937 return -EINVAL;
9938
9939 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9940 pkt_offset = 0;
9941 else
9942 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9943 if (pkt_offset > coalesce->max_pkt_offset)
9944 return -EINVAL;
9945 new_rule->patterns[i].pkt_offset = pkt_offset;
9946
Johannes Berg922bd802014-05-19 17:59:50 +02009947 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9948 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009949 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009950
9951 new_rule->patterns[i].mask = mask_pat;
9952 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9953 mask_len);
9954
9955 mask_pat += mask_len;
9956 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009957 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009958 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9959 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009960 i++;
9961 }
9962
9963 return 0;
9964}
9965
9966static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9967{
9968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9969 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9970 struct cfg80211_coalesce new_coalesce = {};
9971 struct cfg80211_coalesce *n_coalesce;
9972 int err, rem_rule, n_rules = 0, i, j;
9973 struct nlattr *rule;
9974 struct cfg80211_coalesce_rules *tmp_rule;
9975
9976 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9977 return -EOPNOTSUPP;
9978
9979 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9980 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +03009981 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009982 return 0;
9983 }
9984
9985 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9986 rem_rule)
9987 n_rules++;
9988 if (n_rules > coalesce->n_rules)
9989 return -EINVAL;
9990
9991 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9992 GFP_KERNEL);
9993 if (!new_coalesce.rules)
9994 return -ENOMEM;
9995
9996 new_coalesce.n_rules = n_rules;
9997 i = 0;
9998
9999 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10000 rem_rule) {
10001 err = nl80211_parse_coalesce_rule(rdev, rule,
10002 &new_coalesce.rules[i]);
10003 if (err)
10004 goto error;
10005
10006 i++;
10007 }
10008
Ilan Peera1056b12015-10-22 22:27:46 +030010009 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010010 if (err)
10011 goto error;
10012
10013 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10014 if (!n_coalesce) {
10015 err = -ENOMEM;
10016 goto error;
10017 }
10018 cfg80211_rdev_free_coalesce(rdev);
10019 rdev->coalesce = n_coalesce;
10020
10021 return 0;
10022error:
10023 for (i = 0; i < new_coalesce.n_rules; i++) {
10024 tmp_rule = &new_coalesce.rules[i];
10025 for (j = 0; j < tmp_rule->n_patterns; j++)
10026 kfree(tmp_rule->patterns[j].mask);
10027 kfree(tmp_rule->patterns);
10028 }
10029 kfree(new_coalesce.rules);
10030
10031 return err;
10032}
10033
Johannes Berge5497d72011-07-05 16:35:40 +020010034static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10035{
10036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10037 struct net_device *dev = info->user_ptr[1];
10038 struct wireless_dev *wdev = dev->ieee80211_ptr;
10039 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10040 struct cfg80211_gtk_rekey_data rekey_data;
10041 int err;
10042
10043 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10044 return -EINVAL;
10045
10046 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10047 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10048 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10049 nl80211_rekey_policy);
10050 if (err)
10051 return err;
10052
10053 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10054 return -ERANGE;
10055 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10056 return -ERANGE;
10057 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10058 return -ERANGE;
10059
Johannes Berg78f686c2014-09-10 22:28:06 +030010060 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10061 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10062 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010063
10064 wdev_lock(wdev);
10065 if (!wdev->current_bss) {
10066 err = -ENOTCONN;
10067 goto out;
10068 }
10069
10070 if (!rdev->ops->set_rekey_data) {
10071 err = -EOPNOTSUPP;
10072 goto out;
10073 }
10074
Hila Gonene35e4d22012-06-27 17:19:42 +030010075 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010076 out:
10077 wdev_unlock(wdev);
10078 return err;
10079}
10080
Johannes Berg28946da2011-11-04 11:18:12 +010010081static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10082 struct genl_info *info)
10083{
10084 struct net_device *dev = info->user_ptr[1];
10085 struct wireless_dev *wdev = dev->ieee80211_ptr;
10086
10087 if (wdev->iftype != NL80211_IFTYPE_AP &&
10088 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10089 return -EINVAL;
10090
Eric W. Biederman15e47302012-09-07 20:12:54 +000010091 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010092 return -EBUSY;
10093
Eric W. Biederman15e47302012-09-07 20:12:54 +000010094 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010095 return 0;
10096}
10097
Johannes Berg7f6cf312011-11-04 11:18:15 +010010098static int nl80211_probe_client(struct sk_buff *skb,
10099 struct genl_info *info)
10100{
10101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10102 struct net_device *dev = info->user_ptr[1];
10103 struct wireless_dev *wdev = dev->ieee80211_ptr;
10104 struct sk_buff *msg;
10105 void *hdr;
10106 const u8 *addr;
10107 u64 cookie;
10108 int err;
10109
10110 if (wdev->iftype != NL80211_IFTYPE_AP &&
10111 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10112 return -EOPNOTSUPP;
10113
10114 if (!info->attrs[NL80211_ATTR_MAC])
10115 return -EINVAL;
10116
10117 if (!rdev->ops->probe_client)
10118 return -EOPNOTSUPP;
10119
10120 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10121 if (!msg)
10122 return -ENOMEM;
10123
Eric W. Biederman15e47302012-09-07 20:12:54 +000010124 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010125 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010126 if (!hdr) {
10127 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010128 goto free_msg;
10129 }
10130
10131 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10132
Hila Gonene35e4d22012-06-27 17:19:42 +030010133 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010134 if (err)
10135 goto free_msg;
10136
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010137 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10138 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010139 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010140
10141 genlmsg_end(msg, hdr);
10142
10143 return genlmsg_reply(msg, info);
10144
10145 nla_put_failure:
10146 err = -ENOBUFS;
10147 free_msg:
10148 nlmsg_free(msg);
10149 return err;
10150}
10151
Johannes Berg5e7602302011-11-04 11:18:17 +010010152static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10153{
10154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010155 struct cfg80211_beacon_registration *reg, *nreg;
10156 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010157
10158 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10159 return -EOPNOTSUPP;
10160
Ben Greear37c73b52012-10-26 14:49:25 -070010161 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10162 if (!nreg)
10163 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010164
Ben Greear37c73b52012-10-26 14:49:25 -070010165 /* First, check if already registered. */
10166 spin_lock_bh(&rdev->beacon_registrations_lock);
10167 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10168 if (reg->nlportid == info->snd_portid) {
10169 rv = -EALREADY;
10170 goto out_err;
10171 }
10172 }
10173 /* Add it to the list */
10174 nreg->nlportid = info->snd_portid;
10175 list_add(&nreg->list, &rdev->beacon_registrations);
10176
10177 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010178
10179 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010180out_err:
10181 spin_unlock_bh(&rdev->beacon_registrations_lock);
10182 kfree(nreg);
10183 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010184}
10185
Johannes Berg98104fde2012-06-16 00:19:54 +020010186static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10187{
10188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10189 struct wireless_dev *wdev = info->user_ptr[1];
10190 int err;
10191
10192 if (!rdev->ops->start_p2p_device)
10193 return -EOPNOTSUPP;
10194
10195 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10196 return -EOPNOTSUPP;
10197
10198 if (wdev->p2p_started)
10199 return 0;
10200
Luciano Coelhob6a55012014-02-27 11:07:21 +020010201 if (rfkill_blocked(rdev->rfkill))
10202 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010203
Johannes Bergeeb126e2012-10-23 15:16:50 +020010204 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010205 if (err)
10206 return err;
10207
10208 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010209 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010210
10211 return 0;
10212}
10213
10214static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10215{
10216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10217 struct wireless_dev *wdev = info->user_ptr[1];
10218
10219 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10220 return -EOPNOTSUPP;
10221
10222 if (!rdev->ops->stop_p2p_device)
10223 return -EOPNOTSUPP;
10224
Johannes Bergf9f47522013-03-19 15:04:07 +010010225 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010226
10227 return 0;
10228}
10229
Johannes Berg3713b4e2013-02-14 16:19:38 +010010230static int nl80211_get_protocol_features(struct sk_buff *skb,
10231 struct genl_info *info)
10232{
10233 void *hdr;
10234 struct sk_buff *msg;
10235
10236 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10237 if (!msg)
10238 return -ENOMEM;
10239
10240 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10241 NL80211_CMD_GET_PROTOCOL_FEATURES);
10242 if (!hdr)
10243 goto nla_put_failure;
10244
10245 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10246 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10247 goto nla_put_failure;
10248
10249 genlmsg_end(msg, hdr);
10250 return genlmsg_reply(msg, info);
10251
10252 nla_put_failure:
10253 kfree_skb(msg);
10254 return -ENOBUFS;
10255}
10256
Jouni Malinen355199e2013-02-27 17:14:27 +020010257static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10258{
10259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10260 struct cfg80211_update_ft_ies_params ft_params;
10261 struct net_device *dev = info->user_ptr[1];
10262
10263 if (!rdev->ops->update_ft_ies)
10264 return -EOPNOTSUPP;
10265
10266 if (!info->attrs[NL80211_ATTR_MDID] ||
10267 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10268 return -EINVAL;
10269
10270 memset(&ft_params, 0, sizeof(ft_params));
10271 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10272 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10273 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10274
10275 return rdev_update_ft_ies(rdev, dev, &ft_params);
10276}
10277
Arend van Spriel5de17982013-04-18 15:49:00 +020010278static int nl80211_crit_protocol_start(struct sk_buff *skb,
10279 struct genl_info *info)
10280{
10281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10282 struct wireless_dev *wdev = info->user_ptr[1];
10283 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10284 u16 duration;
10285 int ret;
10286
10287 if (!rdev->ops->crit_proto_start)
10288 return -EOPNOTSUPP;
10289
10290 if (WARN_ON(!rdev->ops->crit_proto_stop))
10291 return -EINVAL;
10292
10293 if (rdev->crit_proto_nlportid)
10294 return -EBUSY;
10295
10296 /* determine protocol if provided */
10297 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10298 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10299
10300 if (proto >= NUM_NL80211_CRIT_PROTO)
10301 return -EINVAL;
10302
10303 /* timeout must be provided */
10304 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10305 return -EINVAL;
10306
10307 duration =
10308 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10309
10310 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10311 return -ERANGE;
10312
10313 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10314 if (!ret)
10315 rdev->crit_proto_nlportid = info->snd_portid;
10316
10317 return ret;
10318}
10319
10320static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10321 struct genl_info *info)
10322{
10323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10324 struct wireless_dev *wdev = info->user_ptr[1];
10325
10326 if (!rdev->ops->crit_proto_stop)
10327 return -EOPNOTSUPP;
10328
10329 if (rdev->crit_proto_nlportid) {
10330 rdev->crit_proto_nlportid = 0;
10331 rdev_crit_proto_stop(rdev, wdev);
10332 }
10333 return 0;
10334}
10335
Johannes Bergad7e7182013-11-13 13:37:47 +010010336static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10337{
10338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10339 struct wireless_dev *wdev =
10340 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10341 int i, err;
10342 u32 vid, subcmd;
10343
10344 if (!rdev->wiphy.vendor_commands)
10345 return -EOPNOTSUPP;
10346
10347 if (IS_ERR(wdev)) {
10348 err = PTR_ERR(wdev);
10349 if (err != -EINVAL)
10350 return err;
10351 wdev = NULL;
10352 } else if (wdev->wiphy != &rdev->wiphy) {
10353 return -EINVAL;
10354 }
10355
10356 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10357 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10358 return -EINVAL;
10359
10360 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10361 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10362 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10363 const struct wiphy_vendor_command *vcmd;
10364 void *data = NULL;
10365 int len = 0;
10366
10367 vcmd = &rdev->wiphy.vendor_commands[i];
10368
10369 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10370 continue;
10371
10372 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10373 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10374 if (!wdev)
10375 return -EINVAL;
10376 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10377 !wdev->netdev)
10378 return -EINVAL;
10379
10380 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10381 if (wdev->netdev &&
10382 !netif_running(wdev->netdev))
10383 return -ENETDOWN;
10384 if (!wdev->netdev && !wdev->p2p_started)
10385 return -ENETDOWN;
10386 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010387
10388 if (!vcmd->doit)
10389 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010390 } else {
10391 wdev = NULL;
10392 }
10393
10394 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10395 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10396 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10397 }
10398
10399 rdev->cur_cmd_info = info;
10400 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10401 data, len);
10402 rdev->cur_cmd_info = NULL;
10403 return err;
10404 }
10405
10406 return -EOPNOTSUPP;
10407}
10408
Johannes Berg7bdbe402015-08-15 22:39:49 +030010409static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10410 struct netlink_callback *cb,
10411 struct cfg80211_registered_device **rdev,
10412 struct wireless_dev **wdev)
10413{
10414 u32 vid, subcmd;
10415 unsigned int i;
10416 int vcmd_idx = -1;
10417 int err;
10418 void *data = NULL;
10419 unsigned int data_len = 0;
10420
10421 rtnl_lock();
10422
10423 if (cb->args[0]) {
10424 /* subtract the 1 again here */
10425 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10426 struct wireless_dev *tmp;
10427
10428 if (!wiphy) {
10429 err = -ENODEV;
10430 goto out_unlock;
10431 }
10432 *rdev = wiphy_to_rdev(wiphy);
10433 *wdev = NULL;
10434
10435 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010436 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010437 if (tmp->identifier == cb->args[1] - 1) {
10438 *wdev = tmp;
10439 break;
10440 }
10441 }
10442 }
10443
10444 /* keep rtnl locked in successful case */
10445 return 0;
10446 }
10447
10448 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10449 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10450 nl80211_policy);
10451 if (err)
10452 goto out_unlock;
10453
10454 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10455 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10456 err = -EINVAL;
10457 goto out_unlock;
10458 }
10459
10460 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10461 nl80211_fam.attrbuf);
10462 if (IS_ERR(*wdev))
10463 *wdev = NULL;
10464
10465 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10466 nl80211_fam.attrbuf);
10467 if (IS_ERR(*rdev)) {
10468 err = PTR_ERR(*rdev);
10469 goto out_unlock;
10470 }
10471
10472 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10473 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10474
10475 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10476 const struct wiphy_vendor_command *vcmd;
10477
10478 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10479
10480 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10481 continue;
10482
10483 if (!vcmd->dumpit) {
10484 err = -EOPNOTSUPP;
10485 goto out_unlock;
10486 }
10487
10488 vcmd_idx = i;
10489 break;
10490 }
10491
10492 if (vcmd_idx < 0) {
10493 err = -EOPNOTSUPP;
10494 goto out_unlock;
10495 }
10496
10497 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10498 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10499 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10500 }
10501
10502 /* 0 is the first index - add 1 to parse only once */
10503 cb->args[0] = (*rdev)->wiphy_idx + 1;
10504 /* add 1 to know if it was NULL */
10505 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10506 cb->args[2] = vcmd_idx;
10507 cb->args[3] = (unsigned long)data;
10508 cb->args[4] = data_len;
10509
10510 /* keep rtnl locked in successful case */
10511 return 0;
10512 out_unlock:
10513 rtnl_unlock();
10514 return err;
10515}
10516
10517static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10518 struct netlink_callback *cb)
10519{
10520 struct cfg80211_registered_device *rdev;
10521 struct wireless_dev *wdev;
10522 unsigned int vcmd_idx;
10523 const struct wiphy_vendor_command *vcmd;
10524 void *data;
10525 int data_len;
10526 int err;
10527 struct nlattr *vendor_data;
10528
10529 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10530 if (err)
10531 return err;
10532
10533 vcmd_idx = cb->args[2];
10534 data = (void *)cb->args[3];
10535 data_len = cb->args[4];
10536 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10537
10538 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10539 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10540 if (!wdev)
10541 return -EINVAL;
10542 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10543 !wdev->netdev)
10544 return -EINVAL;
10545
10546 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10547 if (wdev->netdev &&
10548 !netif_running(wdev->netdev))
10549 return -ENETDOWN;
10550 if (!wdev->netdev && !wdev->p2p_started)
10551 return -ENETDOWN;
10552 }
10553 }
10554
10555 while (1) {
10556 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10557 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10558 NL80211_CMD_VENDOR);
10559 if (!hdr)
10560 break;
10561
10562 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010563 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10564 wdev_id(wdev),
10565 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010566 genlmsg_cancel(skb, hdr);
10567 break;
10568 }
10569
10570 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10571 if (!vendor_data) {
10572 genlmsg_cancel(skb, hdr);
10573 break;
10574 }
10575
10576 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10577 (unsigned long *)&cb->args[5]);
10578 nla_nest_end(skb, vendor_data);
10579
10580 if (err == -ENOBUFS || err == -ENOENT) {
10581 genlmsg_cancel(skb, hdr);
10582 break;
10583 } else if (err) {
10584 genlmsg_cancel(skb, hdr);
10585 goto out;
10586 }
10587
10588 genlmsg_end(skb, hdr);
10589 }
10590
10591 err = skb->len;
10592 out:
10593 rtnl_unlock();
10594 return err;
10595}
10596
Johannes Bergad7e7182013-11-13 13:37:47 +010010597struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10598 enum nl80211_commands cmd,
10599 enum nl80211_attrs attr,
10600 int approxlen)
10601{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010602 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010603
10604 if (WARN_ON(!rdev->cur_cmd_info))
10605 return NULL;
10606
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010607 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010608 rdev->cur_cmd_info->snd_portid,
10609 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010610 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010611}
10612EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10613
10614int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10615{
10616 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10617 void *hdr = ((void **)skb->cb)[1];
10618 struct nlattr *data = ((void **)skb->cb)[2];
10619
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010620 /* clear CB data for netlink core to own from now on */
10621 memset(skb->cb, 0, sizeof(skb->cb));
10622
Johannes Bergad7e7182013-11-13 13:37:47 +010010623 if (WARN_ON(!rdev->cur_cmd_info)) {
10624 kfree_skb(skb);
10625 return -EINVAL;
10626 }
10627
10628 nla_nest_end(skb, data);
10629 genlmsg_end(skb, hdr);
10630 return genlmsg_reply(skb, rdev->cur_cmd_info);
10631}
10632EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10633
10634
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010635static int nl80211_set_qos_map(struct sk_buff *skb,
10636 struct genl_info *info)
10637{
10638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10639 struct cfg80211_qos_map *qos_map = NULL;
10640 struct net_device *dev = info->user_ptr[1];
10641 u8 *pos, len, num_des, des_len, des;
10642 int ret;
10643
10644 if (!rdev->ops->set_qos_map)
10645 return -EOPNOTSUPP;
10646
10647 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10648 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10649 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10650
10651 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10652 len > IEEE80211_QOS_MAP_LEN_MAX)
10653 return -EINVAL;
10654
10655 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10656 if (!qos_map)
10657 return -ENOMEM;
10658
10659 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10660 if (num_des) {
10661 des_len = num_des *
10662 sizeof(struct cfg80211_dscp_exception);
10663 memcpy(qos_map->dscp_exception, pos, des_len);
10664 qos_map->num_des = num_des;
10665 for (des = 0; des < num_des; des++) {
10666 if (qos_map->dscp_exception[des].up > 7) {
10667 kfree(qos_map);
10668 return -EINVAL;
10669 }
10670 }
10671 pos += des_len;
10672 }
10673 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10674 }
10675
10676 wdev_lock(dev->ieee80211_ptr);
10677 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10678 if (!ret)
10679 ret = rdev_set_qos_map(rdev, dev, qos_map);
10680 wdev_unlock(dev->ieee80211_ptr);
10681
10682 kfree(qos_map);
10683 return ret;
10684}
10685
Johannes Berg960d01a2014-09-09 22:55:35 +030010686static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10687{
10688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10689 struct net_device *dev = info->user_ptr[1];
10690 struct wireless_dev *wdev = dev->ieee80211_ptr;
10691 const u8 *peer;
10692 u8 tsid, up;
10693 u16 admitted_time = 0;
10694 int err;
10695
Johannes Berg723e73a2014-10-22 09:25:06 +020010696 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010697 return -EOPNOTSUPP;
10698
10699 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10700 !info->attrs[NL80211_ATTR_USER_PRIO])
10701 return -EINVAL;
10702
10703 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10704 if (tsid >= IEEE80211_NUM_TIDS)
10705 return -EINVAL;
10706
10707 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10708 if (up >= IEEE80211_NUM_UPS)
10709 return -EINVAL;
10710
10711 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010712 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010713 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010714 * need more attributes for that (e.g. BA session requirement);
10715 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010716 */
10717 return -EINVAL;
10718 }
10719
10720 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10721
10722 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10723 admitted_time =
10724 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10725 if (!admitted_time)
10726 return -EINVAL;
10727 }
10728
10729 wdev_lock(wdev);
10730 switch (wdev->iftype) {
10731 case NL80211_IFTYPE_STATION:
10732 case NL80211_IFTYPE_P2P_CLIENT:
10733 if (wdev->current_bss)
10734 break;
10735 err = -ENOTCONN;
10736 goto out;
10737 default:
10738 err = -EOPNOTSUPP;
10739 goto out;
10740 }
10741
10742 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10743
10744 out:
10745 wdev_unlock(wdev);
10746 return err;
10747}
10748
10749static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10750{
10751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10752 struct net_device *dev = info->user_ptr[1];
10753 struct wireless_dev *wdev = dev->ieee80211_ptr;
10754 const u8 *peer;
10755 u8 tsid;
10756 int err;
10757
10758 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10759 return -EINVAL;
10760
10761 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10762 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10763
10764 wdev_lock(wdev);
10765 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10766 wdev_unlock(wdev);
10767
10768 return err;
10769}
10770
Arik Nemtsov1057d352014-11-19 12:54:26 +020010771static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10772 struct genl_info *info)
10773{
10774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10775 struct net_device *dev = info->user_ptr[1];
10776 struct wireless_dev *wdev = dev->ieee80211_ptr;
10777 struct cfg80211_chan_def chandef = {};
10778 const u8 *addr;
10779 u8 oper_class;
10780 int err;
10781
10782 if (!rdev->ops->tdls_channel_switch ||
10783 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10784 return -EOPNOTSUPP;
10785
10786 switch (dev->ieee80211_ptr->iftype) {
10787 case NL80211_IFTYPE_STATION:
10788 case NL80211_IFTYPE_P2P_CLIENT:
10789 break;
10790 default:
10791 return -EOPNOTSUPP;
10792 }
10793
10794 if (!info->attrs[NL80211_ATTR_MAC] ||
10795 !info->attrs[NL80211_ATTR_OPER_CLASS])
10796 return -EINVAL;
10797
10798 err = nl80211_parse_chandef(rdev, info, &chandef);
10799 if (err)
10800 return err;
10801
10802 /*
10803 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10804 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10805 * specification is not defined for them.
10806 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010807 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010808 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10809 chandef.width != NL80211_CHAN_WIDTH_20)
10810 return -EINVAL;
10811
10812 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010813 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10814 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010815 return -EINVAL;
10816
10817 /* don't allow switching to DFS channels */
10818 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10819 return -EINVAL;
10820
10821 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10822 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10823
10824 wdev_lock(wdev);
10825 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10826 wdev_unlock(wdev);
10827
10828 return err;
10829}
10830
10831static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10832 struct genl_info *info)
10833{
10834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10835 struct net_device *dev = info->user_ptr[1];
10836 struct wireless_dev *wdev = dev->ieee80211_ptr;
10837 const u8 *addr;
10838
10839 if (!rdev->ops->tdls_channel_switch ||
10840 !rdev->ops->tdls_cancel_channel_switch ||
10841 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10842 return -EOPNOTSUPP;
10843
10844 switch (dev->ieee80211_ptr->iftype) {
10845 case NL80211_IFTYPE_STATION:
10846 case NL80211_IFTYPE_P2P_CLIENT:
10847 break;
10848 default:
10849 return -EOPNOTSUPP;
10850 }
10851
10852 if (!info->attrs[NL80211_ATTR_MAC])
10853 return -EINVAL;
10854
10855 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10856
10857 wdev_lock(wdev);
10858 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10859 wdev_unlock(wdev);
10860
10861 return 0;
10862}
10863
Johannes Berg4c476992010-10-04 21:36:35 +020010864#define NL80211_FLAG_NEED_WIPHY 0x01
10865#define NL80211_FLAG_NEED_NETDEV 0x02
10866#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010867#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10868#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10869 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010870#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010871/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010872#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10873 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010874#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010875
Johannes Bergf84f7712013-11-14 17:14:45 +010010876static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010877 struct genl_info *info)
10878{
10879 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010880 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010881 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010882 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10883
10884 if (rtnl)
10885 rtnl_lock();
10886
10887 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010888 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010889 if (IS_ERR(rdev)) {
10890 if (rtnl)
10891 rtnl_unlock();
10892 return PTR_ERR(rdev);
10893 }
10894 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010895 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10896 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010897 ASSERT_RTNL();
10898
Johannes Berg89a54e42012-06-15 14:33:17 +020010899 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10900 info->attrs);
10901 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010902 if (rtnl)
10903 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010904 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010905 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010906
Johannes Berg89a54e42012-06-15 14:33:17 +020010907 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010908 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010909
Johannes Berg1bf614e2012-06-15 15:23:36 +020010910 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10911 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010912 if (rtnl)
10913 rtnl_unlock();
10914 return -EINVAL;
10915 }
10916
10917 info->user_ptr[1] = dev;
10918 } else {
10919 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010920 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010921
Johannes Berg1bf614e2012-06-15 15:23:36 +020010922 if (dev) {
10923 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10924 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010925 if (rtnl)
10926 rtnl_unlock();
10927 return -ENETDOWN;
10928 }
10929
10930 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010931 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10932 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010933 if (rtnl)
10934 rtnl_unlock();
10935 return -ENETDOWN;
10936 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010937 }
10938
Johannes Berg4c476992010-10-04 21:36:35 +020010939 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010940 }
10941
10942 return 0;
10943}
10944
Johannes Bergf84f7712013-11-14 17:14:45 +010010945static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010946 struct genl_info *info)
10947{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010948 if (info->user_ptr[1]) {
10949 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10950 struct wireless_dev *wdev = info->user_ptr[1];
10951
10952 if (wdev->netdev)
10953 dev_put(wdev->netdev);
10954 } else {
10955 dev_put(info->user_ptr[1]);
10956 }
10957 }
Johannes Berg5393b912014-09-10 15:00:16 +030010958
Johannes Berg4c476992010-10-04 21:36:35 +020010959 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10960 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010961
10962 /* If needed, clear the netlink message payload from the SKB
10963 * as it might contain key data that shouldn't stick around on
10964 * the heap after the SKB is freed. The netlink message header
10965 * is still needed for further processing, so leave it intact.
10966 */
10967 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10968 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10969
10970 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10971 }
Johannes Berg4c476992010-10-04 21:36:35 +020010972}
10973
Johannes Berg4534de82013-11-14 17:14:46 +010010974static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010975 {
10976 .cmd = NL80211_CMD_GET_WIPHY,
10977 .doit = nl80211_get_wiphy,
10978 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010979 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010980 .policy = nl80211_policy,
10981 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010982 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10983 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010984 },
10985 {
10986 .cmd = NL80211_CMD_SET_WIPHY,
10987 .doit = nl80211_set_wiphy,
10988 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020010989 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010990 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010991 },
10992 {
10993 .cmd = NL80211_CMD_GET_INTERFACE,
10994 .doit = nl80211_get_interface,
10995 .dumpit = nl80211_dump_interface,
10996 .policy = nl80211_policy,
10997 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010998 .internal_flags = NL80211_FLAG_NEED_WDEV |
10999 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011000 },
11001 {
11002 .cmd = NL80211_CMD_SET_INTERFACE,
11003 .doit = nl80211_set_interface,
11004 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011005 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011006 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11007 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011008 },
11009 {
11010 .cmd = NL80211_CMD_NEW_INTERFACE,
11011 .doit = nl80211_new_interface,
11012 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011013 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011014 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11015 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011016 },
11017 {
11018 .cmd = NL80211_CMD_DEL_INTERFACE,
11019 .doit = nl80211_del_interface,
11020 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011021 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011022 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011023 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011024 },
Johannes Berg41ade002007-12-19 02:03:29 +010011025 {
11026 .cmd = NL80211_CMD_GET_KEY,
11027 .doit = nl80211_get_key,
11028 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011029 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011030 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011031 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011032 },
11033 {
11034 .cmd = NL80211_CMD_SET_KEY,
11035 .doit = nl80211_set_key,
11036 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011037 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011038 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011039 NL80211_FLAG_NEED_RTNL |
11040 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011041 },
11042 {
11043 .cmd = NL80211_CMD_NEW_KEY,
11044 .doit = nl80211_new_key,
11045 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011046 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011048 NL80211_FLAG_NEED_RTNL |
11049 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011050 },
11051 {
11052 .cmd = NL80211_CMD_DEL_KEY,
11053 .doit = nl80211_del_key,
11054 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011055 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011056 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011057 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011058 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011059 {
11060 .cmd = NL80211_CMD_SET_BEACON,
11061 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011062 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011063 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011064 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011065 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011066 },
11067 {
Johannes Berg88600202012-02-13 15:17:18 +010011068 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011069 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011070 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011071 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011073 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011074 },
11075 {
Johannes Berg88600202012-02-13 15:17:18 +010011076 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011077 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011078 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011079 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011080 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011081 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011082 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011083 {
11084 .cmd = NL80211_CMD_GET_STATION,
11085 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011086 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011087 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011088 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11089 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011090 },
11091 {
11092 .cmd = NL80211_CMD_SET_STATION,
11093 .doit = nl80211_set_station,
11094 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011095 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011097 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011098 },
11099 {
11100 .cmd = NL80211_CMD_NEW_STATION,
11101 .doit = nl80211_new_station,
11102 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011103 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011105 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011106 },
11107 {
11108 .cmd = NL80211_CMD_DEL_STATION,
11109 .doit = nl80211_del_station,
11110 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011111 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011112 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011113 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011114 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011115 {
11116 .cmd = NL80211_CMD_GET_MPATH,
11117 .doit = nl80211_get_mpath,
11118 .dumpit = nl80211_dump_mpath,
11119 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011120 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011121 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011122 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011123 },
11124 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011125 .cmd = NL80211_CMD_GET_MPP,
11126 .doit = nl80211_get_mpp,
11127 .dumpit = nl80211_dump_mpp,
11128 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011129 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011130 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11131 NL80211_FLAG_NEED_RTNL,
11132 },
11133 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011134 .cmd = NL80211_CMD_SET_MPATH,
11135 .doit = nl80211_set_mpath,
11136 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011137 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011138 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011139 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011140 },
11141 {
11142 .cmd = NL80211_CMD_NEW_MPATH,
11143 .doit = nl80211_new_mpath,
11144 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011145 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011146 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011147 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011148 },
11149 {
11150 .cmd = NL80211_CMD_DEL_MPATH,
11151 .doit = nl80211_del_mpath,
11152 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011153 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011154 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011155 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011156 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011157 {
11158 .cmd = NL80211_CMD_SET_BSS,
11159 .doit = nl80211_set_bss,
11160 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011161 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011163 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011164 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011165 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011166 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011167 .doit = nl80211_get_reg_do,
11168 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011169 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011170 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011171 /* can be retrieved by unprivileged users */
11172 },
Johannes Bergb6863032015-10-15 09:25:18 +020011173#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011174 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011175 .cmd = NL80211_CMD_SET_REG,
11176 .doit = nl80211_set_reg,
11177 .policy = nl80211_policy,
11178 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011179 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011180 },
Johannes Bergb6863032015-10-15 09:25:18 +020011181#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011182 {
11183 .cmd = NL80211_CMD_REQ_SET_REG,
11184 .doit = nl80211_req_set_reg,
11185 .policy = nl80211_policy,
11186 .flags = GENL_ADMIN_PERM,
11187 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011188 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011189 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11190 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011191 .policy = nl80211_policy,
11192 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011193 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011194 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011195 },
11196 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011197 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11198 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011199 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011200 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011201 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011202 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011203 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011204 {
Johannes Berg2a519312009-02-10 21:25:55 +010011205 .cmd = NL80211_CMD_TRIGGER_SCAN,
11206 .doit = nl80211_trigger_scan,
11207 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011208 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011209 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011210 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011211 },
11212 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011213 .cmd = NL80211_CMD_ABORT_SCAN,
11214 .doit = nl80211_abort_scan,
11215 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011216 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011217 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11218 NL80211_FLAG_NEED_RTNL,
11219 },
11220 {
Johannes Berg2a519312009-02-10 21:25:55 +010011221 .cmd = NL80211_CMD_GET_SCAN,
11222 .policy = nl80211_policy,
11223 .dumpit = nl80211_dump_scan,
11224 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011225 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011226 .cmd = NL80211_CMD_START_SCHED_SCAN,
11227 .doit = nl80211_start_sched_scan,
11228 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011229 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11231 NL80211_FLAG_NEED_RTNL,
11232 },
11233 {
11234 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11235 .doit = nl80211_stop_sched_scan,
11236 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011237 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11239 NL80211_FLAG_NEED_RTNL,
11240 },
11241 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011242 .cmd = NL80211_CMD_AUTHENTICATE,
11243 .doit = nl80211_authenticate,
11244 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011245 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011247 NL80211_FLAG_NEED_RTNL |
11248 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011249 },
11250 {
11251 .cmd = NL80211_CMD_ASSOCIATE,
11252 .doit = nl80211_associate,
11253 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011254 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011255 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011256 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011257 },
11258 {
11259 .cmd = NL80211_CMD_DEAUTHENTICATE,
11260 .doit = nl80211_deauthenticate,
11261 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011262 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011263 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011264 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011265 },
11266 {
11267 .cmd = NL80211_CMD_DISASSOCIATE,
11268 .doit = nl80211_disassociate,
11269 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011270 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011271 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011272 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011273 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011274 {
11275 .cmd = NL80211_CMD_JOIN_IBSS,
11276 .doit = nl80211_join_ibss,
11277 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011278 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011280 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011281 },
11282 {
11283 .cmd = NL80211_CMD_LEAVE_IBSS,
11284 .doit = nl80211_leave_ibss,
11285 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011286 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011287 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011288 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011289 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011290#ifdef CONFIG_NL80211_TESTMODE
11291 {
11292 .cmd = NL80211_CMD_TESTMODE,
11293 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011294 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011295 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011296 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011297 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11298 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011299 },
11300#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011301 {
11302 .cmd = NL80211_CMD_CONNECT,
11303 .doit = nl80211_connect,
11304 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011305 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011307 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011308 },
11309 {
11310 .cmd = NL80211_CMD_DISCONNECT,
11311 .doit = nl80211_disconnect,
11312 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011313 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011315 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011316 },
Johannes Berg463d0182009-07-14 00:33:35 +020011317 {
11318 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11319 .doit = nl80211_wiphy_netns,
11320 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011321 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011322 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11323 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011324 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011325 {
11326 .cmd = NL80211_CMD_GET_SURVEY,
11327 .policy = nl80211_policy,
11328 .dumpit = nl80211_dump_survey,
11329 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011330 {
11331 .cmd = NL80211_CMD_SET_PMKSA,
11332 .doit = nl80211_setdel_pmksa,
11333 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011334 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011335 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011336 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011337 },
11338 {
11339 .cmd = NL80211_CMD_DEL_PMKSA,
11340 .doit = nl80211_setdel_pmksa,
11341 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011342 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011343 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011344 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011345 },
11346 {
11347 .cmd = NL80211_CMD_FLUSH_PMKSA,
11348 .doit = nl80211_flush_pmksa,
11349 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011350 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011351 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011352 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011353 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011354 {
11355 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11356 .doit = nl80211_remain_on_channel,
11357 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011358 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011359 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011360 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011361 },
11362 {
11363 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11364 .doit = nl80211_cancel_remain_on_channel,
11365 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011366 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011367 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011368 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011369 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011370 {
11371 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11372 .doit = nl80211_set_tx_bitrate_mask,
11373 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011374 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011375 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11376 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011377 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011378 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011379 .cmd = NL80211_CMD_REGISTER_FRAME,
11380 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011381 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011382 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011383 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011384 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011385 },
11386 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011387 .cmd = NL80211_CMD_FRAME,
11388 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011389 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011390 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011391 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011392 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011393 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011394 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011395 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11396 .doit = nl80211_tx_mgmt_cancel_wait,
11397 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011398 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011399 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011400 NL80211_FLAG_NEED_RTNL,
11401 },
11402 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011403 .cmd = NL80211_CMD_SET_POWER_SAVE,
11404 .doit = nl80211_set_power_save,
11405 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011406 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011407 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11408 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011409 },
11410 {
11411 .cmd = NL80211_CMD_GET_POWER_SAVE,
11412 .doit = nl80211_get_power_save,
11413 .policy = nl80211_policy,
11414 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011415 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11416 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011417 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011418 {
11419 .cmd = NL80211_CMD_SET_CQM,
11420 .doit = nl80211_set_cqm,
11421 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011422 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011423 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11424 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011425 },
Johannes Bergf444de02010-05-05 15:25:02 +020011426 {
11427 .cmd = NL80211_CMD_SET_CHANNEL,
11428 .doit = nl80211_set_channel,
11429 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011430 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011431 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11432 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011433 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011434 {
11435 .cmd = NL80211_CMD_SET_WDS_PEER,
11436 .doit = nl80211_set_wds_peer,
11437 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011438 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011439 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11440 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011441 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011442 {
11443 .cmd = NL80211_CMD_JOIN_MESH,
11444 .doit = nl80211_join_mesh,
11445 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011446 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11448 NL80211_FLAG_NEED_RTNL,
11449 },
11450 {
11451 .cmd = NL80211_CMD_LEAVE_MESH,
11452 .doit = nl80211_leave_mesh,
11453 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011454 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11456 NL80211_FLAG_NEED_RTNL,
11457 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011458 {
11459 .cmd = NL80211_CMD_JOIN_OCB,
11460 .doit = nl80211_join_ocb,
11461 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011462 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11464 NL80211_FLAG_NEED_RTNL,
11465 },
11466 {
11467 .cmd = NL80211_CMD_LEAVE_OCB,
11468 .doit = nl80211_leave_ocb,
11469 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011470 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11472 NL80211_FLAG_NEED_RTNL,
11473 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011474#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011475 {
11476 .cmd = NL80211_CMD_GET_WOWLAN,
11477 .doit = nl80211_get_wowlan,
11478 .policy = nl80211_policy,
11479 /* can be retrieved by unprivileged users */
11480 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11481 NL80211_FLAG_NEED_RTNL,
11482 },
11483 {
11484 .cmd = NL80211_CMD_SET_WOWLAN,
11485 .doit = nl80211_set_wowlan,
11486 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011487 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011488 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11489 NL80211_FLAG_NEED_RTNL,
11490 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011491#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011492 {
11493 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11494 .doit = nl80211_set_rekey_data,
11495 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011496 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011498 NL80211_FLAG_NEED_RTNL |
11499 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011500 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011501 {
11502 .cmd = NL80211_CMD_TDLS_MGMT,
11503 .doit = nl80211_tdls_mgmt,
11504 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011505 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011506 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11507 NL80211_FLAG_NEED_RTNL,
11508 },
11509 {
11510 .cmd = NL80211_CMD_TDLS_OPER,
11511 .doit = nl80211_tdls_oper,
11512 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011513 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011514 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11515 NL80211_FLAG_NEED_RTNL,
11516 },
Johannes Berg28946da2011-11-04 11:18:12 +010011517 {
11518 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11519 .doit = nl80211_register_unexpected_frame,
11520 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011521 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011522 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11523 NL80211_FLAG_NEED_RTNL,
11524 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011525 {
11526 .cmd = NL80211_CMD_PROBE_CLIENT,
11527 .doit = nl80211_probe_client,
11528 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011529 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011531 NL80211_FLAG_NEED_RTNL,
11532 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011533 {
11534 .cmd = NL80211_CMD_REGISTER_BEACONS,
11535 .doit = nl80211_register_beacons,
11536 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011537 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010011538 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11539 NL80211_FLAG_NEED_RTNL,
11540 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011541 {
11542 .cmd = NL80211_CMD_SET_NOACK_MAP,
11543 .doit = nl80211_set_noack_map,
11544 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011545 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011546 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11547 NL80211_FLAG_NEED_RTNL,
11548 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011549 {
11550 .cmd = NL80211_CMD_START_P2P_DEVICE,
11551 .doit = nl80211_start_p2p_device,
11552 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011553 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011554 .internal_flags = NL80211_FLAG_NEED_WDEV |
11555 NL80211_FLAG_NEED_RTNL,
11556 },
11557 {
11558 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11559 .doit = nl80211_stop_p2p_device,
11560 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011561 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011562 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11563 NL80211_FLAG_NEED_RTNL,
11564 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011565 {
11566 .cmd = NL80211_CMD_SET_MCAST_RATE,
11567 .doit = nl80211_set_mcast_rate,
11568 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011569 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011570 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11571 NL80211_FLAG_NEED_RTNL,
11572 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011573 {
11574 .cmd = NL80211_CMD_SET_MAC_ACL,
11575 .doit = nl80211_set_mac_acl,
11576 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011577 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011578 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11579 NL80211_FLAG_NEED_RTNL,
11580 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011581 {
11582 .cmd = NL80211_CMD_RADAR_DETECT,
11583 .doit = nl80211_start_radar_detection,
11584 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011585 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11587 NL80211_FLAG_NEED_RTNL,
11588 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011589 {
11590 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11591 .doit = nl80211_get_protocol_features,
11592 .policy = nl80211_policy,
11593 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011594 {
11595 .cmd = NL80211_CMD_UPDATE_FT_IES,
11596 .doit = nl80211_update_ft_ies,
11597 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011598 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011599 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11600 NL80211_FLAG_NEED_RTNL,
11601 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011602 {
11603 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11604 .doit = nl80211_crit_protocol_start,
11605 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011606 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011607 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11608 NL80211_FLAG_NEED_RTNL,
11609 },
11610 {
11611 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11612 .doit = nl80211_crit_protocol_stop,
11613 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011614 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011615 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11616 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011617 },
11618 {
11619 .cmd = NL80211_CMD_GET_COALESCE,
11620 .doit = nl80211_get_coalesce,
11621 .policy = nl80211_policy,
11622 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11623 NL80211_FLAG_NEED_RTNL,
11624 },
11625 {
11626 .cmd = NL80211_CMD_SET_COALESCE,
11627 .doit = nl80211_set_coalesce,
11628 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011629 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011630 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11631 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011632 },
11633 {
11634 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11635 .doit = nl80211_channel_switch,
11636 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011637 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011638 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11639 NL80211_FLAG_NEED_RTNL,
11640 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011641 {
11642 .cmd = NL80211_CMD_VENDOR,
11643 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011644 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011645 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011646 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011647 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11648 NL80211_FLAG_NEED_RTNL,
11649 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011650 {
11651 .cmd = NL80211_CMD_SET_QOS_MAP,
11652 .doit = nl80211_set_qos_map,
11653 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011654 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11656 NL80211_FLAG_NEED_RTNL,
11657 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011658 {
11659 .cmd = NL80211_CMD_ADD_TX_TS,
11660 .doit = nl80211_add_tx_ts,
11661 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011662 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11664 NL80211_FLAG_NEED_RTNL,
11665 },
11666 {
11667 .cmd = NL80211_CMD_DEL_TX_TS,
11668 .doit = nl80211_del_tx_ts,
11669 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011670 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11672 NL80211_FLAG_NEED_RTNL,
11673 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011674 {
11675 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11676 .doit = nl80211_tdls_channel_switch,
11677 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011678 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11680 NL80211_FLAG_NEED_RTNL,
11681 },
11682 {
11683 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11684 .doit = nl80211_tdls_cancel_channel_switch,
11685 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011686 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11688 NL80211_FLAG_NEED_RTNL,
11689 },
Johannes Berg55682962007-09-20 13:09:35 -040011690};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011691
Johannes Berg55682962007-09-20 13:09:35 -040011692/* notification functions */
11693
Johannes Berg3bb20552014-05-26 13:52:25 +020011694void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11695 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011696{
11697 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011698 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011699
Johannes Berg3bb20552014-05-26 13:52:25 +020011700 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11701 cmd != NL80211_CMD_DEL_WIPHY);
11702
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011703 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011704 if (!msg)
11705 return;
11706
Johannes Berg3bb20552014-05-26 13:52:25 +020011707 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011708 nlmsg_free(msg);
11709 return;
11710 }
11711
Johannes Berg68eb5502013-11-19 15:19:38 +010011712 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011713 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011714}
11715
Johannes Berg362a4152009-05-24 16:43:15 +020011716static int nl80211_add_scan_req(struct sk_buff *msg,
11717 struct cfg80211_registered_device *rdev)
11718{
11719 struct cfg80211_scan_request *req = rdev->scan_req;
11720 struct nlattr *nest;
11721 int i;
11722
11723 if (WARN_ON(!req))
11724 return 0;
11725
11726 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11727 if (!nest)
11728 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011729 for (i = 0; i < req->n_ssids; i++) {
11730 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11731 goto nla_put_failure;
11732 }
Johannes Berg362a4152009-05-24 16:43:15 +020011733 nla_nest_end(msg, nest);
11734
11735 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11736 if (!nest)
11737 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011738 for (i = 0; i < req->n_channels; i++) {
11739 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11740 goto nla_put_failure;
11741 }
Johannes Berg362a4152009-05-24 16:43:15 +020011742 nla_nest_end(msg, nest);
11743
David S. Miller9360ffd2012-03-29 04:41:26 -040011744 if (req->ie &&
11745 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11746 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011747
Johannes Bergae917c92013-10-25 11:05:22 +020011748 if (req->flags &&
11749 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11750 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011751
Johannes Berg362a4152009-05-24 16:43:15 +020011752 return 0;
11753 nla_put_failure:
11754 return -ENOBUFS;
11755}
11756
Johannes Berga538e2d2009-06-16 19:56:42 +020011757static int nl80211_send_scan_msg(struct sk_buff *msg,
11758 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011759 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011760 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011761 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011762{
11763 void *hdr;
11764
Eric W. Biederman15e47302012-09-07 20:12:54 +000011765 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011766 if (!hdr)
11767 return -1;
11768
David S. Miller9360ffd2012-03-29 04:41:26 -040011769 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011770 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11771 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011772 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11773 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011774 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011775
Johannes Berg362a4152009-05-24 16:43:15 +020011776 /* ignore errors and send incomplete event anyway */
11777 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011778
Johannes Berg053c0952015-01-16 22:09:00 +010011779 genlmsg_end(msg, hdr);
11780 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011781
11782 nla_put_failure:
11783 genlmsg_cancel(msg, hdr);
11784 return -EMSGSIZE;
11785}
11786
Luciano Coelho807f8a82011-05-11 17:09:35 +030011787static int
11788nl80211_send_sched_scan_msg(struct sk_buff *msg,
11789 struct cfg80211_registered_device *rdev,
11790 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011791 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011792{
11793 void *hdr;
11794
Eric W. Biederman15e47302012-09-07 20:12:54 +000011795 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011796 if (!hdr)
11797 return -1;
11798
David S. Miller9360ffd2012-03-29 04:41:26 -040011799 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11800 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11801 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011802
Johannes Berg053c0952015-01-16 22:09:00 +010011803 genlmsg_end(msg, hdr);
11804 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011805
11806 nla_put_failure:
11807 genlmsg_cancel(msg, hdr);
11808 return -EMSGSIZE;
11809}
11810
Johannes Berga538e2d2009-06-16 19:56:42 +020011811void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011812 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011813{
11814 struct sk_buff *msg;
11815
Thomas Graf58050fc2012-06-28 03:57:45 +000011816 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011817 if (!msg)
11818 return;
11819
Johannes Bergfd014282012-06-18 19:17:03 +020011820 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011821 NL80211_CMD_TRIGGER_SCAN) < 0) {
11822 nlmsg_free(msg);
11823 return;
11824 }
11825
Johannes Berg68eb5502013-11-19 15:19:38 +010011826 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011827 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011828}
11829
Johannes Bergf9d15d12014-01-22 11:14:19 +020011830struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11831 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011832{
11833 struct sk_buff *msg;
11834
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011835 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011836 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011837 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011838
Johannes Bergfd014282012-06-18 19:17:03 +020011839 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011840 aborted ? NL80211_CMD_SCAN_ABORTED :
11841 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011842 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011843 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011844 }
11845
Johannes Bergf9d15d12014-01-22 11:14:19 +020011846 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011847}
11848
Johannes Bergf9d15d12014-01-22 11:14:19 +020011849void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11850 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011851{
Johannes Berg2a519312009-02-10 21:25:55 +010011852 if (!msg)
11853 return;
11854
Johannes Berg68eb5502013-11-19 15:19:38 +010011855 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011856 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011857}
11858
Luciano Coelho807f8a82011-05-11 17:09:35 +030011859void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11860 struct net_device *netdev)
11861{
11862 struct sk_buff *msg;
11863
11864 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11865 if (!msg)
11866 return;
11867
11868 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11869 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11870 nlmsg_free(msg);
11871 return;
11872 }
11873
Johannes Berg68eb5502013-11-19 15:19:38 +010011874 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011875 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011876}
11877
11878void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11879 struct net_device *netdev, u32 cmd)
11880{
11881 struct sk_buff *msg;
11882
Thomas Graf58050fc2012-06-28 03:57:45 +000011883 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011884 if (!msg)
11885 return;
11886
11887 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11888 nlmsg_free(msg);
11889 return;
11890 }
11891
Johannes Berg68eb5502013-11-19 15:19:38 +010011892 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011893 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011894}
11895
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011896static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11897 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011898{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011899 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011900 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11901 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011902
David S. Miller9360ffd2012-03-29 04:41:26 -040011903 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11904 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11905 NL80211_REGDOM_TYPE_WORLD))
11906 goto nla_put_failure;
11907 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11908 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11909 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11910 goto nla_put_failure;
11911 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11912 request->intersect) {
11913 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11914 NL80211_REGDOM_TYPE_INTERSECTION))
11915 goto nla_put_failure;
11916 } else {
11917 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11918 NL80211_REGDOM_TYPE_COUNTRY) ||
11919 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11920 request->alpha2))
11921 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011922 }
11923
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011924 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11925 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11926
11927 if (wiphy &&
11928 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11929 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011930
11931 if (wiphy &&
11932 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11933 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11934 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011935 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011936
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011937 return true;
11938
11939nla_put_failure:
11940 return false;
11941}
11942
11943/*
11944 * This can happen on global regulatory changes or device specific settings
11945 * based on custom regulatory domains.
11946 */
11947void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11948 struct regulatory_request *request)
11949{
11950 struct sk_buff *msg;
11951 void *hdr;
11952
11953 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11954 if (!msg)
11955 return;
11956
11957 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11958 if (!hdr) {
11959 nlmsg_free(msg);
11960 return;
11961 }
11962
11963 if (nl80211_reg_change_event_fill(msg, request) == false)
11964 goto nla_put_failure;
11965
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011966 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011967
Johannes Bergbc43b282009-07-25 10:54:13 +020011968 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011969 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011970 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011971 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011972
11973 return;
11974
11975nla_put_failure:
11976 genlmsg_cancel(msg, hdr);
11977 nlmsg_free(msg);
11978}
11979
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011980static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11981 struct net_device *netdev,
11982 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011983 enum nl80211_commands cmd, gfp_t gfp,
11984 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011985{
11986 struct sk_buff *msg;
11987 void *hdr;
11988
Johannes Berge6d6e342009-07-01 21:26:47 +020011989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011990 if (!msg)
11991 return;
11992
11993 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11994 if (!hdr) {
11995 nlmsg_free(msg);
11996 return;
11997 }
11998
David S. Miller9360ffd2012-03-29 04:41:26 -040011999 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12000 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12001 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12002 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012003
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012004 if (uapsd_queues >= 0) {
12005 struct nlattr *nla_wmm =
12006 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12007 if (!nla_wmm)
12008 goto nla_put_failure;
12009
12010 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12011 uapsd_queues))
12012 goto nla_put_failure;
12013
12014 nla_nest_end(msg, nla_wmm);
12015 }
12016
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012017 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012018
Johannes Berg68eb5502013-11-19 15:19:38 +010012019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012020 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012021 return;
12022
12023 nla_put_failure:
12024 genlmsg_cancel(msg, hdr);
12025 nlmsg_free(msg);
12026}
12027
12028void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012029 struct net_device *netdev, const u8 *buf,
12030 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012031{
12032 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012033 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012034}
12035
12036void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12037 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012038 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012039{
Johannes Berge6d6e342009-07-01 21:26:47 +020012040 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012041 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012042}
12043
Jouni Malinen53b46b82009-03-27 20:53:56 +020012044void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012045 struct net_device *netdev, const u8 *buf,
12046 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012047{
12048 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012049 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012050}
12051
Jouni Malinen53b46b82009-03-27 20:53:56 +020012052void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12053 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012054 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012055{
12056 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012057 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012058}
12059
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012060void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12061 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012062{
Johannes Berg947add32013-02-22 22:05:20 +010012063 struct wireless_dev *wdev = dev->ieee80211_ptr;
12064 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012065 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012066 const struct ieee80211_mgmt *mgmt = (void *)buf;
12067 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012068
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012069 if (WARN_ON(len < 2))
12070 return;
12071
12072 if (ieee80211_is_deauth(mgmt->frame_control))
12073 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12074 else
12075 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12076
12077 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012078 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012079}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012080EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012081
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012082static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12083 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012084 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012085{
12086 struct sk_buff *msg;
12087 void *hdr;
12088
Johannes Berge6d6e342009-07-01 21:26:47 +020012089 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012090 if (!msg)
12091 return;
12092
12093 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12094 if (!hdr) {
12095 nlmsg_free(msg);
12096 return;
12097 }
12098
David S. Miller9360ffd2012-03-29 04:41:26 -040012099 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12100 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12101 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12102 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12103 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012104
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012105 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012106
Johannes Berg68eb5502013-11-19 15:19:38 +010012107 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012108 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012109 return;
12110
12111 nla_put_failure:
12112 genlmsg_cancel(msg, hdr);
12113 nlmsg_free(msg);
12114}
12115
12116void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012117 struct net_device *netdev, const u8 *addr,
12118 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012119{
12120 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012121 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012122}
12123
12124void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012125 struct net_device *netdev, const u8 *addr,
12126 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012127{
Johannes Berge6d6e342009-07-01 21:26:47 +020012128 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12129 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012130}
12131
Samuel Ortizb23aa672009-07-01 21:26:54 +020012132void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12133 struct net_device *netdev, const u8 *bssid,
12134 const u8 *req_ie, size_t req_ie_len,
12135 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012136 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012137{
12138 struct sk_buff *msg;
12139 void *hdr;
12140
Thomas Graf58050fc2012-06-28 03:57:45 +000012141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012142 if (!msg)
12143 return;
12144
12145 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12146 if (!hdr) {
12147 nlmsg_free(msg);
12148 return;
12149 }
12150
David S. Miller9360ffd2012-03-29 04:41:26 -040012151 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12152 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12153 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030012154 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
12155 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
12156 status) ||
12157 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012158 (req_ie &&
12159 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12160 (resp_ie &&
12161 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12162 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012163
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012164 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012165
Johannes Berg68eb5502013-11-19 15:19:38 +010012166 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012167 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012168 return;
12169
12170 nla_put_failure:
12171 genlmsg_cancel(msg, hdr);
12172 nlmsg_free(msg);
12173
12174}
12175
12176void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12177 struct net_device *netdev, const u8 *bssid,
12178 const u8 *req_ie, size_t req_ie_len,
12179 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12180{
12181 struct sk_buff *msg;
12182 void *hdr;
12183
Thomas Graf58050fc2012-06-28 03:57:45 +000012184 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012185 if (!msg)
12186 return;
12187
12188 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12189 if (!hdr) {
12190 nlmsg_free(msg);
12191 return;
12192 }
12193
David S. Miller9360ffd2012-03-29 04:41:26 -040012194 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12195 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12196 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12197 (req_ie &&
12198 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12199 (resp_ie &&
12200 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12201 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012202
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012203 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012204
Johannes Berg68eb5502013-11-19 15:19:38 +010012205 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012206 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012207 return;
12208
12209 nla_put_failure:
12210 genlmsg_cancel(msg, hdr);
12211 nlmsg_free(msg);
12212
12213}
12214
12215void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12216 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012217 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012218{
12219 struct sk_buff *msg;
12220 void *hdr;
12221
Thomas Graf58050fc2012-06-28 03:57:45 +000012222 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012223 if (!msg)
12224 return;
12225
12226 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12227 if (!hdr) {
12228 nlmsg_free(msg);
12229 return;
12230 }
12231
David S. Miller9360ffd2012-03-29 04:41:26 -040012232 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12233 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12234 (from_ap && reason &&
12235 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12236 (from_ap &&
12237 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12238 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12239 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012240
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012241 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012242
Johannes Berg68eb5502013-11-19 15:19:38 +010012243 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012244 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012245 return;
12246
12247 nla_put_failure:
12248 genlmsg_cancel(msg, hdr);
12249 nlmsg_free(msg);
12250
12251}
12252
Johannes Berg04a773a2009-04-19 21:24:32 +020012253void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12254 struct net_device *netdev, const u8 *bssid,
12255 gfp_t gfp)
12256{
12257 struct sk_buff *msg;
12258 void *hdr;
12259
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012260 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012261 if (!msg)
12262 return;
12263
12264 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12265 if (!hdr) {
12266 nlmsg_free(msg);
12267 return;
12268 }
12269
David S. Miller9360ffd2012-03-29 04:41:26 -040012270 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12271 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12272 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12273 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012274
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012275 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012276
Johannes Berg68eb5502013-11-19 15:19:38 +010012277 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012278 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012279 return;
12280
12281 nla_put_failure:
12282 genlmsg_cancel(msg, hdr);
12283 nlmsg_free(msg);
12284}
12285
Johannes Berg947add32013-02-22 22:05:20 +010012286void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12287 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012288{
Johannes Berg947add32013-02-22 22:05:20 +010012289 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012290 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012291 struct sk_buff *msg;
12292 void *hdr;
12293
Johannes Berg947add32013-02-22 22:05:20 +010012294 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12295 return;
12296
12297 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12298
Javier Cardonac93b5e72011-04-07 15:08:34 -070012299 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12300 if (!msg)
12301 return;
12302
12303 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12304 if (!hdr) {
12305 nlmsg_free(msg);
12306 return;
12307 }
12308
David S. Miller9360ffd2012-03-29 04:41:26 -040012309 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012310 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12311 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012312 (ie_len && ie &&
12313 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12314 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012315
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012316 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012317
Johannes Berg68eb5502013-11-19 15:19:38 +010012318 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012319 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012320 return;
12321
12322 nla_put_failure:
12323 genlmsg_cancel(msg, hdr);
12324 nlmsg_free(msg);
12325}
Johannes Berg947add32013-02-22 22:05:20 +010012326EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012327
Jouni Malinena3b8b052009-03-27 21:59:49 +020012328void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12329 struct net_device *netdev, const u8 *addr,
12330 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012331 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012332{
12333 struct sk_buff *msg;
12334 void *hdr;
12335
Johannes Berge6d6e342009-07-01 21:26:47 +020012336 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012337 if (!msg)
12338 return;
12339
12340 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12341 if (!hdr) {
12342 nlmsg_free(msg);
12343 return;
12344 }
12345
David S. Miller9360ffd2012-03-29 04:41:26 -040012346 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12347 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12348 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12349 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12350 (key_id != -1 &&
12351 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12352 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12353 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012354
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012355 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012356
Johannes Berg68eb5502013-11-19 15:19:38 +010012357 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012358 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012359 return;
12360
12361 nla_put_failure:
12362 genlmsg_cancel(msg, hdr);
12363 nlmsg_free(msg);
12364}
12365
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012366void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12367 struct ieee80211_channel *channel_before,
12368 struct ieee80211_channel *channel_after)
12369{
12370 struct sk_buff *msg;
12371 void *hdr;
12372 struct nlattr *nl_freq;
12373
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012374 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012375 if (!msg)
12376 return;
12377
12378 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12379 if (!hdr) {
12380 nlmsg_free(msg);
12381 return;
12382 }
12383
12384 /*
12385 * Since we are applying the beacon hint to a wiphy we know its
12386 * wiphy_idx is valid
12387 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012388 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12389 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012390
12391 /* Before */
12392 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12393 if (!nl_freq)
12394 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012395 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012396 goto nla_put_failure;
12397 nla_nest_end(msg, nl_freq);
12398
12399 /* After */
12400 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12401 if (!nl_freq)
12402 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012403 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012404 goto nla_put_failure;
12405 nla_nest_end(msg, nl_freq);
12406
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012407 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012408
Johannes Berg463d0182009-07-14 00:33:35 +020012409 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012410 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012411 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012412 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012413
12414 return;
12415
12416nla_put_failure:
12417 genlmsg_cancel(msg, hdr);
12418 nlmsg_free(msg);
12419}
12420
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012421static void nl80211_send_remain_on_chan_event(
12422 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012423 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012424 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012425 unsigned int duration, gfp_t gfp)
12426{
12427 struct sk_buff *msg;
12428 void *hdr;
12429
12430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12431 if (!msg)
12432 return;
12433
12434 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12435 if (!hdr) {
12436 nlmsg_free(msg);
12437 return;
12438 }
12439
David S. Miller9360ffd2012-03-29 04:41:26 -040012440 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012441 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12442 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012443 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12444 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012445 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012446 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12447 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012448 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12449 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012450 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012451
David S. Miller9360ffd2012-03-29 04:41:26 -040012452 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12453 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12454 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012455
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012456 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012457
Johannes Berg68eb5502013-11-19 15:19:38 +010012458 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012459 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012460 return;
12461
12462 nla_put_failure:
12463 genlmsg_cancel(msg, hdr);
12464 nlmsg_free(msg);
12465}
12466
Johannes Berg947add32013-02-22 22:05:20 +010012467void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12468 struct ieee80211_channel *chan,
12469 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012470{
Johannes Berg947add32013-02-22 22:05:20 +010012471 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012472 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012473
12474 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012475 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012476 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012477 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012478}
Johannes Berg947add32013-02-22 22:05:20 +010012479EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012480
Johannes Berg947add32013-02-22 22:05:20 +010012481void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12482 struct ieee80211_channel *chan,
12483 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012484{
Johannes Berg947add32013-02-22 22:05:20 +010012485 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012486 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012487
12488 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012489 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012490 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012491}
Johannes Berg947add32013-02-22 22:05:20 +010012492EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012493
Johannes Berg947add32013-02-22 22:05:20 +010012494void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12495 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012496{
Johannes Berg947add32013-02-22 22:05:20 +010012497 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012498 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012499 struct sk_buff *msg;
12500
Johannes Berg947add32013-02-22 22:05:20 +010012501 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12502
Thomas Graf58050fc2012-06-28 03:57:45 +000012503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012504 if (!msg)
12505 return;
12506
Johannes Bergcf5ead82014-11-14 17:14:00 +010012507 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012508 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012509 nlmsg_free(msg);
12510 return;
12511 }
12512
Johannes Berg68eb5502013-11-19 15:19:38 +010012513 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012514 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012515}
Johannes Berg947add32013-02-22 22:05:20 +010012516EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012517
Johannes Bergcf5ead82014-11-14 17:14:00 +010012518void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12519 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012520{
Johannes Berg947add32013-02-22 22:05:20 +010012521 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012522 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012523 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012524 struct station_info empty_sinfo = {};
12525
12526 if (!sinfo)
12527 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012528
Johannes Berg947add32013-02-22 22:05:20 +010012529 trace_cfg80211_del_sta(dev, mac_addr);
12530
Thomas Graf58050fc2012-06-28 03:57:45 +000012531 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012532 if (!msg)
12533 return;
12534
Johannes Bergcf5ead82014-11-14 17:14:00 +010012535 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012536 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012537 nlmsg_free(msg);
12538 return;
12539 }
12540
Johannes Berg68eb5502013-11-19 15:19:38 +010012541 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012542 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012543}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012544EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012545
Johannes Berg947add32013-02-22 22:05:20 +010012546void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12547 enum nl80211_connect_failed_reason reason,
12548 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012549{
Johannes Berg947add32013-02-22 22:05:20 +010012550 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012551 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012552 struct sk_buff *msg;
12553 void *hdr;
12554
12555 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12556 if (!msg)
12557 return;
12558
12559 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12560 if (!hdr) {
12561 nlmsg_free(msg);
12562 return;
12563 }
12564
12565 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12566 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12567 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12568 goto nla_put_failure;
12569
12570 genlmsg_end(msg, hdr);
12571
Johannes Berg68eb5502013-11-19 15:19:38 +010012572 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012573 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012574 return;
12575
12576 nla_put_failure:
12577 genlmsg_cancel(msg, hdr);
12578 nlmsg_free(msg);
12579}
Johannes Berg947add32013-02-22 22:05:20 +010012580EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012581
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012582static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12583 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012584{
12585 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012586 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012587 struct sk_buff *msg;
12588 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012589 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012590
Eric W. Biederman15e47302012-09-07 20:12:54 +000012591 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012592 return false;
12593
12594 msg = nlmsg_new(100, gfp);
12595 if (!msg)
12596 return true;
12597
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012598 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012599 if (!hdr) {
12600 nlmsg_free(msg);
12601 return true;
12602 }
12603
David S. Miller9360ffd2012-03-29 04:41:26 -040012604 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12605 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12606 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12607 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012608
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012609 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012610 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012611 return true;
12612
12613 nla_put_failure:
12614 genlmsg_cancel(msg, hdr);
12615 nlmsg_free(msg);
12616 return true;
12617}
12618
Johannes Berg947add32013-02-22 22:05:20 +010012619bool cfg80211_rx_spurious_frame(struct net_device *dev,
12620 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012621{
Johannes Berg947add32013-02-22 22:05:20 +010012622 struct wireless_dev *wdev = dev->ieee80211_ptr;
12623 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012624
Johannes Berg947add32013-02-22 22:05:20 +010012625 trace_cfg80211_rx_spurious_frame(dev, addr);
12626
12627 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12628 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12629 trace_cfg80211_return_bool(false);
12630 return false;
12631 }
12632 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12633 addr, gfp);
12634 trace_cfg80211_return_bool(ret);
12635 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012636}
Johannes Berg947add32013-02-22 22:05:20 +010012637EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12638
12639bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12640 const u8 *addr, gfp_t gfp)
12641{
12642 struct wireless_dev *wdev = dev->ieee80211_ptr;
12643 bool ret;
12644
12645 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12646
12647 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12648 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12649 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12650 trace_cfg80211_return_bool(false);
12651 return false;
12652 }
12653 ret = __nl80211_unexpected_frame(dev,
12654 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12655 addr, gfp);
12656 trace_cfg80211_return_bool(ret);
12657 return ret;
12658}
12659EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012660
Johannes Berg2e161f72010-08-12 15:38:38 +020012661int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012662 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012663 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012664 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012665{
Johannes Berg71bbc992012-06-15 15:30:18 +020012666 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012667 struct sk_buff *msg;
12668 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012669
12670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12671 if (!msg)
12672 return -ENOMEM;
12673
Johannes Berg2e161f72010-08-12 15:38:38 +020012674 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012675 if (!hdr) {
12676 nlmsg_free(msg);
12677 return -ENOMEM;
12678 }
12679
David S. Miller9360ffd2012-03-29 04:41:26 -040012680 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012681 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12682 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012683 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12684 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012685 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12686 (sig_dbm &&
12687 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012688 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12689 (flags &&
12690 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012691 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012692
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012693 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012694
Eric W. Biederman15e47302012-09-07 20:12:54 +000012695 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012696
12697 nla_put_failure:
12698 genlmsg_cancel(msg, hdr);
12699 nlmsg_free(msg);
12700 return -ENOBUFS;
12701}
12702
Johannes Berg947add32013-02-22 22:05:20 +010012703void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12704 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012705{
Johannes Berg947add32013-02-22 22:05:20 +010012706 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012707 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012708 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012709 struct sk_buff *msg;
12710 void *hdr;
12711
Johannes Berg947add32013-02-22 22:05:20 +010012712 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12713
Jouni Malinen026331c2010-02-15 12:53:10 +020012714 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12715 if (!msg)
12716 return;
12717
Johannes Berg2e161f72010-08-12 15:38:38 +020012718 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012719 if (!hdr) {
12720 nlmsg_free(msg);
12721 return;
12722 }
12723
David S. Miller9360ffd2012-03-29 04:41:26 -040012724 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012725 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12726 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012727 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12728 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012729 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012730 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12731 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012732 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12733 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012734
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012735 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012736
Johannes Berg68eb5502013-11-19 15:19:38 +010012737 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012738 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012739 return;
12740
12741 nla_put_failure:
12742 genlmsg_cancel(msg, hdr);
12743 nlmsg_free(msg);
12744}
Johannes Berg947add32013-02-22 22:05:20 +010012745EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012746
Johannes Berg5b97f492014-11-26 12:37:43 +010012747static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12748 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012749{
Johannes Berg947add32013-02-22 22:05:20 +010012750 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012751 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12752 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12753 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012754
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012755 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012756 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012757
Johannes Berg5b97f492014-11-26 12:37:43 +010012758 cb = (void **)msg->cb;
12759
12760 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12761 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012762 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012763 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012764 }
12765
David S. Miller9360ffd2012-03-29 04:41:26 -040012766 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012767 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012768 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012769
Johannes Berg5b97f492014-11-26 12:37:43 +010012770 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012771 goto nla_put_failure;
12772
Johannes Berg5b97f492014-11-26 12:37:43 +010012773 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12774 if (!cb[1])
12775 goto nla_put_failure;
12776
12777 cb[2] = rdev;
12778
12779 return msg;
12780 nla_put_failure:
12781 nlmsg_free(msg);
12782 return NULL;
12783}
12784
12785static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12786{
12787 void **cb = (void **)msg->cb;
12788 struct cfg80211_registered_device *rdev = cb[2];
12789
12790 nla_nest_end(msg, cb[1]);
12791 genlmsg_end(msg, cb[0]);
12792
12793 memset(msg->cb, 0, sizeof(msg->cb));
12794
12795 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12796 NL80211_MCGRP_MLME, gfp);
12797}
12798
12799void cfg80211_cqm_rssi_notify(struct net_device *dev,
12800 enum nl80211_cqm_rssi_threshold_event rssi_event,
12801 gfp_t gfp)
12802{
12803 struct sk_buff *msg;
12804
12805 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12806
Johannes Berg98f03342014-11-26 12:42:02 +010012807 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12808 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12809 return;
12810
Johannes Berg5b97f492014-11-26 12:37:43 +010012811 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12812 if (!msg)
12813 return;
12814
David S. Miller9360ffd2012-03-29 04:41:26 -040012815 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12816 rssi_event))
12817 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012818
Johannes Berg5b97f492014-11-26 12:37:43 +010012819 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012820
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012821 return;
12822
12823 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012824 nlmsg_free(msg);
12825}
Johannes Berg947add32013-02-22 22:05:20 +010012826EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012827
Johannes Berg5b97f492014-11-26 12:37:43 +010012828void cfg80211_cqm_txe_notify(struct net_device *dev,
12829 const u8 *peer, u32 num_packets,
12830 u32 rate, u32 intvl, gfp_t gfp)
12831{
12832 struct sk_buff *msg;
12833
12834 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12835 if (!msg)
12836 return;
12837
12838 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12839 goto nla_put_failure;
12840
12841 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12842 goto nla_put_failure;
12843
12844 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12845 goto nla_put_failure;
12846
12847 cfg80211_send_cqm(msg, gfp);
12848 return;
12849
12850 nla_put_failure:
12851 nlmsg_free(msg);
12852}
12853EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12854
12855void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12856 const u8 *peer, u32 num_packets, gfp_t gfp)
12857{
12858 struct sk_buff *msg;
12859
12860 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12861
12862 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12863 if (!msg)
12864 return;
12865
12866 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12867 goto nla_put_failure;
12868
12869 cfg80211_send_cqm(msg, gfp);
12870 return;
12871
12872 nla_put_failure:
12873 nlmsg_free(msg);
12874}
12875EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12876
Johannes Berg98f03342014-11-26 12:42:02 +010012877void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12878{
12879 struct sk_buff *msg;
12880
12881 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12882 if (!msg)
12883 return;
12884
12885 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12886 goto nla_put_failure;
12887
12888 cfg80211_send_cqm(msg, gfp);
12889 return;
12890
12891 nla_put_failure:
12892 nlmsg_free(msg);
12893}
12894EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12895
Johannes Berg947add32013-02-22 22:05:20 +010012896static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12897 struct net_device *netdev, const u8 *bssid,
12898 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012899{
12900 struct sk_buff *msg;
12901 struct nlattr *rekey_attr;
12902 void *hdr;
12903
Thomas Graf58050fc2012-06-28 03:57:45 +000012904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012905 if (!msg)
12906 return;
12907
12908 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12909 if (!hdr) {
12910 nlmsg_free(msg);
12911 return;
12912 }
12913
David S. Miller9360ffd2012-03-29 04:41:26 -040012914 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12915 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12916 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12917 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012918
12919 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12920 if (!rekey_attr)
12921 goto nla_put_failure;
12922
David S. Miller9360ffd2012-03-29 04:41:26 -040012923 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12924 NL80211_REPLAY_CTR_LEN, replay_ctr))
12925 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012926
12927 nla_nest_end(msg, rekey_attr);
12928
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012929 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012930
Johannes Berg68eb5502013-11-19 15:19:38 +010012931 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012932 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012933 return;
12934
12935 nla_put_failure:
12936 genlmsg_cancel(msg, hdr);
12937 nlmsg_free(msg);
12938}
12939
Johannes Berg947add32013-02-22 22:05:20 +010012940void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12941 const u8 *replay_ctr, gfp_t gfp)
12942{
12943 struct wireless_dev *wdev = dev->ieee80211_ptr;
12944 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012945 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012946
12947 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12948 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12949}
12950EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12951
12952static void
12953nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12954 struct net_device *netdev, int index,
12955 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012956{
12957 struct sk_buff *msg;
12958 struct nlattr *attr;
12959 void *hdr;
12960
Thomas Graf58050fc2012-06-28 03:57:45 +000012961 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012962 if (!msg)
12963 return;
12964
12965 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12966 if (!hdr) {
12967 nlmsg_free(msg);
12968 return;
12969 }
12970
David S. Miller9360ffd2012-03-29 04:41:26 -040012971 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12972 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12973 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012974
12975 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12976 if (!attr)
12977 goto nla_put_failure;
12978
David S. Miller9360ffd2012-03-29 04:41:26 -040012979 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12980 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12981 (preauth &&
12982 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12983 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012984
12985 nla_nest_end(msg, attr);
12986
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012987 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012988
Johannes Berg68eb5502013-11-19 15:19:38 +010012989 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012990 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012991 return;
12992
12993 nla_put_failure:
12994 genlmsg_cancel(msg, hdr);
12995 nlmsg_free(msg);
12996}
12997
Johannes Berg947add32013-02-22 22:05:20 +010012998void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12999 const u8 *bssid, bool preauth, gfp_t gfp)
13000{
13001 struct wireless_dev *wdev = dev->ieee80211_ptr;
13002 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013003 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013004
13005 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13006 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13007}
13008EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13009
13010static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13011 struct net_device *netdev,
13012 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013013 gfp_t gfp,
13014 enum nl80211_commands notif,
13015 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013016{
13017 struct sk_buff *msg;
13018 void *hdr;
13019
Thomas Graf58050fc2012-06-28 03:57:45 +000013020 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013021 if (!msg)
13022 return;
13023
Luciano Coelhof8d75522014-11-07 14:31:35 +020013024 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013025 if (!hdr) {
13026 nlmsg_free(msg);
13027 return;
13028 }
13029
Johannes Berg683b6d32012-11-08 21:25:48 +010013030 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13031 goto nla_put_failure;
13032
13033 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013034 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013035
Luciano Coelhof8d75522014-11-07 14:31:35 +020013036 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13037 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13038 goto nla_put_failure;
13039
Thomas Pedersen53145262012-04-06 13:35:47 -070013040 genlmsg_end(msg, hdr);
13041
Johannes Berg68eb5502013-11-19 15:19:38 +010013042 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013043 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013044 return;
13045
13046 nla_put_failure:
13047 genlmsg_cancel(msg, hdr);
13048 nlmsg_free(msg);
13049}
13050
Johannes Berg947add32013-02-22 22:05:20 +010013051void cfg80211_ch_switch_notify(struct net_device *dev,
13052 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013053{
Johannes Berg947add32013-02-22 22:05:20 +010013054 struct wireless_dev *wdev = dev->ieee80211_ptr;
13055 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013056 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013057
Simon Wunderliche487eae2013-11-21 18:19:51 +010013058 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013059
Simon Wunderliche487eae2013-11-21 18:19:51 +010013060 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013061
Michal Kazior9e0e2962014-01-29 14:22:27 +010013062 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013063 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013064 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13065 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013066}
13067EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13068
Luciano Coelhof8d75522014-11-07 14:31:35 +020013069void cfg80211_ch_switch_started_notify(struct net_device *dev,
13070 struct cfg80211_chan_def *chandef,
13071 u8 count)
13072{
13073 struct wireless_dev *wdev = dev->ieee80211_ptr;
13074 struct wiphy *wiphy = wdev->wiphy;
13075 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13076
13077 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13078
13079 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13080 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13081}
13082EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13083
Thomas Pedersen84f10702012-07-12 16:17:33 -070013084void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013085nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013086 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013087 enum nl80211_radar_event event,
13088 struct net_device *netdev, gfp_t gfp)
13089{
13090 struct sk_buff *msg;
13091 void *hdr;
13092
13093 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13094 if (!msg)
13095 return;
13096
13097 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13098 if (!hdr) {
13099 nlmsg_free(msg);
13100 return;
13101 }
13102
13103 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13104 goto nla_put_failure;
13105
13106 /* NOP and radar events don't need a netdev parameter */
13107 if (netdev) {
13108 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13109
13110 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013111 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13112 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013113 goto nla_put_failure;
13114 }
13115
13116 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13117 goto nla_put_failure;
13118
13119 if (nl80211_send_chandef(msg, chandef))
13120 goto nla_put_failure;
13121
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013122 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013123
Johannes Berg68eb5502013-11-19 15:19:38 +010013124 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013125 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013126 return;
13127
13128 nla_put_failure:
13129 genlmsg_cancel(msg, hdr);
13130 nlmsg_free(msg);
13131}
13132
Johannes Berg7f6cf312011-11-04 11:18:15 +010013133void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13134 u64 cookie, bool acked, gfp_t gfp)
13135{
13136 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013137 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013138 struct sk_buff *msg;
13139 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013140
Beni Lev4ee3e062012-08-27 12:49:39 +030013141 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13142
Thomas Graf58050fc2012-06-28 03:57:45 +000013143 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013144
Johannes Berg7f6cf312011-11-04 11:18:15 +010013145 if (!msg)
13146 return;
13147
13148 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13149 if (!hdr) {
13150 nlmsg_free(msg);
13151 return;
13152 }
13153
David S. Miller9360ffd2012-03-29 04:41:26 -040013154 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13155 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13156 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013157 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13158 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013159 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13160 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013161
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013162 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013163
Johannes Berg68eb5502013-11-19 15:19:38 +010013164 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013165 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013166 return;
13167
13168 nla_put_failure:
13169 genlmsg_cancel(msg, hdr);
13170 nlmsg_free(msg);
13171}
13172EXPORT_SYMBOL(cfg80211_probe_status);
13173
Johannes Berg5e7602302011-11-04 11:18:17 +010013174void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13175 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013176 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013177{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013178 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013179 struct sk_buff *msg;
13180 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013181 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013182
Beni Lev4ee3e062012-08-27 12:49:39 +030013183 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13184
Ben Greear37c73b52012-10-26 14:49:25 -070013185 spin_lock_bh(&rdev->beacon_registrations_lock);
13186 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13187 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13188 if (!msg) {
13189 spin_unlock_bh(&rdev->beacon_registrations_lock);
13190 return;
13191 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013192
Ben Greear37c73b52012-10-26 14:49:25 -070013193 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13194 if (!hdr)
13195 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013196
Ben Greear37c73b52012-10-26 14:49:25 -070013197 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13198 (freq &&
13199 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13200 (sig_dbm &&
13201 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13202 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13203 goto nla_put_failure;
13204
13205 genlmsg_end(msg, hdr);
13206
13207 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013208 }
Ben Greear37c73b52012-10-26 14:49:25 -070013209 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013210 return;
13211
13212 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013213 spin_unlock_bh(&rdev->beacon_registrations_lock);
13214 if (hdr)
13215 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013216 nlmsg_free(msg);
13217}
13218EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13219
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013220#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013221static int cfg80211_net_detect_results(struct sk_buff *msg,
13222 struct cfg80211_wowlan_wakeup *wakeup)
13223{
13224 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13225 struct nlattr *nl_results, *nl_match, *nl_freqs;
13226 int i, j;
13227
13228 nl_results = nla_nest_start(
13229 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13230 if (!nl_results)
13231 return -EMSGSIZE;
13232
13233 for (i = 0; i < nd->n_matches; i++) {
13234 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13235
13236 nl_match = nla_nest_start(msg, i);
13237 if (!nl_match)
13238 break;
13239
13240 /* The SSID attribute is optional in nl80211, but for
13241 * simplicity reasons it's always present in the
13242 * cfg80211 structure. If a driver can't pass the
13243 * SSID, that needs to be changed. A zero length SSID
13244 * is still a valid SSID (wildcard), so it cannot be
13245 * used for this purpose.
13246 */
13247 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13248 match->ssid.ssid)) {
13249 nla_nest_cancel(msg, nl_match);
13250 goto out;
13251 }
13252
13253 if (match->n_channels) {
13254 nl_freqs = nla_nest_start(
13255 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13256 if (!nl_freqs) {
13257 nla_nest_cancel(msg, nl_match);
13258 goto out;
13259 }
13260
13261 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013262 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013263 nla_nest_cancel(msg, nl_freqs);
13264 nla_nest_cancel(msg, nl_match);
13265 goto out;
13266 }
13267 }
13268
13269 nla_nest_end(msg, nl_freqs);
13270 }
13271
13272 nla_nest_end(msg, nl_match);
13273 }
13274
13275out:
13276 nla_nest_end(msg, nl_results);
13277 return 0;
13278}
13279
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013280void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13281 struct cfg80211_wowlan_wakeup *wakeup,
13282 gfp_t gfp)
13283{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013284 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013285 struct sk_buff *msg;
13286 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013287 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013288
13289 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13290
13291 if (wakeup)
13292 size += wakeup->packet_present_len;
13293
13294 msg = nlmsg_new(size, gfp);
13295 if (!msg)
13296 return;
13297
13298 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13299 if (!hdr)
13300 goto free_msg;
13301
13302 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013303 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13304 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013305 goto free_msg;
13306
13307 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13308 wdev->netdev->ifindex))
13309 goto free_msg;
13310
13311 if (wakeup) {
13312 struct nlattr *reasons;
13313
13314 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013315 if (!reasons)
13316 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013317
13318 if (wakeup->disconnect &&
13319 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13320 goto free_msg;
13321 if (wakeup->magic_pkt &&
13322 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13323 goto free_msg;
13324 if (wakeup->gtk_rekey_failure &&
13325 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13326 goto free_msg;
13327 if (wakeup->eap_identity_req &&
13328 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13329 goto free_msg;
13330 if (wakeup->four_way_handshake &&
13331 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13332 goto free_msg;
13333 if (wakeup->rfkill_release &&
13334 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13335 goto free_msg;
13336
13337 if (wakeup->pattern_idx >= 0 &&
13338 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13339 wakeup->pattern_idx))
13340 goto free_msg;
13341
Johannes Bergae917c92013-10-25 11:05:22 +020013342 if (wakeup->tcp_match &&
13343 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13344 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013345
Johannes Bergae917c92013-10-25 11:05:22 +020013346 if (wakeup->tcp_connlost &&
13347 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13348 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013349
Johannes Bergae917c92013-10-25 11:05:22 +020013350 if (wakeup->tcp_nomoretokens &&
13351 nla_put_flag(msg,
13352 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13353 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013354
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013355 if (wakeup->packet) {
13356 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13357 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13358
13359 if (!wakeup->packet_80211) {
13360 pkt_attr =
13361 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13362 len_attr =
13363 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13364 }
13365
13366 if (wakeup->packet_len &&
13367 nla_put_u32(msg, len_attr, wakeup->packet_len))
13368 goto free_msg;
13369
13370 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13371 wakeup->packet))
13372 goto free_msg;
13373 }
13374
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013375 if (wakeup->net_detect &&
13376 cfg80211_net_detect_results(msg, wakeup))
13377 goto free_msg;
13378
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013379 nla_nest_end(msg, reasons);
13380 }
13381
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013382 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013383
Johannes Berg68eb5502013-11-19 15:19:38 +010013384 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013385 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013386 return;
13387
13388 free_msg:
13389 nlmsg_free(msg);
13390}
13391EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13392#endif
13393
Jouni Malinen3475b092012-11-16 22:49:57 +020013394void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13395 enum nl80211_tdls_operation oper,
13396 u16 reason_code, gfp_t gfp)
13397{
13398 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013399 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013400 struct sk_buff *msg;
13401 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013402
13403 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13404 reason_code);
13405
13406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13407 if (!msg)
13408 return;
13409
13410 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13411 if (!hdr) {
13412 nlmsg_free(msg);
13413 return;
13414 }
13415
13416 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13417 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13418 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13419 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13420 (reason_code > 0 &&
13421 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13422 goto nla_put_failure;
13423
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013424 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013425
Johannes Berg68eb5502013-11-19 15:19:38 +010013426 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013427 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013428 return;
13429
13430 nla_put_failure:
13431 genlmsg_cancel(msg, hdr);
13432 nlmsg_free(msg);
13433}
13434EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13435
Jouni Malinen026331c2010-02-15 12:53:10 +020013436static int nl80211_netlink_notify(struct notifier_block * nb,
13437 unsigned long state,
13438 void *_notify)
13439{
13440 struct netlink_notify *notify = _notify;
13441 struct cfg80211_registered_device *rdev;
13442 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013443 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013444
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013445 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013446 return NOTIFY_DONE;
13447
13448 rcu_read_lock();
13449
Johannes Berg5e7602302011-11-04 11:18:17 +010013450 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013451 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013452 bool schedule_scan_stop = false;
13453 struct cfg80211_sched_scan_request *sched_scan_req =
13454 rcu_dereference(rdev->sched_scan_req);
13455
13456 if (sched_scan_req && notify->portid &&
13457 sched_scan_req->owner_nlportid == notify->portid)
13458 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013459
Johannes Berg53873f12016-05-03 16:52:04 +030013460 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013461 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013462
Johannes Berg78f22b62014-03-24 17:57:27 +010013463 if (wdev->owner_nlportid == notify->portid)
13464 schedule_destroy_work = true;
13465 }
13466
Ben Greear37c73b52012-10-26 14:49:25 -070013467 spin_lock_bh(&rdev->beacon_registrations_lock);
13468 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13469 list) {
13470 if (reg->nlportid == notify->portid) {
13471 list_del(&reg->list);
13472 kfree(reg);
13473 break;
13474 }
13475 }
13476 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013477
13478 if (schedule_destroy_work) {
13479 struct cfg80211_iface_destroy *destroy;
13480
13481 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13482 if (destroy) {
13483 destroy->nlportid = notify->portid;
13484 spin_lock(&rdev->destroy_list_lock);
13485 list_add(&destroy->list, &rdev->destroy_list);
13486 spin_unlock(&rdev->destroy_list_lock);
13487 schedule_work(&rdev->destroy_work);
13488 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013489 } else if (schedule_scan_stop) {
13490 sched_scan_req->owner_nlportid = 0;
13491
13492 if (rdev->ops->sched_scan_stop &&
13493 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13494 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013495 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013496 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013497
13498 rcu_read_unlock();
13499
Ilan peer05050752015-03-04 00:32:06 -050013500 /*
13501 * It is possible that the user space process that is controlling the
13502 * indoor setting disappeared, so notify the regulatory core.
13503 */
13504 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013505 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013506}
13507
13508static struct notifier_block nl80211_netlink_notifier = {
13509 .notifier_call = nl80211_netlink_notify,
13510};
13511
Jouni Malinen355199e2013-02-27 17:14:27 +020013512void cfg80211_ft_event(struct net_device *netdev,
13513 struct cfg80211_ft_event_params *ft_event)
13514{
13515 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013516 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013517 struct sk_buff *msg;
13518 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013519
13520 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13521
13522 if (!ft_event->target_ap)
13523 return;
13524
13525 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13526 if (!msg)
13527 return;
13528
13529 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013530 if (!hdr)
13531 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013532
Johannes Bergae917c92013-10-25 11:05:22 +020013533 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13534 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13535 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13536 goto out;
13537
13538 if (ft_event->ies &&
13539 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13540 goto out;
13541 if (ft_event->ric_ies &&
13542 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13543 ft_event->ric_ies))
13544 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013545
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013546 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013547
Johannes Berg68eb5502013-11-19 15:19:38 +010013548 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013549 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013550 return;
13551 out:
13552 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013553}
13554EXPORT_SYMBOL(cfg80211_ft_event);
13555
Arend van Spriel5de17982013-04-18 15:49:00 +020013556void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13557{
13558 struct cfg80211_registered_device *rdev;
13559 struct sk_buff *msg;
13560 void *hdr;
13561 u32 nlportid;
13562
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013563 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013564 if (!rdev->crit_proto_nlportid)
13565 return;
13566
13567 nlportid = rdev->crit_proto_nlportid;
13568 rdev->crit_proto_nlportid = 0;
13569
13570 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13571 if (!msg)
13572 return;
13573
13574 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13575 if (!hdr)
13576 goto nla_put_failure;
13577
13578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013579 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13580 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013581 goto nla_put_failure;
13582
13583 genlmsg_end(msg, hdr);
13584
13585 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13586 return;
13587
13588 nla_put_failure:
13589 if (hdr)
13590 genlmsg_cancel(msg, hdr);
13591 nlmsg_free(msg);
13592
13593}
13594EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13595
Johannes Berg348baf02014-01-24 14:06:29 +010013596void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13597{
13598 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013599 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013600 struct sk_buff *msg;
13601 void *hdr;
13602
13603 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13604 if (!msg)
13605 return;
13606
13607 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13608 if (!hdr)
13609 goto out;
13610
13611 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13612 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013613 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13614 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013615 goto out;
13616
13617 genlmsg_end(msg, hdr);
13618
13619 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13620 NL80211_MCGRP_MLME, GFP_KERNEL);
13621 return;
13622 out:
13623 nlmsg_free(msg);
13624}
13625
Johannes Berg55682962007-09-20 13:09:35 -040013626/* initialisation/exit functions */
13627
13628int nl80211_init(void)
13629{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013630 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013631
Johannes Berg2a94fe42013-11-19 15:19:39 +010013632 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13633 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013634 if (err)
13635 return err;
13636
Jouni Malinen026331c2010-02-15 12:53:10 +020013637 err = netlink_register_notifier(&nl80211_netlink_notifier);
13638 if (err)
13639 goto err_out;
13640
Johannes Berg55682962007-09-20 13:09:35 -040013641 return 0;
13642 err_out:
13643 genl_unregister_family(&nl80211_fam);
13644 return err;
13645}
13646
13647void nl80211_exit(void)
13648{
Jouni Malinen026331c2010-02-15 12:53:10 +020013649 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013650 genl_unregister_family(&nl80211_fam);
13651}