blob: afeb1ef1b1992a1fe2e4ff2772badeb1f7e83c24 [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 Berg89a54e42012-06-15 14:33:17 +0200106 list_for_each_entry(wdev, &rdev->wdev_list, list) {
107 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 Berg89a54e42012-06-15 14:33:17 +0200152 list_for_each_entry(wdev, &tmp->wdev_list, list) {
153 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 Berg97990a02013-04-19 01:02:55 +0200538 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
539 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;
1267 long split_start, band_start, chan_start;
1268 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
Johannes Berg3713b4e2013-02-14 16:19:38 +01001764 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001765 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001766 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001767 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001768 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001769 genlmsg_end(msg, hdr);
1770 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001771
1772 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001773 genlmsg_cancel(msg, hdr);
1774 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001775}
1776
Johannes Berg86e8cf92013-06-19 10:57:22 +02001777static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1778 struct netlink_callback *cb,
1779 struct nl80211_dump_wiphy_state *state)
1780{
1781 struct nlattr **tb = nl80211_fam.attrbuf;
1782 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1783 tb, nl80211_fam.maxattr, nl80211_policy);
1784 /* ignore parse errors for backward compatibility */
1785 if (ret)
1786 return 0;
1787
1788 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1789 if (tb[NL80211_ATTR_WIPHY])
1790 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1791 if (tb[NL80211_ATTR_WDEV])
1792 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1793 if (tb[NL80211_ATTR_IFINDEX]) {
1794 struct net_device *netdev;
1795 struct cfg80211_registered_device *rdev;
1796 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1797
Ying Xue7f2b8562014-01-15 10:23:45 +08001798 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001799 if (!netdev)
1800 return -ENODEV;
1801 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001802 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001803 netdev->ieee80211_ptr->wiphy);
1804 state->filter_wiphy = rdev->wiphy_idx;
1805 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806 }
1807
1808 return 0;
1809}
1810
Johannes Berg55682962007-09-20 13:09:35 -04001811static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1812{
Johannes Berg645e77d2013-03-01 14:03:49 +01001813 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001815 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001816
Johannes Berg5fe231e2013-05-08 21:45:15 +02001817 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 if (!state) {
1819 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001820 if (!state) {
1821 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001822 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001823 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001824 state->filter_wiphy = -1;
1825 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1826 if (ret) {
1827 kfree(state);
1828 rtnl_unlock();
1829 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001830 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001831 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001832 }
1833
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001834 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1835 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001836 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001837 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001838 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001839 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001840 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001841 continue;
1842 /* attempt to fit multiple wiphy data chunks into the skb */
1843 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001844 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1845 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001846 NETLINK_CB(cb->skb).portid,
1847 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001848 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001849 if (ret < 0) {
1850 /*
1851 * If sending the wiphy data didn't fit (ENOBUFS
1852 * or EMSGSIZE returned), this SKB is still
1853 * empty (so it's not too big because another
1854 * wiphy dataset is already in the skb) and
1855 * we've not tried to adjust the dump allocation
1856 * yet ... then adjust the alloc size to be
1857 * bigger, and return 1 but with the empty skb.
1858 * This results in an empty message being RX'ed
1859 * in userspace, but that is ignored.
1860 *
1861 * We can then retry with the larger buffer.
1862 */
1863 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001864 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001865 cb->min_dump_alloc < 4096) {
1866 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001867 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001868 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001869 return 1;
1870 }
1871 idx--;
1872 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001873 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001874 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001875 break;
Johannes Berg55682962007-09-20 13:09:35 -04001876 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001877 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001878
Johannes Berg86e8cf92013-06-19 10:57:22 +02001879 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001880
1881 return skb->len;
1882}
1883
Johannes Berg86e8cf92013-06-19 10:57:22 +02001884static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1885{
1886 kfree((void *)cb->args[0]);
1887 return 0;
1888}
1889
Johannes Berg55682962007-09-20 13:09:35 -04001890static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1891{
1892 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001894 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001895
Johannes Berg645e77d2013-03-01 14:03:49 +01001896 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001897 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001898 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001899
Johannes Berg3bb20552014-05-26 13:52:25 +02001900 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1901 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001902 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001903 nlmsg_free(msg);
1904 return -ENOBUFS;
1905 }
Johannes Berg55682962007-09-20 13:09:35 -04001906
Johannes Berg134e6372009-07-10 09:51:34 +00001907 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001908}
1909
Jouni Malinen31888482008-10-30 16:59:24 +02001910static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1911 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1912 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1913 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1914 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1915 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1916};
1917
1918static int parse_txq_params(struct nlattr *tb[],
1919 struct ieee80211_txq_params *txq_params)
1920{
Johannes Berga3304b02012-03-28 11:04:24 +02001921 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001922 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1923 !tb[NL80211_TXQ_ATTR_AIFS])
1924 return -EINVAL;
1925
Johannes Berga3304b02012-03-28 11:04:24 +02001926 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001927 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1928 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1929 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1930 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1931
Johannes Berga3304b02012-03-28 11:04:24 +02001932 if (txq_params->ac >= NL80211_NUM_ACS)
1933 return -EINVAL;
1934
Jouni Malinen31888482008-10-30 16:59:24 +02001935 return 0;
1936}
1937
Johannes Bergf444de02010-05-05 15:25:02 +02001938static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1939{
1940 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001941 * You can only set the channel explicitly for WDS interfaces,
1942 * all others have their channel managed via their respective
1943 * "establish a connection" command (connect, join, ...)
1944 *
1945 * For AP/GO and mesh mode, the channel can be set with the
1946 * channel userspace API, but is only stored and passed to the
1947 * low-level driver when the AP starts or the mesh is joined.
1948 * This is for backward compatibility, userspace can also give
1949 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001950 *
1951 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001952 * whatever else is going on, so they have their own special
1953 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001954 */
1955 return !wdev ||
1956 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001957 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001958 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1959 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001960}
1961
Johannes Berg683b6d32012-11-08 21:25:48 +01001962static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1963 struct genl_info *info,
1964 struct cfg80211_chan_def *chandef)
1965{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301966 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001967
1968 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1969 return -EINVAL;
1970
1971 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1972
1973 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001974 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1975 chandef->center_freq1 = control_freq;
1976 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001977
1978 /* Primary channel not allowed */
1979 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1980 return -EINVAL;
1981
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001982 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1983 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001984
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001985 chantype = nla_get_u32(
1986 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1987
1988 switch (chantype) {
1989 case NL80211_CHAN_NO_HT:
1990 case NL80211_CHAN_HT20:
1991 case NL80211_CHAN_HT40PLUS:
1992 case NL80211_CHAN_HT40MINUS:
1993 cfg80211_chandef_create(chandef, chandef->chan,
1994 chantype);
1995 break;
1996 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001997 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001998 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001999 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2000 chandef->width =
2001 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2002 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2003 chandef->center_freq1 =
2004 nla_get_u32(
2005 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2006 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2007 chandef->center_freq2 =
2008 nla_get_u32(
2009 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2010 }
2011
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002012 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002013 return -EINVAL;
2014
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002015 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2016 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002017 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002018
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002019 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2020 chandef->width == NL80211_CHAN_WIDTH_10) &&
2021 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2022 return -EINVAL;
2023
Johannes Berg683b6d32012-11-08 21:25:48 +01002024 return 0;
2025}
2026
Johannes Bergf444de02010-05-05 15:25:02 +02002027static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002028 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002029 struct genl_info *info)
2030{
Johannes Berg683b6d32012-11-08 21:25:48 +01002031 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002032 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002033 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002034 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002035
Jouni Malinene16821b2014-04-28 11:22:08 +03002036 if (dev)
2037 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002038 if (!nl80211_can_set_dev_channel(wdev))
2039 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002040 if (wdev)
2041 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002042
Johannes Berg683b6d32012-11-08 21:25:48 +01002043 result = nl80211_parse_chandef(rdev, info, &chandef);
2044 if (result)
2045 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002046
Johannes Berge8c9bd52012-06-06 08:18:22 +02002047 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002048 case NL80211_IFTYPE_AP:
2049 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002050 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2051 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002052 result = -EINVAL;
2053 break;
2054 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002055 if (wdev->beacon_interval) {
2056 if (!dev || !rdev->ops->set_ap_chanwidth ||
2057 !(rdev->wiphy.features &
2058 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2059 result = -EBUSY;
2060 break;
2061 }
2062
2063 /* Only allow dynamic channel width changes */
2064 if (chandef.chan != wdev->preset_chandef.chan) {
2065 result = -EBUSY;
2066 break;
2067 }
2068 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2069 if (result)
2070 break;
2071 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002072 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002073 result = 0;
2074 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002075 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002076 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002077 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002078 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002079 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002080 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002081 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002082 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002083 }
Johannes Bergf444de02010-05-05 15:25:02 +02002084
2085 return result;
2086}
2087
2088static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2089{
Johannes Berg4c476992010-10-04 21:36:35 +02002090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2091 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002092
Jouni Malinene16821b2014-04-28 11:22:08 +03002093 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002094}
2095
Bill Jordane8347eb2010-10-01 13:54:28 -04002096static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2097{
Johannes Berg43b19952010-10-07 13:10:30 +02002098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2099 struct net_device *dev = info->user_ptr[1];
2100 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002101 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002102
2103 if (!info->attrs[NL80211_ATTR_MAC])
2104 return -EINVAL;
2105
Johannes Berg43b19952010-10-07 13:10:30 +02002106 if (netif_running(dev))
2107 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002108
Johannes Berg43b19952010-10-07 13:10:30 +02002109 if (!rdev->ops->set_wds_peer)
2110 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002111
Johannes Berg43b19952010-10-07 13:10:30 +02002112 if (wdev->iftype != NL80211_IFTYPE_WDS)
2113 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002114
2115 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002116 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002117}
2118
2119
Johannes Berg55682962007-09-20 13:09:35 -04002120static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2121{
2122 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002123 struct net_device *netdev = NULL;
2124 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002125 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002126 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002127 u32 changed;
2128 u8 retry_short = 0, retry_long = 0;
2129 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002130 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002131
Johannes Berg5fe231e2013-05-08 21:45:15 +02002132 ASSERT_RTNL();
2133
Johannes Bergf444de02010-05-05 15:25:02 +02002134 /*
2135 * Try to find the wiphy and netdev. Normally this
2136 * function shouldn't need the netdev, but this is
2137 * done for backward compatibility -- previously
2138 * setting the channel was done per wiphy, but now
2139 * it is per netdev. Previous userland like hostapd
2140 * also passed a netdev to set_wiphy, so that it is
2141 * possible to let that go to the right netdev!
2142 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002143
Johannes Bergf444de02010-05-05 15:25:02 +02002144 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2145 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2146
Ying Xue7f2b8562014-01-15 10:23:45 +08002147 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002148 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002149 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002150 else
Johannes Bergf444de02010-05-05 15:25:02 +02002151 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002152 }
2153
Johannes Bergf444de02010-05-05 15:25:02 +02002154 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002155 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2156 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002157 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002158 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002159 wdev = NULL;
2160 netdev = NULL;
2161 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002162 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002163 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002164
2165 /*
2166 * end workaround code, by now the rdev is available
2167 * and locked, and wdev may or may not be NULL.
2168 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002169
2170 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002171 result = cfg80211_dev_rename(
2172 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002173
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002174 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002176
Jouni Malinen31888482008-10-30 16:59:24 +02002177 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2178 struct ieee80211_txq_params txq_params;
2179 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2180
Ying Xue7f2b8562014-01-15 10:23:45 +08002181 if (!rdev->ops->set_txq_params)
2182 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002183
Ying Xue7f2b8562014-01-15 10:23:45 +08002184 if (!netdev)
2185 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002186
Johannes Berg133a3ff2011-11-03 14:50:13 +01002187 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002188 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2189 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002190
Ying Xue7f2b8562014-01-15 10:23:45 +08002191 if (!netif_running(netdev))
2192 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002193
Jouni Malinen31888482008-10-30 16:59:24 +02002194 nla_for_each_nested(nl_txq_params,
2195 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2196 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002197 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2198 nla_data(nl_txq_params),
2199 nla_len(nl_txq_params),
2200 txq_params_policy);
2201 if (result)
2202 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002203 result = parse_txq_params(tb, &txq_params);
2204 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002205 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002206
Hila Gonene35e4d22012-06-27 17:19:42 +03002207 result = rdev_set_txq_params(rdev, netdev,
2208 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002209 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002211 }
2212 }
2213
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002214 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002215 result = __nl80211_set_channel(
2216 rdev,
2217 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2218 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002219 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002220 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002221 }
2222
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002223 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002224 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002225 enum nl80211_tx_power_setting type;
2226 int idx, mbm = 0;
2227
Johannes Bergc8442112012-10-24 10:17:18 +02002228 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2229 txp_wdev = NULL;
2230
Ying Xue7f2b8562014-01-15 10:23:45 +08002231 if (!rdev->ops->set_tx_power)
2232 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002233
2234 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2235 type = nla_get_u32(info->attrs[idx]);
2236
2237 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 (type != NL80211_TX_POWER_AUTOMATIC))
2239 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002240
2241 if (type != NL80211_TX_POWER_AUTOMATIC) {
2242 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2243 mbm = nla_get_u32(info->attrs[idx]);
2244 }
2245
Johannes Bergc8442112012-10-24 10:17:18 +02002246 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002247 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002248 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002249 }
2250
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002251 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2252 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2253 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002254 if ((!rdev->wiphy.available_antennas_tx &&
2255 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002256 !rdev->ops->set_antenna)
2257 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002258
2259 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2260 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2261
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002262 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002263 * available antenna masks, except for the "all" mask */
2264 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002265 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2266 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002267
Bruno Randolf7f531e02010-12-16 11:30:22 +09002268 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2269 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002270
Hila Gonene35e4d22012-06-27 17:19:42 +03002271 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002272 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002273 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002274 }
2275
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002276 changed = 0;
2277
2278 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2279 retry_short = nla_get_u8(
2280 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002281 if (retry_short == 0)
2282 return -EINVAL;
2283
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002284 changed |= WIPHY_PARAM_RETRY_SHORT;
2285 }
2286
2287 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2288 retry_long = nla_get_u8(
2289 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002290 if (retry_long == 0)
2291 return -EINVAL;
2292
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002293 changed |= WIPHY_PARAM_RETRY_LONG;
2294 }
2295
2296 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2297 frag_threshold = nla_get_u32(
2298 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002299 if (frag_threshold < 256)
2300 return -EINVAL;
2301
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002302 if (frag_threshold != (u32) -1) {
2303 /*
2304 * Fragments (apart from the last one) are required to
2305 * have even length. Make the fragmentation code
2306 * simpler by stripping LSB should someone try to use
2307 * odd threshold value.
2308 */
2309 frag_threshold &= ~0x1;
2310 }
2311 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2312 }
2313
2314 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2315 rts_threshold = nla_get_u32(
2316 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2317 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2318 }
2319
Lukáš Turek81077e82009-12-21 22:50:47 +01002320 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002321 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2322 return -EINVAL;
2323
Lukáš Turek81077e82009-12-21 22:50:47 +01002324 coverage_class = nla_get_u8(
2325 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2326 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2327 }
2328
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002329 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2330 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2331 return -EOPNOTSUPP;
2332
2333 changed |= WIPHY_PARAM_DYN_ACK;
2334 }
2335
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002336 if (changed) {
2337 u8 old_retry_short, old_retry_long;
2338 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002339 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002340
Ying Xue7f2b8562014-01-15 10:23:45 +08002341 if (!rdev->ops->set_wiphy_params)
2342 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002343
2344 old_retry_short = rdev->wiphy.retry_short;
2345 old_retry_long = rdev->wiphy.retry_long;
2346 old_frag_threshold = rdev->wiphy.frag_threshold;
2347 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002348 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002349
2350 if (changed & WIPHY_PARAM_RETRY_SHORT)
2351 rdev->wiphy.retry_short = retry_short;
2352 if (changed & WIPHY_PARAM_RETRY_LONG)
2353 rdev->wiphy.retry_long = retry_long;
2354 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2355 rdev->wiphy.frag_threshold = frag_threshold;
2356 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2357 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002358 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2359 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002360
Hila Gonene35e4d22012-06-27 17:19:42 +03002361 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002362 if (result) {
2363 rdev->wiphy.retry_short = old_retry_short;
2364 rdev->wiphy.retry_long = old_retry_long;
2365 rdev->wiphy.frag_threshold = old_frag_threshold;
2366 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002367 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002368 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002369 }
2370 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002371 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002372}
2373
Johannes Berg71bbc992012-06-15 15:30:18 +02002374static inline u64 wdev_id(struct wireless_dev *wdev)
2375{
2376 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002377 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002378}
Johannes Berg55682962007-09-20 13:09:35 -04002379
Johannes Berg683b6d32012-11-08 21:25:48 +01002380static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002381 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002382{
Johannes Berg601555c2014-11-27 17:26:56 +01002383 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2384 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002385
Johannes Berg683b6d32012-11-08 21:25:48 +01002386 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2387 chandef->chan->center_freq))
2388 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002389 switch (chandef->width) {
2390 case NL80211_CHAN_WIDTH_20_NOHT:
2391 case NL80211_CHAN_WIDTH_20:
2392 case NL80211_CHAN_WIDTH_40:
2393 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2394 cfg80211_get_chandef_type(chandef)))
2395 return -ENOBUFS;
2396 break;
2397 default:
2398 break;
2399 }
2400 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2401 return -ENOBUFS;
2402 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2403 return -ENOBUFS;
2404 if (chandef->center_freq2 &&
2405 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002406 return -ENOBUFS;
2407 return 0;
2408}
2409
Eric W. Biederman15e47302012-09-07 20:12:54 +00002410static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002411 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002412 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002413{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002414 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002415 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002416 void *hdr;
2417
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002418 if (removal)
2419 cmd = NL80211_CMD_DEL_INTERFACE;
2420
2421 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002422 if (!hdr)
2423 return -1;
2424
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002425 if (dev &&
2426 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002427 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002428 goto nla_put_failure;
2429
2430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2431 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002432 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2433 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002434 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002435 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2436 rdev->devlist_generation ^
2437 (cfg80211_rdev_list_generation << 2)))
2438 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002439
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002440 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002441 int ret;
2442 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002443
Johannes Berg683b6d32012-11-08 21:25:48 +01002444 ret = rdev_get_channel(rdev, wdev, &chandef);
2445 if (ret == 0) {
2446 if (nl80211_send_chandef(msg, &chandef))
2447 goto nla_put_failure;
2448 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002449 }
2450
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002451 if (rdev->ops->get_tx_power) {
2452 int dbm, ret;
2453
2454 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2455 if (ret == 0 &&
2456 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2457 DBM_TO_MBM(dbm)))
2458 goto nla_put_failure;
2459 }
2460
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002461 if (wdev->ssid_len) {
2462 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2463 goto nla_put_failure;
2464 }
2465
Johannes Berg053c0952015-01-16 22:09:00 +01002466 genlmsg_end(msg, hdr);
2467 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002468
2469 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002470 genlmsg_cancel(msg, hdr);
2471 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002472}
2473
2474static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2475{
2476 int wp_idx = 0;
2477 int if_idx = 0;
2478 int wp_start = cb->args[0];
2479 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002480 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002481 struct wireless_dev *wdev;
2482
Johannes Berg5fe231e2013-05-08 21:45:15 +02002483 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002484 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2485 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002486 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002487 if (wp_idx < wp_start) {
2488 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002489 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002490 }
Johannes Berg55682962007-09-20 13:09:35 -04002491 if_idx = 0;
2492
Johannes Berg89a54e42012-06-15 14:33:17 +02002493 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002494 if (if_idx < if_start) {
2495 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002496 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002497 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002498 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002499 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002500 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002501 goto out;
2502 }
2503 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002504 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002505
2506 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002507 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002508 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002509 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002510
2511 cb->args[0] = wp_idx;
2512 cb->args[1] = if_idx;
2513
2514 return skb->len;
2515}
2516
2517static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2518{
2519 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002521 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002522
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002524 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002525 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002526
Eric W. Biederman15e47302012-09-07 20:12:54 +00002527 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002528 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002529 nlmsg_free(msg);
2530 return -ENOBUFS;
2531 }
Johannes Berg55682962007-09-20 13:09:35 -04002532
Johannes Berg134e6372009-07-10 09:51:34 +00002533 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002534}
2535
Michael Wu66f7ac52008-01-31 19:48:22 +01002536static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2537 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2538 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2539 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2540 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2541 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002542 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002543};
2544
2545static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2546{
2547 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2548 int flag;
2549
2550 *mntrflags = 0;
2551
2552 if (!nla)
2553 return -EINVAL;
2554
2555 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2556 nla, mntr_flags_policy))
2557 return -EINVAL;
2558
2559 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2560 if (flags[flag])
2561 *mntrflags |= (1<<flag);
2562
2563 return 0;
2564}
2565
Johannes Berg9bc383d2009-11-19 11:55:19 +01002566static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002567 struct net_device *netdev, u8 use_4addr,
2568 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002569{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002570 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002571 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002572 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002573 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002574 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002575
2576 switch (iftype) {
2577 case NL80211_IFTYPE_AP_VLAN:
2578 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2579 return 0;
2580 break;
2581 case NL80211_IFTYPE_STATION:
2582 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2583 return 0;
2584 break;
2585 default:
2586 break;
2587 }
2588
2589 return -EOPNOTSUPP;
2590}
2591
Johannes Berg55682962007-09-20 13:09:35 -04002592static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2593{
Johannes Berg4c476992010-10-04 21:36:35 +02002594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002595 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002596 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002597 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002598 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002599 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002600 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002601
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002602 memset(&params, 0, sizeof(params));
2603
Johannes Berg04a773a2009-04-19 21:24:32 +02002604 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002605
Johannes Berg723b0382008-09-16 20:22:09 +02002606 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002607 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002608 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002609 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002610 if (ntype > NL80211_IFTYPE_MAX)
2611 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002612 }
2613
Johannes Berg92ffe052008-09-16 20:39:36 +02002614 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002615 struct wireless_dev *wdev = dev->ieee80211_ptr;
2616
Johannes Berg4c476992010-10-04 21:36:35 +02002617 if (ntype != NL80211_IFTYPE_MESH_POINT)
2618 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002619 if (netif_running(dev))
2620 return -EBUSY;
2621
2622 wdev_lock(wdev);
2623 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2624 IEEE80211_MAX_MESH_ID_LEN);
2625 wdev->mesh_id_up_len =
2626 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2627 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2628 wdev->mesh_id_up_len);
2629 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002630 }
2631
Felix Fietkau8b787642009-11-10 18:53:10 +01002632 if (info->attrs[NL80211_ATTR_4ADDR]) {
2633 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2634 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002635 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002636 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002637 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002638 } else {
2639 params.use_4addr = -1;
2640 }
2641
Johannes Berg92ffe052008-09-16 20:39:36 +02002642 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002643 if (ntype != NL80211_IFTYPE_MONITOR)
2644 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002645 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2646 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002647 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002648 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002649
2650 flags = &_flags;
2651 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002652 }
Johannes Berg3b858752009-03-12 09:55:09 +01002653
Luciano Coelho18003292013-08-29 13:26:57 +03002654 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002655 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2656 return -EOPNOTSUPP;
2657
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002658 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002659 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002660 else
2661 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002662
Johannes Berg9bc383d2009-11-19 11:55:19 +01002663 if (!err && params.use_4addr != -1)
2664 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2665
Johannes Berg55682962007-09-20 13:09:35 -04002666 return err;
2667}
2668
2669static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2670{
Johannes Berg4c476992010-10-04 21:36:35 +02002671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002672 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002673 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002674 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002675 int err;
2676 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002677 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002678
Johannes Berg78f22b62014-03-24 17:57:27 +01002679 /* to avoid failing a new interface creation due to pending removal */
2680 cfg80211_destroy_ifaces(rdev);
2681
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002682 memset(&params, 0, sizeof(params));
2683
Johannes Berg55682962007-09-20 13:09:35 -04002684 if (!info->attrs[NL80211_ATTR_IFNAME])
2685 return -EINVAL;
2686
2687 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2688 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2689 if (type > NL80211_IFTYPE_MAX)
2690 return -EINVAL;
2691 }
2692
Johannes Berg79c97e92009-07-07 03:56:12 +02002693 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002694 !(rdev->wiphy.interface_modes & (1 << type)))
2695 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002696
Ben Greeare8f479b2014-10-22 12:23:05 -07002697 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2698 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2699 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002700 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2701 ETH_ALEN);
2702 if (!is_valid_ether_addr(params.macaddr))
2703 return -EADDRNOTAVAIL;
2704 }
2705
Johannes Berg9bc383d2009-11-19 11:55:19 +01002706 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002707 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002708 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002709 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002710 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002711 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002712
Michael Wu66f7ac52008-01-31 19:48:22 +01002713 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2714 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2715 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002716
Luciano Coelho18003292013-08-29 13:26:57 +03002717 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002718 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2719 return -EOPNOTSUPP;
2720
Johannes Berga18c7192015-02-24 10:56:42 +01002721 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2722 if (!msg)
2723 return -ENOMEM;
2724
Hila Gonene35e4d22012-06-27 17:19:42 +03002725 wdev = rdev_add_virtual_intf(rdev,
2726 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002727 NET_NAME_USER, type, err ? NULL : &flags,
2728 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002729 if (WARN_ON(!wdev)) {
2730 nlmsg_free(msg);
2731 return -EPROTO;
2732 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002733 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002734 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002735 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002736
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002737 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002738 wdev->owner_nlportid = info->snd_portid;
2739
Johannes Berg98104fde2012-06-16 00:19:54 +02002740 switch (type) {
2741 case NL80211_IFTYPE_MESH_POINT:
2742 if (!info->attrs[NL80211_ATTR_MESH_ID])
2743 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002744 wdev_lock(wdev);
2745 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2746 IEEE80211_MAX_MESH_ID_LEN);
2747 wdev->mesh_id_up_len =
2748 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2749 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2750 wdev->mesh_id_up_len);
2751 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002752 break;
2753 case NL80211_IFTYPE_P2P_DEVICE:
2754 /*
2755 * P2P Device doesn't have a netdev, so doesn't go
2756 * through the netdev notifier and must be added here
2757 */
2758 mutex_init(&wdev->mtx);
2759 INIT_LIST_HEAD(&wdev->event_list);
2760 spin_lock_init(&wdev->event_lock);
2761 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2762 spin_lock_init(&wdev->mgmt_registrations_lock);
2763
Johannes Berg98104fde2012-06-16 00:19:54 +02002764 wdev->identifier = ++rdev->wdev_id;
2765 list_add_rcu(&wdev->list, &rdev->wdev_list);
2766 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002767 break;
2768 default:
2769 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002770 }
2771
Eric W. Biederman15e47302012-09-07 20:12:54 +00002772 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002773 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002774 nlmsg_free(msg);
2775 return -ENOBUFS;
2776 }
2777
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002778 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2779 if (event) {
2780 if (nl80211_send_iface(event, 0, 0, 0,
2781 rdev, wdev, false) < 0) {
2782 nlmsg_free(event);
2783 goto out;
2784 }
2785
2786 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2787 event, 0, NL80211_MCGRP_CONFIG,
2788 GFP_KERNEL);
2789 }
2790
2791out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002792 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002793}
2794
2795static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2796{
Johannes Berg4c476992010-10-04 21:36:35 +02002797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002798 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002799 struct sk_buff *msg;
2800 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002801
Johannes Berg4c476992010-10-04 21:36:35 +02002802 if (!rdev->ops->del_virtual_intf)
2803 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002804
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2806 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2807 nlmsg_free(msg);
2808 msg = NULL;
2809 }
2810
Johannes Berg84efbb82012-06-16 00:00:26 +02002811 /*
2812 * If we remove a wireless device without a netdev then clear
2813 * user_ptr[1] so that nl80211_post_doit won't dereference it
2814 * to check if it needs to do dev_put(). Otherwise it crashes
2815 * since the wdev has been freed, unlike with a netdev where
2816 * we need the dev_put() for the netdev to really be freed.
2817 */
2818 if (!wdev->netdev)
2819 info->user_ptr[1] = NULL;
2820
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002821 status = rdev_del_virtual_intf(rdev, wdev);
2822 if (status >= 0 && msg)
2823 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2824 msg, 0, NL80211_MCGRP_CONFIG,
2825 GFP_KERNEL);
2826 else
2827 nlmsg_free(msg);
2828
2829 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002830}
2831
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002832static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2833{
2834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2835 struct net_device *dev = info->user_ptr[1];
2836 u16 noack_map;
2837
2838 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2839 return -EINVAL;
2840
2841 if (!rdev->ops->set_noack_map)
2842 return -EOPNOTSUPP;
2843
2844 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2845
Hila Gonene35e4d22012-06-27 17:19:42 +03002846 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002847}
2848
Johannes Berg41ade002007-12-19 02:03:29 +01002849struct get_key_cookie {
2850 struct sk_buff *msg;
2851 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002852 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002853};
2854
2855static void get_key_callback(void *c, struct key_params *params)
2856{
Johannes Bergb9454e82009-07-08 13:29:08 +02002857 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002858 struct get_key_cookie *cookie = c;
2859
David S. Miller9360ffd2012-03-29 04:41:26 -04002860 if ((params->key &&
2861 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2862 params->key_len, params->key)) ||
2863 (params->seq &&
2864 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2865 params->seq_len, params->seq)) ||
2866 (params->cipher &&
2867 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2868 params->cipher)))
2869 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002870
Johannes Bergb9454e82009-07-08 13:29:08 +02002871 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2872 if (!key)
2873 goto nla_put_failure;
2874
David S. Miller9360ffd2012-03-29 04:41:26 -04002875 if ((params->key &&
2876 nla_put(cookie->msg, NL80211_KEY_DATA,
2877 params->key_len, params->key)) ||
2878 (params->seq &&
2879 nla_put(cookie->msg, NL80211_KEY_SEQ,
2880 params->seq_len, params->seq)) ||
2881 (params->cipher &&
2882 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2883 params->cipher)))
2884 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002885
David S. Miller9360ffd2012-03-29 04:41:26 -04002886 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2887 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002888
2889 nla_nest_end(cookie->msg, key);
2890
Johannes Berg41ade002007-12-19 02:03:29 +01002891 return;
2892 nla_put_failure:
2893 cookie->error = 1;
2894}
2895
2896static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2897{
Johannes Berg4c476992010-10-04 21:36:35 +02002898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002899 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002900 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002901 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002902 const u8 *mac_addr = NULL;
2903 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002904 struct get_key_cookie cookie = {
2905 .error = 0,
2906 };
2907 void *hdr;
2908 struct sk_buff *msg;
2909
2910 if (info->attrs[NL80211_ATTR_KEY_IDX])
2911 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2912
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002913 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return -EINVAL;
2915
2916 if (info->attrs[NL80211_ATTR_MAC])
2917 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2918
Johannes Berge31b8212010-10-05 19:39:30 +02002919 pairwise = !!mac_addr;
2920 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2921 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2922 if (kt >= NUM_NL80211_KEYTYPES)
2923 return -EINVAL;
2924 if (kt != NL80211_KEYTYPE_GROUP &&
2925 kt != NL80211_KEYTYPE_PAIRWISE)
2926 return -EINVAL;
2927 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2928 }
2929
Johannes Berg4c476992010-10-04 21:36:35 +02002930 if (!rdev->ops->get_key)
2931 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002932
Johannes Berg0fa7b392015-01-23 11:10:12 +01002933 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2934 return -ENOENT;
2935
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002936 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002937 if (!msg)
2938 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002939
Eric W. Biederman15e47302012-09-07 20:12:54 +00002940 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002941 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002942 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002943 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002944
2945 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002946 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002947
David S. Miller9360ffd2012-03-29 04:41:26 -04002948 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2949 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2950 goto nla_put_failure;
2951 if (mac_addr &&
2952 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2953 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002954
Hila Gonene35e4d22012-06-27 17:19:42 +03002955 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2956 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002957
2958 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002959 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002960
2961 if (cookie.error)
2962 goto nla_put_failure;
2963
2964 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002965 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002966
2967 nla_put_failure:
2968 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002969 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002970 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002971 return err;
2972}
2973
2974static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2975{
Johannes Berg4c476992010-10-04 21:36:35 +02002976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002977 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002978 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002979 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002980
Johannes Bergb9454e82009-07-08 13:29:08 +02002981 err = nl80211_parse_key(info, &key);
2982 if (err)
2983 return err;
2984
2985 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002986 return -EINVAL;
2987
Johannes Bergb9454e82009-07-08 13:29:08 +02002988 /* only support setting default key */
2989 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002990 return -EINVAL;
2991
Johannes Bergfffd0932009-07-08 14:22:54 +02002992 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002993
2994 if (key.def) {
2995 if (!rdev->ops->set_default_key) {
2996 err = -EOPNOTSUPP;
2997 goto out;
2998 }
2999
3000 err = nl80211_key_allowed(dev->ieee80211_ptr);
3001 if (err)
3002 goto out;
3003
Hila Gonene35e4d22012-06-27 17:19:42 +03003004 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003005 key.def_uni, key.def_multi);
3006
3007 if (err)
3008 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003009
Johannes Berg3d23e342009-09-29 23:27:28 +02003010#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003011 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003012#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003013 } else {
3014 if (key.def_uni || !key.def_multi) {
3015 err = -EINVAL;
3016 goto out;
3017 }
3018
3019 if (!rdev->ops->set_default_mgmt_key) {
3020 err = -EOPNOTSUPP;
3021 goto out;
3022 }
3023
3024 err = nl80211_key_allowed(dev->ieee80211_ptr);
3025 if (err)
3026 goto out;
3027
Hila Gonene35e4d22012-06-27 17:19:42 +03003028 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003029 if (err)
3030 goto out;
3031
3032#ifdef CONFIG_CFG80211_WEXT
3033 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3034#endif
3035 }
3036
3037 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003038 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003039
Johannes Berg41ade002007-12-19 02:03:29 +01003040 return err;
3041}
3042
3043static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3044{
Johannes Berg4c476992010-10-04 21:36:35 +02003045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003046 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003047 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003048 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003049 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003050
Johannes Bergb9454e82009-07-08 13:29:08 +02003051 err = nl80211_parse_key(info, &key);
3052 if (err)
3053 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003054
Johannes Bergb9454e82009-07-08 13:29:08 +02003055 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003056 return -EINVAL;
3057
Johannes Berg41ade002007-12-19 02:03:29 +01003058 if (info->attrs[NL80211_ATTR_MAC])
3059 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3060
Johannes Berge31b8212010-10-05 19:39:30 +02003061 if (key.type == -1) {
3062 if (mac_addr)
3063 key.type = NL80211_KEYTYPE_PAIRWISE;
3064 else
3065 key.type = NL80211_KEYTYPE_GROUP;
3066 }
3067
3068 /* for now */
3069 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3070 key.type != NL80211_KEYTYPE_GROUP)
3071 return -EINVAL;
3072
Johannes Berg4c476992010-10-04 21:36:35 +02003073 if (!rdev->ops->add_key)
3074 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003075
Johannes Berge31b8212010-10-05 19:39:30 +02003076 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3077 key.type == NL80211_KEYTYPE_PAIRWISE,
3078 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003079 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003080
3081 wdev_lock(dev->ieee80211_ptr);
3082 err = nl80211_key_allowed(dev->ieee80211_ptr);
3083 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003084 err = rdev_add_key(rdev, dev, key.idx,
3085 key.type == NL80211_KEYTYPE_PAIRWISE,
3086 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003087 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003088
Johannes Berg41ade002007-12-19 02:03:29 +01003089 return err;
3090}
3091
3092static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3093{
Johannes Berg4c476992010-10-04 21:36:35 +02003094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003095 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003096 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003097 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003098 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003099
Johannes Bergb9454e82009-07-08 13:29:08 +02003100 err = nl80211_parse_key(info, &key);
3101 if (err)
3102 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003103
3104 if (info->attrs[NL80211_ATTR_MAC])
3105 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3106
Johannes Berge31b8212010-10-05 19:39:30 +02003107 if (key.type == -1) {
3108 if (mac_addr)
3109 key.type = NL80211_KEYTYPE_PAIRWISE;
3110 else
3111 key.type = NL80211_KEYTYPE_GROUP;
3112 }
3113
3114 /* for now */
3115 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3116 key.type != NL80211_KEYTYPE_GROUP)
3117 return -EINVAL;
3118
Johannes Berg4c476992010-10-04 21:36:35 +02003119 if (!rdev->ops->del_key)
3120 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003121
Johannes Bergfffd0932009-07-08 14:22:54 +02003122 wdev_lock(dev->ieee80211_ptr);
3123 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003124
Johannes Berg0fa7b392015-01-23 11:10:12 +01003125 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003126 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3127 err = -ENOENT;
3128
Johannes Bergfffd0932009-07-08 14:22:54 +02003129 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003130 err = rdev_del_key(rdev, dev, key.idx,
3131 key.type == NL80211_KEYTYPE_PAIRWISE,
3132 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003133
Johannes Berg3d23e342009-09-29 23:27:28 +02003134#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003135 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003136 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003137 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003138 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003139 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3140 }
3141#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003142 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003143
Johannes Berg41ade002007-12-19 02:03:29 +01003144 return err;
3145}
3146
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303147/* This function returns an error or the number of nested attributes */
3148static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3149{
3150 struct nlattr *attr;
3151 int n_entries = 0, tmp;
3152
3153 nla_for_each_nested(attr, nl_attr, tmp) {
3154 if (nla_len(attr) != ETH_ALEN)
3155 return -EINVAL;
3156
3157 n_entries++;
3158 }
3159
3160 return n_entries;
3161}
3162
3163/*
3164 * This function parses ACL information and allocates memory for ACL data.
3165 * On successful return, the calling function is responsible to free the
3166 * ACL buffer returned by this function.
3167 */
3168static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3169 struct genl_info *info)
3170{
3171 enum nl80211_acl_policy acl_policy;
3172 struct nlattr *attr;
3173 struct cfg80211_acl_data *acl;
3174 int i = 0, n_entries, tmp;
3175
3176 if (!wiphy->max_acl_mac_addrs)
3177 return ERR_PTR(-EOPNOTSUPP);
3178
3179 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3180 return ERR_PTR(-EINVAL);
3181
3182 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3183 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3184 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3185 return ERR_PTR(-EINVAL);
3186
3187 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3188 return ERR_PTR(-EINVAL);
3189
3190 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3191 if (n_entries < 0)
3192 return ERR_PTR(n_entries);
3193
3194 if (n_entries > wiphy->max_acl_mac_addrs)
3195 return ERR_PTR(-ENOTSUPP);
3196
3197 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3198 GFP_KERNEL);
3199 if (!acl)
3200 return ERR_PTR(-ENOMEM);
3201
3202 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3203 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3204 i++;
3205 }
3206
3207 acl->n_acl_entries = n_entries;
3208 acl->acl_policy = acl_policy;
3209
3210 return acl;
3211}
3212
3213static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3214{
3215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3216 struct net_device *dev = info->user_ptr[1];
3217 struct cfg80211_acl_data *acl;
3218 int err;
3219
3220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3222 return -EOPNOTSUPP;
3223
3224 if (!dev->ieee80211_ptr->beacon_interval)
3225 return -EINVAL;
3226
3227 acl = parse_acl_data(&rdev->wiphy, info);
3228 if (IS_ERR(acl))
3229 return PTR_ERR(acl);
3230
3231 err = rdev_set_mac_acl(rdev, dev, acl);
3232
3233 kfree(acl);
3234
3235 return err;
3236}
3237
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003238static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003239 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003240{
Johannes Berg88600202012-02-13 15:17:18 +01003241 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003242
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003243 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3244 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3245 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3246 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003247 return -EINVAL;
3248
Johannes Berg88600202012-02-13 15:17:18 +01003249 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003250
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003251 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3252 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3253 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003254 if (!bcn->head_len)
3255 return -EINVAL;
3256 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003257 }
3258
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003259 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3260 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3261 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003262 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003263 }
3264
Johannes Berg4c476992010-10-04 21:36:35 +02003265 if (!haveinfo)
3266 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003267
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003268 if (attrs[NL80211_ATTR_IE]) {
3269 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3270 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003271 }
3272
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003273 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003274 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003275 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003276 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003277 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003278 }
3279
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003280 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003281 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003282 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003283 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003284 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003285 }
3286
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003287 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3288 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3289 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003290 }
3291
Johannes Berg88600202012-02-13 15:17:18 +01003292 return 0;
3293}
3294
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003295static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3296 struct cfg80211_ap_settings *params)
3297{
3298 struct wireless_dev *wdev;
3299 bool ret = false;
3300
Johannes Berg89a54e42012-06-15 14:33:17 +02003301 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003302 if (wdev->iftype != NL80211_IFTYPE_AP &&
3303 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3304 continue;
3305
Johannes Berg683b6d32012-11-08 21:25:48 +01003306 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003307 continue;
3308
Johannes Berg683b6d32012-11-08 21:25:48 +01003309 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003310 ret = true;
3311 break;
3312 }
3313
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003314 return ret;
3315}
3316
Jouni Malinene39e5b52012-09-30 19:29:39 +03003317static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3318 enum nl80211_auth_type auth_type,
3319 enum nl80211_commands cmd)
3320{
3321 if (auth_type > NL80211_AUTHTYPE_MAX)
3322 return false;
3323
3324 switch (cmd) {
3325 case NL80211_CMD_AUTHENTICATE:
3326 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3327 auth_type == NL80211_AUTHTYPE_SAE)
3328 return false;
3329 return true;
3330 case NL80211_CMD_CONNECT:
3331 case NL80211_CMD_START_AP:
3332 /* SAE not supported yet */
3333 if (auth_type == NL80211_AUTHTYPE_SAE)
3334 return false;
3335 return true;
3336 default:
3337 return false;
3338 }
3339}
3340
Johannes Berg88600202012-02-13 15:17:18 +01003341static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3342{
3343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3344 struct net_device *dev = info->user_ptr[1];
3345 struct wireless_dev *wdev = dev->ieee80211_ptr;
3346 struct cfg80211_ap_settings params;
3347 int err;
3348
3349 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3350 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3351 return -EOPNOTSUPP;
3352
3353 if (!rdev->ops->start_ap)
3354 return -EOPNOTSUPP;
3355
3356 if (wdev->beacon_interval)
3357 return -EALREADY;
3358
3359 memset(&params, 0, sizeof(params));
3360
3361 /* these are required for START_AP */
3362 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3363 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3364 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3365 return -EINVAL;
3366
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003367 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003368 if (err)
3369 return err;
3370
3371 params.beacon_interval =
3372 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3373 params.dtim_period =
3374 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3375
3376 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3377 if (err)
3378 return err;
3379
3380 /*
3381 * In theory, some of these attributes should be required here
3382 * but since they were not used when the command was originally
3383 * added, keep them optional for old user space programs to let
3384 * them continue to work with drivers that do not need the
3385 * additional information -- drivers must check!
3386 */
3387 if (info->attrs[NL80211_ATTR_SSID]) {
3388 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3389 params.ssid_len =
3390 nla_len(info->attrs[NL80211_ATTR_SSID]);
3391 if (params.ssid_len == 0 ||
3392 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3393 return -EINVAL;
3394 }
3395
3396 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3397 params.hidden_ssid = nla_get_u32(
3398 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3399 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3400 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3401 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3402 return -EINVAL;
3403 }
3404
3405 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3406
3407 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3408 params.auth_type = nla_get_u32(
3409 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003410 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3411 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003412 return -EINVAL;
3413 } else
3414 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3415
3416 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3417 NL80211_MAX_NR_CIPHER_SUITES);
3418 if (err)
3419 return err;
3420
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303421 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3422 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3423 return -EOPNOTSUPP;
3424 params.inactivity_timeout = nla_get_u16(
3425 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3426 }
3427
Johannes Berg53cabad2012-11-14 15:17:28 +01003428 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3429 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3430 return -EINVAL;
3431 params.p2p_ctwindow =
3432 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3433 if (params.p2p_ctwindow > 127)
3434 return -EINVAL;
3435 if (params.p2p_ctwindow != 0 &&
3436 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3437 return -EINVAL;
3438 }
3439
3440 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3441 u8 tmp;
3442
3443 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3444 return -EINVAL;
3445 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3446 if (tmp > 1)
3447 return -EINVAL;
3448 params.p2p_opp_ps = tmp;
3449 if (params.p2p_opp_ps != 0 &&
3450 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3451 return -EINVAL;
3452 }
3453
Johannes Bergaa430da2012-05-16 23:50:18 +02003454 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003455 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3456 if (err)
3457 return err;
3458 } else if (wdev->preset_chandef.chan) {
3459 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003460 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003461 return -EINVAL;
3462
Arik Nemtsov923b3522015-07-08 15:41:44 +03003463 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3464 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003465 return -EINVAL;
3466
Eliad Peller18998c32014-09-10 14:07:34 +03003467 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3468 params.smps_mode =
3469 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3470 switch (params.smps_mode) {
3471 case NL80211_SMPS_OFF:
3472 break;
3473 case NL80211_SMPS_STATIC:
3474 if (!(rdev->wiphy.features &
3475 NL80211_FEATURE_STATIC_SMPS))
3476 return -EINVAL;
3477 break;
3478 case NL80211_SMPS_DYNAMIC:
3479 if (!(rdev->wiphy.features &
3480 NL80211_FEATURE_DYNAMIC_SMPS))
3481 return -EINVAL;
3482 break;
3483 default:
3484 return -EINVAL;
3485 }
3486 } else {
3487 params.smps_mode = NL80211_SMPS_OFF;
3488 }
3489
Ola Olsson4baf6be2015-10-29 07:04:58 +01003490 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3491 params.acl = parse_acl_data(&rdev->wiphy, info);
3492 if (IS_ERR(params.acl))
3493 return PTR_ERR(params.acl);
3494 }
3495
Lior David34d50512016-01-28 10:58:25 +02003496 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02003497 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
Lior David34d50512016-01-28 10:58:25 +02003498 return -EOPNOTSUPP;
3499
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003500 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003501 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003502 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003503 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003504 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003505 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003506 wdev->ssid_len = params.ssid_len;
3507 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003508 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003509 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303510
3511 kfree(params.acl);
3512
Johannes Berg56d18932011-05-09 18:41:15 +02003513 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003514}
3515
Johannes Berg88600202012-02-13 15:17:18 +01003516static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3517{
3518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3519 struct net_device *dev = info->user_ptr[1];
3520 struct wireless_dev *wdev = dev->ieee80211_ptr;
3521 struct cfg80211_beacon_data params;
3522 int err;
3523
3524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3526 return -EOPNOTSUPP;
3527
3528 if (!rdev->ops->change_beacon)
3529 return -EOPNOTSUPP;
3530
3531 if (!wdev->beacon_interval)
3532 return -EINVAL;
3533
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003534 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003535 if (err)
3536 return err;
3537
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003538 wdev_lock(wdev);
3539 err = rdev_change_beacon(rdev, dev, &params);
3540 wdev_unlock(wdev);
3541
3542 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003543}
3544
3545static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003546{
Johannes Berg4c476992010-10-04 21:36:35 +02003547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3548 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003549
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003550 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003551}
3552
Johannes Berg5727ef12007-12-19 02:03:34 +01003553static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3554 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3555 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3556 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003557 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003558 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003559 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003560};
3561
Johannes Bergeccb8e82009-05-11 21:57:56 +03003562static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003563 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003564 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003565{
3566 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003567 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003568 int flag;
3569
Johannes Bergeccb8e82009-05-11 21:57:56 +03003570 /*
3571 * Try parsing the new attribute first so userspace
3572 * can specify both for older kernels.
3573 */
3574 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3575 if (nla) {
3576 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003577
Johannes Bergeccb8e82009-05-11 21:57:56 +03003578 sta_flags = nla_data(nla);
3579 params->sta_flags_mask = sta_flags->mask;
3580 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003581 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003582 if ((params->sta_flags_mask |
3583 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3584 return -EINVAL;
3585 return 0;
3586 }
3587
3588 /* if present, parse the old attribute */
3589
3590 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003591 if (!nla)
3592 return 0;
3593
3594 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3595 nla, sta_flags_policy))
3596 return -EINVAL;
3597
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003598 /*
3599 * Only allow certain flags for interface types so that
3600 * other attributes are silently ignored. Remember that
3601 * this is backward compatibility code with old userspace
3602 * and shouldn't be hit in other cases anyway.
3603 */
3604 switch (iftype) {
3605 case NL80211_IFTYPE_AP:
3606 case NL80211_IFTYPE_AP_VLAN:
3607 case NL80211_IFTYPE_P2P_GO:
3608 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3609 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3610 BIT(NL80211_STA_FLAG_WME) |
3611 BIT(NL80211_STA_FLAG_MFP);
3612 break;
3613 case NL80211_IFTYPE_P2P_CLIENT:
3614 case NL80211_IFTYPE_STATION:
3615 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3616 BIT(NL80211_STA_FLAG_TDLS_PEER);
3617 break;
3618 case NL80211_IFTYPE_MESH_POINT:
3619 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3620 BIT(NL80211_STA_FLAG_MFP) |
3621 BIT(NL80211_STA_FLAG_AUTHORIZED);
3622 default:
3623 return -EINVAL;
3624 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003625
Johannes Berg3383b5a2012-05-10 20:14:43 +02003626 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3627 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003628 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003629
Johannes Berg3383b5a2012-05-10 20:14:43 +02003630 /* no longer support new API additions in old API */
3631 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3632 return -EINVAL;
3633 }
3634 }
3635
Johannes Berg5727ef12007-12-19 02:03:34 +01003636 return 0;
3637}
3638
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003639static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3640 int attr)
3641{
3642 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003643 u32 bitrate;
3644 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003645 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003646
3647 rate = nla_nest_start(msg, attr);
3648 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003649 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003650
3651 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3652 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003653 /* report 16-bit bitrate only if we can */
3654 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003655 if (bitrate > 0 &&
3656 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3657 return false;
3658 if (bitrate_compat > 0 &&
3659 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3660 return false;
3661
Johannes Bergb51f3be2015-01-15 16:14:02 +01003662 switch (info->bw) {
3663 case RATE_INFO_BW_5:
3664 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3665 break;
3666 case RATE_INFO_BW_10:
3667 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3668 break;
3669 default:
3670 WARN_ON(1);
3671 /* fall through */
3672 case RATE_INFO_BW_20:
3673 rate_flg = 0;
3674 break;
3675 case RATE_INFO_BW_40:
3676 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3677 break;
3678 case RATE_INFO_BW_80:
3679 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3680 break;
3681 case RATE_INFO_BW_160:
3682 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3683 break;
3684 }
3685
3686 if (rate_flg && nla_put_flag(msg, rate_flg))
3687 return false;
3688
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003689 if (info->flags & RATE_INFO_FLAGS_MCS) {
3690 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3691 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003692 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3693 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3694 return false;
3695 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3696 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3697 return false;
3698 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3699 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003700 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3701 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3702 return false;
3703 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003704
3705 nla_nest_end(msg, rate);
3706 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003707}
3708
Felix Fietkau119363c2013-04-22 16:29:30 +02003709static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3710 int id)
3711{
3712 void *attr;
3713 int i = 0;
3714
3715 if (!mask)
3716 return true;
3717
3718 attr = nla_nest_start(msg, id);
3719 if (!attr)
3720 return false;
3721
3722 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3723 if (!(mask & BIT(i)))
3724 continue;
3725
3726 if (nla_put_u8(msg, i, signal[i]))
3727 return false;
3728 }
3729
3730 nla_nest_end(msg, attr);
3731
3732 return true;
3733}
3734
Johannes Bergcf5ead82014-11-14 17:14:00 +01003735static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3736 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003737 struct cfg80211_registered_device *rdev,
3738 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003739 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003740{
3741 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003742 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003743
Johannes Bergcf5ead82014-11-14 17:14:00 +01003744 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003745 if (!hdr)
3746 return -1;
3747
David S. Miller9360ffd2012-03-29 04:41:26 -04003748 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3750 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3751 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003752
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003753 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3754 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003755 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003756
3757#define PUT_SINFO(attr, memb, type) do { \
3758 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3759 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3760 sinfo->memb)) \
3761 goto nla_put_failure; \
3762 } while (0)
3763
3764 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3765 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3766
3767 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3768 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003769 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003770 (u32)sinfo->rx_bytes))
3771 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003772
3773 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3774 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003775 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3776 (u32)sinfo->tx_bytes))
3777 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003778
3779 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3780 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3781 PUT_SINFO(LLID, llid, u16);
3782 PUT_SINFO(PLID, plid, u16);
3783 PUT_SINFO(PLINK_STATE, plink_state, u8);
3784
John W. Linville66266b32012-03-15 13:25:41 -04003785 switch (rdev->wiphy.signal_type) {
3786 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003787 PUT_SINFO(SIGNAL, signal, u8);
3788 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003789 break;
3790 default:
3791 break;
3792 }
Johannes Berg319090b2014-11-17 14:08:11 +01003793 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003794 if (!nl80211_put_signal(msg, sinfo->chains,
3795 sinfo->chain_signal,
3796 NL80211_STA_INFO_CHAIN_SIGNAL))
3797 goto nla_put_failure;
3798 }
Johannes Berg319090b2014-11-17 14:08:11 +01003799 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003800 if (!nl80211_put_signal(msg, sinfo->chains,
3801 sinfo->chain_signal_avg,
3802 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3803 goto nla_put_failure;
3804 }
Johannes Berg319090b2014-11-17 14:08:11 +01003805 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003806 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3807 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003808 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003809 }
Johannes Berg319090b2014-11-17 14:08:11 +01003810 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003811 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3812 NL80211_STA_INFO_RX_BITRATE))
3813 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003814 }
Johannes Berg319090b2014-11-17 14:08:11 +01003815
3816 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3817 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3818 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3819 PUT_SINFO(TX_FAILED, tx_failed, u32);
3820 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3821 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3822 PUT_SINFO(LOCAL_PM, local_pm, u32);
3823 PUT_SINFO(PEER_PM, peer_pm, u32);
3824 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3825
3826 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003827 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3828 if (!bss_param)
3829 goto nla_put_failure;
3830
David S. Miller9360ffd2012-03-29 04:41:26 -04003831 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3832 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3833 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3834 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3835 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3836 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3837 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3838 sinfo->bss_param.dtim_period) ||
3839 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3840 sinfo->bss_param.beacon_interval))
3841 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003842
3843 nla_nest_end(msg, bss_param);
3844 }
Johannes Berg319090b2014-11-17 14:08:11 +01003845 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003846 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3847 sizeof(struct nl80211_sta_flag_update),
3848 &sinfo->sta_flags))
3849 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003850
3851 PUT_SINFO(T_OFFSET, t_offset, u64);
3852 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003853 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3854 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003855
3856#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003857
3858 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3859 struct nlattr *tidsattr;
3860 int tid;
3861
3862 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3863 if (!tidsattr)
3864 goto nla_put_failure;
3865
3866 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3867 struct cfg80211_tid_stats *tidstats;
3868 struct nlattr *tidattr;
3869
3870 tidstats = &sinfo->pertid[tid];
3871
3872 if (!tidstats->filled)
3873 continue;
3874
3875 tidattr = nla_nest_start(msg, tid + 1);
3876 if (!tidattr)
3877 goto nla_put_failure;
3878
3879#define PUT_TIDVAL(attr, memb, type) do { \
3880 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3881 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3882 tidstats->memb)) \
3883 goto nla_put_failure; \
3884 } while (0)
3885
3886 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3887 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3888 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3889 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3890
3891#undef PUT_TIDVAL
3892 nla_nest_end(msg, tidattr);
3893 }
3894
3895 nla_nest_end(msg, tidsattr);
3896 }
3897
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003898 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003899
Johannes Berg319090b2014-11-17 14:08:11 +01003900 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003901 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3902 sinfo->assoc_req_ies))
3903 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003904
Johannes Berg053c0952015-01-16 22:09:00 +01003905 genlmsg_end(msg, hdr);
3906 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003907
3908 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003909 genlmsg_cancel(msg, hdr);
3910 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003911}
3912
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003913static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003914 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003915{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003916 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003917 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003918 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003919 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003920 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003921 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003922
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003923 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003924 if (err)
3925 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003926
Johannes Berg97990a02013-04-19 01:02:55 +02003927 if (!wdev->netdev) {
3928 err = -EINVAL;
3929 goto out_err;
3930 }
3931
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003932 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003933 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003934 goto out_err;
3935 }
3936
Johannes Bergbba95fe2008-07-29 13:22:51 +02003937 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003938 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003939 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003940 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003941 if (err == -ENOENT)
3942 break;
3943 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003944 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003945
Johannes Bergcf5ead82014-11-14 17:14:00 +01003946 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003947 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003948 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003949 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003950 &sinfo) < 0)
3951 goto out;
3952
3953 sta_idx++;
3954 }
3955
3956
3957 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003958 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003959 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003960 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003961 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003962
3963 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003964}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003965
Johannes Berg5727ef12007-12-19 02:03:34 +01003966static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3967{
Johannes Berg4c476992010-10-04 21:36:35 +02003968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3969 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003970 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003971 struct sk_buff *msg;
3972 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003973 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003974
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003975 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003976
3977 if (!info->attrs[NL80211_ATTR_MAC])
3978 return -EINVAL;
3979
3980 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3981
Johannes Berg4c476992010-10-04 21:36:35 +02003982 if (!rdev->ops->get_station)
3983 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003984
Hila Gonene35e4d22012-06-27 17:19:42 +03003985 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003986 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003987 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003988
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003990 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003991 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003992
Johannes Bergcf5ead82014-11-14 17:14:00 +01003993 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3994 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003995 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003996 nlmsg_free(msg);
3997 return -ENOBUFS;
3998 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003999
Johannes Berg4c476992010-10-04 21:36:35 +02004000 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004001}
4002
Johannes Berg77ee7c82013-02-15 00:48:33 +01004003int cfg80211_check_station_change(struct wiphy *wiphy,
4004 struct station_parameters *params,
4005 enum cfg80211_station_type statype)
4006{
Ayala Bekere4208422015-10-23 11:20:06 +03004007 if (params->listen_interval != -1 &&
4008 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004009 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004010
Ayala Beker17b94242016-03-17 15:41:38 +02004011 if (params->support_p2p_ps != -1 &&
4012 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4013 return -EINVAL;
4014
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004015 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004016 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4017 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004018 return -EINVAL;
4019
4020 /* When you run into this, adjust the code below for the new flag */
4021 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4022
4023 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004024 case CFG80211_STA_MESH_PEER_KERNEL:
4025 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004026 /*
4027 * No ignoring the TDLS flag here -- the userspace mesh
4028 * code doesn't have the bug of including TDLS in the
4029 * mask everywhere.
4030 */
4031 if (params->sta_flags_mask &
4032 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4033 BIT(NL80211_STA_FLAG_MFP) |
4034 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4035 return -EINVAL;
4036 break;
4037 case CFG80211_STA_TDLS_PEER_SETUP:
4038 case CFG80211_STA_TDLS_PEER_ACTIVE:
4039 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4040 return -EINVAL;
4041 /* ignore since it can't change */
4042 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4043 break;
4044 default:
4045 /* disallow mesh-specific things */
4046 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4047 return -EINVAL;
4048 if (params->local_pm)
4049 return -EINVAL;
4050 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4051 return -EINVAL;
4052 }
4053
4054 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4055 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4056 /* TDLS can't be set, ... */
4057 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4058 return -EINVAL;
4059 /*
4060 * ... but don't bother the driver with it. This works around
4061 * a hostapd/wpa_supplicant issue -- it always includes the
4062 * TLDS_PEER flag in the mask even for AP mode.
4063 */
4064 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4065 }
4066
Ayala Beker47edb112015-09-21 15:49:53 +03004067 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4068 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004069 /* reject other things that can't change */
4070 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4071 return -EINVAL;
4072 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4073 return -EINVAL;
4074 if (params->supported_rates)
4075 return -EINVAL;
4076 if (params->ext_capab || params->ht_capa || params->vht_capa)
4077 return -EINVAL;
4078 }
4079
Ayala Beker47edb112015-09-21 15:49:53 +03004080 if (statype != CFG80211_STA_AP_CLIENT &&
4081 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004082 if (params->vlan)
4083 return -EINVAL;
4084 }
4085
4086 switch (statype) {
4087 case CFG80211_STA_AP_MLME_CLIENT:
4088 /* Use this only for authorizing/unauthorizing a station */
4089 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4090 return -EOPNOTSUPP;
4091 break;
4092 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004093 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004094 /* accept only the listed bits */
4095 if (params->sta_flags_mask &
4096 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4097 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4098 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4099 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4100 BIT(NL80211_STA_FLAG_WME) |
4101 BIT(NL80211_STA_FLAG_MFP)))
4102 return -EINVAL;
4103
4104 /* but authenticated/associated only if driver handles it */
4105 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4106 params->sta_flags_mask &
4107 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4108 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4109 return -EINVAL;
4110 break;
4111 case CFG80211_STA_IBSS:
4112 case CFG80211_STA_AP_STA:
4113 /* reject any changes other than AUTHORIZED */
4114 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4115 return -EINVAL;
4116 break;
4117 case CFG80211_STA_TDLS_PEER_SETUP:
4118 /* reject any changes other than AUTHORIZED or WME */
4119 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4120 BIT(NL80211_STA_FLAG_WME)))
4121 return -EINVAL;
4122 /* force (at least) rates when authorizing */
4123 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4124 !params->supported_rates)
4125 return -EINVAL;
4126 break;
4127 case CFG80211_STA_TDLS_PEER_ACTIVE:
4128 /* reject any changes */
4129 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004130 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004131 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4132 return -EINVAL;
4133 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004134 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004135 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4136 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004137 return -EINVAL;
4138 break;
4139 }
4140
4141 return 0;
4142}
4143EXPORT_SYMBOL(cfg80211_check_station_change);
4144
Johannes Berg5727ef12007-12-19 02:03:34 +01004145/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004146 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004147 */
Johannes Berg80b99892011-11-18 16:23:01 +01004148static struct net_device *get_vlan(struct genl_info *info,
4149 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004150{
Johannes Berg463d0182009-07-14 00:33:35 +02004151 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004152 struct net_device *v;
4153 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004154
Johannes Berg80b99892011-11-18 16:23:01 +01004155 if (!vlanattr)
4156 return NULL;
4157
4158 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4159 if (!v)
4160 return ERR_PTR(-ENODEV);
4161
4162 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4163 ret = -EINVAL;
4164 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004165 }
Johannes Berg80b99892011-11-18 16:23:01 +01004166
Johannes Berg77ee7c82013-02-15 00:48:33 +01004167 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4168 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4169 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4170 ret = -EINVAL;
4171 goto error;
4172 }
4173
Johannes Berg80b99892011-11-18 16:23:01 +01004174 if (!netif_running(v)) {
4175 ret = -ENETDOWN;
4176 goto error;
4177 }
4178
4179 return v;
4180 error:
4181 dev_put(v);
4182 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004183}
4184
Johannes Berg94e860f2014-01-20 23:58:15 +01004185static const struct nla_policy
4186nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004187 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4188 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4189};
4190
Johannes Bergff276692013-02-15 00:09:01 +01004191static int nl80211_parse_sta_wme(struct genl_info *info,
4192 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004193{
Jouni Malinendf881292013-02-14 21:10:54 +02004194 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4195 struct nlattr *nla;
4196 int err;
4197
Jouni Malinendf881292013-02-14 21:10:54 +02004198 /* parse WME attributes if present */
4199 if (!info->attrs[NL80211_ATTR_STA_WME])
4200 return 0;
4201
4202 nla = info->attrs[NL80211_ATTR_STA_WME];
4203 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4204 nl80211_sta_wme_policy);
4205 if (err)
4206 return err;
4207
4208 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4209 params->uapsd_queues = nla_get_u8(
4210 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4211 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4212 return -EINVAL;
4213
4214 if (tb[NL80211_STA_WME_MAX_SP])
4215 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4216
4217 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4218 return -EINVAL;
4219
4220 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4221
4222 return 0;
4223}
4224
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304225static int nl80211_parse_sta_channel_info(struct genl_info *info,
4226 struct station_parameters *params)
4227{
4228 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4229 params->supported_channels =
4230 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4231 params->supported_channels_len =
4232 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4233 /*
4234 * Need to include at least one (first channel, number of
4235 * channels) tuple for each subband, and must have proper
4236 * tuples for the rest of the data as well.
4237 */
4238 if (params->supported_channels_len < 2)
4239 return -EINVAL;
4240 if (params->supported_channels_len % 2)
4241 return -EINVAL;
4242 }
4243
4244 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4245 params->supported_oper_classes =
4246 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4247 params->supported_oper_classes_len =
4248 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4249 /*
4250 * The value of the Length field of the Supported Operating
4251 * Classes element is between 2 and 253.
4252 */
4253 if (params->supported_oper_classes_len < 2 ||
4254 params->supported_oper_classes_len > 253)
4255 return -EINVAL;
4256 }
4257 return 0;
4258}
4259
Johannes Bergff276692013-02-15 00:09:01 +01004260static int nl80211_set_station_tdls(struct genl_info *info,
4261 struct station_parameters *params)
4262{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304263 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004264 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004265 if (info->attrs[NL80211_ATTR_PEER_AID])
4266 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004267 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4268 params->ht_capa =
4269 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4270 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4271 params->vht_capa =
4272 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4273
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304274 err = nl80211_parse_sta_channel_info(info, params);
4275 if (err)
4276 return err;
4277
Johannes Bergff276692013-02-15 00:09:01 +01004278 return nl80211_parse_sta_wme(info, params);
4279}
4280
Johannes Berg5727ef12007-12-19 02:03:34 +01004281static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4282{
Johannes Berg4c476992010-10-04 21:36:35 +02004283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004284 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004285 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004286 u8 *mac_addr;
4287 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004288
4289 memset(&params, 0, sizeof(params));
4290
Johannes Berg77ee7c82013-02-15 00:48:33 +01004291 if (!rdev->ops->change_station)
4292 return -EOPNOTSUPP;
4293
Ayala Bekere4208422015-10-23 11:20:06 +03004294 /*
4295 * AID and listen_interval properties can be set only for unassociated
4296 * station. Include these parameters here and will check them in
4297 * cfg80211_check_station_change().
4298 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004299 if (info->attrs[NL80211_ATTR_STA_AID])
4300 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004301
4302 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4303 params.listen_interval =
4304 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4305 else
4306 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004307
Ayala Beker17b94242016-03-17 15:41:38 +02004308 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4309 u8 tmp;
4310
4311 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4312 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4313 return -EINVAL;
4314
4315 params.support_p2p_ps = tmp;
4316 } else {
4317 params.support_p2p_ps = -1;
4318 }
4319
Johannes Berg5727ef12007-12-19 02:03:34 +01004320 if (!info->attrs[NL80211_ATTR_MAC])
4321 return -EINVAL;
4322
4323 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4324
4325 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4326 params.supported_rates =
4327 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4328 params.supported_rates_len =
4329 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4330 }
4331
Jouni Malinen9d62a982013-02-14 21:10:13 +02004332 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4333 params.capability =
4334 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4335 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4336 }
4337
4338 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4339 params.ext_capab =
4340 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4341 params.ext_capab_len =
4342 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4343 }
4344
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004345 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004346 return -EINVAL;
4347
Johannes Bergf8bacc22013-02-14 23:27:01 +01004348 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004349 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004350 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4351 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4352 return -EINVAL;
4353 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004354
Johannes Bergf8bacc22013-02-14 23:27:01 +01004355 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004356 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004357 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4358 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4359 return -EINVAL;
4360 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4361 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004362
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004363 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4364 enum nl80211_mesh_power_mode pm = nla_get_u32(
4365 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4366
4367 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4368 pm > NL80211_MESH_POWER_MAX)
4369 return -EINVAL;
4370
4371 params.local_pm = pm;
4372 }
4373
Johannes Berg77ee7c82013-02-15 00:48:33 +01004374 /* Include parameters for TDLS peer (will check later) */
4375 err = nl80211_set_station_tdls(info, &params);
4376 if (err)
4377 return err;
4378
4379 params.vlan = get_vlan(info, rdev);
4380 if (IS_ERR(params.vlan))
4381 return PTR_ERR(params.vlan);
4382
Johannes Berga97f4422009-06-18 17:23:43 +02004383 switch (dev->ieee80211_ptr->iftype) {
4384 case NL80211_IFTYPE_AP:
4385 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004386 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004387 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004388 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004389 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004390 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004391 break;
4392 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004393 err = -EOPNOTSUPP;
4394 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004395 }
4396
Johannes Berg77ee7c82013-02-15 00:48:33 +01004397 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004398 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004399
Johannes Berg77ee7c82013-02-15 00:48:33 +01004400 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004401 if (params.vlan)
4402 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004403
Johannes Berg5727ef12007-12-19 02:03:34 +01004404 return err;
4405}
4406
4407static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4408{
Johannes Berg4c476992010-10-04 21:36:35 +02004409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004410 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004411 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004412 struct station_parameters params;
4413 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004414 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4415 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004416
4417 memset(&params, 0, sizeof(params));
4418
Johannes Berg984c3112013-02-14 23:43:25 +01004419 if (!rdev->ops->add_station)
4420 return -EOPNOTSUPP;
4421
Johannes Berg5727ef12007-12-19 02:03:34 +01004422 if (!info->attrs[NL80211_ATTR_MAC])
4423 return -EINVAL;
4424
Johannes Berg5727ef12007-12-19 02:03:34 +01004425 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4426 return -EINVAL;
4427
4428 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4429 return -EINVAL;
4430
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004431 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4432 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004433 return -EINVAL;
4434
Johannes Berg5727ef12007-12-19 02:03:34 +01004435 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4436 params.supported_rates =
4437 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4438 params.supported_rates_len =
4439 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4440 params.listen_interval =
4441 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004442
Ayala Beker17b94242016-03-17 15:41:38 +02004443 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4444 u8 tmp;
4445
4446 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4447 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4448 return -EINVAL;
4449
4450 params.support_p2p_ps = tmp;
4451 } else {
4452 /*
4453 * if not specified, assume it's supported for P2P GO interface,
4454 * and is NOT supported for AP interface
4455 */
4456 params.support_p2p_ps =
4457 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4458 }
4459
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004460 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004461 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004462 else
4463 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004464 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4465 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004466
Jouni Malinen9d62a982013-02-14 21:10:13 +02004467 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4468 params.capability =
4469 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4470 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4471 }
4472
4473 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4474 params.ext_capab =
4475 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4476 params.ext_capab_len =
4477 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4478 }
4479
Jouni Malinen36aedc902008-08-25 11:58:58 +03004480 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4481 params.ht_capa =
4482 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004483
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004484 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4485 params.vht_capa =
4486 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4487
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004488 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4489 params.opmode_notif_used = true;
4490 params.opmode_notif =
4491 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4492 }
4493
Johannes Bergf8bacc22013-02-14 23:27:01 +01004494 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004495 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004496 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4497 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4498 return -EINVAL;
4499 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004500
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304501 err = nl80211_parse_sta_channel_info(info, &params);
4502 if (err)
4503 return err;
4504
Johannes Bergff276692013-02-15 00:09:01 +01004505 err = nl80211_parse_sta_wme(info, &params);
4506 if (err)
4507 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004508
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004509 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004510 return -EINVAL;
4511
Johannes Berg496fcc22015-03-12 08:53:27 +02004512 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4513 * as userspace might just pass through the capabilities from the IEs
4514 * directly, rather than enforcing this restriction and returning an
4515 * error in this case.
4516 */
4517 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4518 params.ht_capa = NULL;
4519 params.vht_capa = NULL;
4520 }
4521
Johannes Berg77ee7c82013-02-15 00:48:33 +01004522 /* When you run into this, adjust the code below for the new flag */
4523 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4524
Johannes Bergbdd90d52011-12-14 12:20:27 +01004525 switch (dev->ieee80211_ptr->iftype) {
4526 case NL80211_IFTYPE_AP:
4527 case NL80211_IFTYPE_AP_VLAN:
4528 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004529 /* ignore WME attributes if iface/sta is not capable */
4530 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4531 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4532 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004533
Johannes Bergbdd90d52011-12-14 12:20:27 +01004534 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004535 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4536 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004537 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004538 /* but don't bother the driver with it */
4539 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004540
Johannes Bergd582cff2012-10-26 17:53:44 +02004541 /* allow authenticated/associated only if driver handles it */
4542 if (!(rdev->wiphy.features &
4543 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004544 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004545 return -EINVAL;
4546
Johannes Bergbda95eb2015-11-26 16:26:13 +01004547 /* Older userspace, or userspace wanting to be compatible with
4548 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4549 * and assoc flags in the mask, but assumes the station will be
4550 * added as associated anyway since this was the required driver
4551 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4552 * introduced.
4553 * In order to not bother drivers with this quirk in the API
4554 * set the flags in both the mask and set for new stations in
4555 * this case.
4556 */
4557 if (!(params.sta_flags_mask & auth_assoc)) {
4558 params.sta_flags_mask |= auth_assoc;
4559 params.sta_flags_set |= auth_assoc;
4560 }
4561
Johannes Bergbdd90d52011-12-14 12:20:27 +01004562 /* must be last in here for error handling */
4563 params.vlan = get_vlan(info, rdev);
4564 if (IS_ERR(params.vlan))
4565 return PTR_ERR(params.vlan);
4566 break;
4567 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004568 /* ignore uAPSD data */
4569 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4570
Johannes Bergd582cff2012-10-26 17:53:44 +02004571 /* associated is disallowed */
4572 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4573 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004574 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004575 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4576 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004577 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004578 break;
4579 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004580 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004581 /* ignore uAPSD data */
4582 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4583
Johannes Berg77ee7c82013-02-15 00:48:33 +01004584 /* these are disallowed */
4585 if (params.sta_flags_mask &
4586 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4587 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004588 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004589 /* Only TDLS peers can be added */
4590 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4591 return -EINVAL;
4592 /* Can only add if TDLS ... */
4593 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4594 return -EOPNOTSUPP;
4595 /* ... with external setup is supported */
4596 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4597 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004598 /*
4599 * Older wpa_supplicant versions always mark the TDLS peer
4600 * as authorized, but it shouldn't yet be.
4601 */
4602 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004603 break;
4604 default:
4605 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004606 }
4607
Johannes Bergbdd90d52011-12-14 12:20:27 +01004608 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004609
Hila Gonene35e4d22012-06-27 17:19:42 +03004610 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004611
Johannes Berg5727ef12007-12-19 02:03:34 +01004612 if (params.vlan)
4613 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004614 return err;
4615}
4616
4617static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4618{
Johannes Berg4c476992010-10-04 21:36:35 +02004619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4620 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004621 struct station_del_parameters params;
4622
4623 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004624
4625 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004626 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004627
Johannes Berge80cf852009-05-11 14:43:13 +02004628 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004629 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004630 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004631 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4632 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004633
Johannes Berg4c476992010-10-04 21:36:35 +02004634 if (!rdev->ops->del_station)
4635 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004636
Jouni Malinen98856862014-10-20 13:20:45 +03004637 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4638 params.subtype =
4639 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4640 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4641 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4642 return -EINVAL;
4643 } else {
4644 /* Default to Deauthentication frame */
4645 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4646 }
4647
4648 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4649 params.reason_code =
4650 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4651 if (params.reason_code == 0)
4652 return -EINVAL; /* 0 is reserved */
4653 } else {
4654 /* Default to reason code 2 */
4655 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4656 }
4657
Jouni Malinen89c771e2014-10-10 20:52:40 +03004658 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004659}
4660
Eric W. Biederman15e47302012-09-07 20:12:54 +00004661static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004662 int flags, struct net_device *dev,
4663 u8 *dst, u8 *next_hop,
4664 struct mpath_info *pinfo)
4665{
4666 void *hdr;
4667 struct nlattr *pinfoattr;
4668
Henning Rogge1ef4c852014-11-04 16:14:58 +01004669 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004670 if (!hdr)
4671 return -1;
4672
David S. Miller9360ffd2012-03-29 04:41:26 -04004673 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4674 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4675 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4676 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4677 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004678
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004679 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4680 if (!pinfoattr)
4681 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004682 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4683 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4684 pinfo->frame_qlen))
4685 goto nla_put_failure;
4686 if (((pinfo->filled & MPATH_INFO_SN) &&
4687 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4688 ((pinfo->filled & MPATH_INFO_METRIC) &&
4689 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4690 pinfo->metric)) ||
4691 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4692 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4693 pinfo->exptime)) ||
4694 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4695 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4696 pinfo->flags)) ||
4697 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4698 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4699 pinfo->discovery_timeout)) ||
4700 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4701 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4702 pinfo->discovery_retries)))
4703 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004704
4705 nla_nest_end(msg, pinfoattr);
4706
Johannes Berg053c0952015-01-16 22:09:00 +01004707 genlmsg_end(msg, hdr);
4708 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004709
4710 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004711 genlmsg_cancel(msg, hdr);
4712 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004713}
4714
4715static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004716 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004717{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004718 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004719 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004720 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004721 u8 dst[ETH_ALEN];
4722 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004723 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004724 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004725
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004726 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004727 if (err)
4728 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004729
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004730 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004731 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004732 goto out_err;
4733 }
4734
Johannes Berg97990a02013-04-19 01:02:55 +02004735 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004736 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004737 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004738 }
4739
Johannes Bergbba95fe2008-07-29 13:22:51 +02004740 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004741 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004742 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004743 if (err == -ENOENT)
4744 break;
4745 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004746 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004747
Eric W. Biederman15e47302012-09-07 20:12:54 +00004748 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004749 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004750 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004751 &pinfo) < 0)
4752 goto out;
4753
4754 path_idx++;
4755 }
4756
4757
4758 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004759 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004760 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004761 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004762 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004763 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004764}
4765
4766static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4767{
Johannes Berg4c476992010-10-04 21:36:35 +02004768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004769 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004770 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004771 struct mpath_info pinfo;
4772 struct sk_buff *msg;
4773 u8 *dst = NULL;
4774 u8 next_hop[ETH_ALEN];
4775
4776 memset(&pinfo, 0, sizeof(pinfo));
4777
4778 if (!info->attrs[NL80211_ATTR_MAC])
4779 return -EINVAL;
4780
4781 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4782
Johannes Berg4c476992010-10-04 21:36:35 +02004783 if (!rdev->ops->get_mpath)
4784 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004785
Johannes Berg4c476992010-10-04 21:36:35 +02004786 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4787 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004788
Hila Gonene35e4d22012-06-27 17:19:42 +03004789 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004790 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004791 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004792
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004793 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004794 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004795 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004796
Eric W. Biederman15e47302012-09-07 20:12:54 +00004797 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004798 dev, dst, next_hop, &pinfo) < 0) {
4799 nlmsg_free(msg);
4800 return -ENOBUFS;
4801 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004802
Johannes Berg4c476992010-10-04 21:36:35 +02004803 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004804}
4805
4806static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4807{
Johannes Berg4c476992010-10-04 21:36:35 +02004808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4809 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004810 u8 *dst = NULL;
4811 u8 *next_hop = NULL;
4812
4813 if (!info->attrs[NL80211_ATTR_MAC])
4814 return -EINVAL;
4815
4816 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4817 return -EINVAL;
4818
4819 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4820 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4821
Johannes Berg4c476992010-10-04 21:36:35 +02004822 if (!rdev->ops->change_mpath)
4823 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004824
Johannes Berg4c476992010-10-04 21:36:35 +02004825 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4826 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004827
Hila Gonene35e4d22012-06-27 17:19:42 +03004828 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004829}
Johannes Berg4c476992010-10-04 21:36:35 +02004830
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004831static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4832{
Johannes Berg4c476992010-10-04 21:36:35 +02004833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4834 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004835 u8 *dst = NULL;
4836 u8 *next_hop = NULL;
4837
4838 if (!info->attrs[NL80211_ATTR_MAC])
4839 return -EINVAL;
4840
4841 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4842 return -EINVAL;
4843
4844 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4845 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4846
Johannes Berg4c476992010-10-04 21:36:35 +02004847 if (!rdev->ops->add_mpath)
4848 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004849
Johannes Berg4c476992010-10-04 21:36:35 +02004850 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4851 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004852
Hila Gonene35e4d22012-06-27 17:19:42 +03004853 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004854}
4855
4856static int nl80211_del_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
4862 if (info->attrs[NL80211_ATTR_MAC])
4863 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4864
Johannes Berg4c476992010-10-04 21:36:35 +02004865 if (!rdev->ops->del_mpath)
4866 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004867
Hila Gonene35e4d22012-06-27 17:19:42 +03004868 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004869}
4870
Henning Rogge66be7d22014-09-12 08:58:49 +02004871static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4872{
4873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4874 int err;
4875 struct net_device *dev = info->user_ptr[1];
4876 struct mpath_info pinfo;
4877 struct sk_buff *msg;
4878 u8 *dst = NULL;
4879 u8 mpp[ETH_ALEN];
4880
4881 memset(&pinfo, 0, sizeof(pinfo));
4882
4883 if (!info->attrs[NL80211_ATTR_MAC])
4884 return -EINVAL;
4885
4886 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4887
4888 if (!rdev->ops->get_mpp)
4889 return -EOPNOTSUPP;
4890
4891 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4892 return -EOPNOTSUPP;
4893
4894 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4895 if (err)
4896 return err;
4897
4898 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4899 if (!msg)
4900 return -ENOMEM;
4901
4902 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4903 dev, dst, mpp, &pinfo) < 0) {
4904 nlmsg_free(msg);
4905 return -ENOBUFS;
4906 }
4907
4908 return genlmsg_reply(msg, info);
4909}
4910
4911static int nl80211_dump_mpp(struct sk_buff *skb,
4912 struct netlink_callback *cb)
4913{
4914 struct mpath_info pinfo;
4915 struct cfg80211_registered_device *rdev;
4916 struct wireless_dev *wdev;
4917 u8 dst[ETH_ALEN];
4918 u8 mpp[ETH_ALEN];
4919 int path_idx = cb->args[2];
4920 int err;
4921
4922 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4923 if (err)
4924 return err;
4925
4926 if (!rdev->ops->dump_mpp) {
4927 err = -EOPNOTSUPP;
4928 goto out_err;
4929 }
4930
4931 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4932 err = -EOPNOTSUPP;
4933 goto out_err;
4934 }
4935
4936 while (1) {
4937 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4938 mpp, &pinfo);
4939 if (err == -ENOENT)
4940 break;
4941 if (err)
4942 goto out_err;
4943
4944 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4945 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4946 wdev->netdev, dst, mpp,
4947 &pinfo) < 0)
4948 goto out;
4949
4950 path_idx++;
4951 }
4952
4953 out:
4954 cb->args[2] = path_idx;
4955 err = skb->len;
4956 out_err:
4957 nl80211_finish_wdev_dump(rdev);
4958 return err;
4959}
4960
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004961static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4962{
Johannes Berg4c476992010-10-04 21:36:35 +02004963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4964 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004965 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004966 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004967 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004968
4969 memset(&params, 0, sizeof(params));
4970 /* default to not changing parameters */
4971 params.use_cts_prot = -1;
4972 params.use_short_preamble = -1;
4973 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004974 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004975 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004976 params.p2p_ctwindow = -1;
4977 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004978
4979 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4980 params.use_cts_prot =
4981 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4982 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4983 params.use_short_preamble =
4984 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4985 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4986 params.use_short_slot_time =
4987 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004988 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4989 params.basic_rates =
4990 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4991 params.basic_rates_len =
4992 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4993 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004994 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4995 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004996 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4997 params.ht_opmode =
4998 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004999
Johannes Berg53cabad2012-11-14 15:17:28 +01005000 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5001 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5002 return -EINVAL;
5003 params.p2p_ctwindow =
5004 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5005 if (params.p2p_ctwindow < 0)
5006 return -EINVAL;
5007 if (params.p2p_ctwindow != 0 &&
5008 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5009 return -EINVAL;
5010 }
5011
5012 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5013 u8 tmp;
5014
5015 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5016 return -EINVAL;
5017 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5018 if (tmp > 1)
5019 return -EINVAL;
5020 params.p2p_opp_ps = tmp;
5021 if (params.p2p_opp_ps &&
5022 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5023 return -EINVAL;
5024 }
5025
Johannes Berg4c476992010-10-04 21:36:35 +02005026 if (!rdev->ops->change_bss)
5027 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005028
Johannes Berg074ac8d2010-09-16 14:58:22 +02005029 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005030 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5031 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005032
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005033 wdev_lock(wdev);
5034 err = rdev_change_bss(rdev, dev, &params);
5035 wdev_unlock(wdev);
5036
5037 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005038}
5039
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005040static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5041{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005042 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005043 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005044 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005045 u32 owner_nlportid;
5046
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005047
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005048 /*
5049 * You should only get this when cfg80211 hasn't yet initialized
5050 * completely when built-in to the kernel right between the time
5051 * window between nl80211_init() and regulatory_init(), if that is
5052 * even possible.
5053 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005054 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005055 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005056
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005057 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5058 user_reg_hint_type =
5059 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5060 else
5061 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5062
5063 switch (user_reg_hint_type) {
5064 case NL80211_USER_REG_HINT_USER:
5065 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005066 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5067 return -EINVAL;
5068
5069 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5070 return regulatory_hint_user(data, user_reg_hint_type);
5071 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005072 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5073 owner_nlportid = info->snd_portid;
5074 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5075 } else {
5076 owner_nlportid = 0;
5077 is_indoor = true;
5078 }
5079
5080 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005081 default:
5082 return -EINVAL;
5083 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005084}
5085
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005086static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005087 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005088{
Johannes Berg4c476992010-10-04 21:36:35 +02005089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005090 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005091 struct wireless_dev *wdev = dev->ieee80211_ptr;
5092 struct mesh_config cur_params;
5093 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005094 void *hdr;
5095 struct nlattr *pinfoattr;
5096 struct sk_buff *msg;
5097
Johannes Berg29cbe682010-12-03 09:20:44 +01005098 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5099 return -EOPNOTSUPP;
5100
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005101 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005102 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005103
Johannes Berg29cbe682010-12-03 09:20:44 +01005104 wdev_lock(wdev);
5105 /* If not connected, get default parameters */
5106 if (!wdev->mesh_id_len)
5107 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5108 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005109 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005110 wdev_unlock(wdev);
5111
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005112 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005113 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005114
5115 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005116 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005117 if (!msg)
5118 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005119 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005120 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005121 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005122 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005123 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005124 if (!pinfoattr)
5125 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005126 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5127 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5128 cur_params.dot11MeshRetryTimeout) ||
5129 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5130 cur_params.dot11MeshConfirmTimeout) ||
5131 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5132 cur_params.dot11MeshHoldingTimeout) ||
5133 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5134 cur_params.dot11MeshMaxPeerLinks) ||
5135 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5136 cur_params.dot11MeshMaxRetries) ||
5137 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5138 cur_params.dot11MeshTTL) ||
5139 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5140 cur_params.element_ttl) ||
5141 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5142 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005143 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5144 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005145 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5146 cur_params.dot11MeshHWMPmaxPREQretries) ||
5147 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5148 cur_params.path_refresh_time) ||
5149 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5150 cur_params.min_discovery_timeout) ||
5151 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5152 cur_params.dot11MeshHWMPactivePathTimeout) ||
5153 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5154 cur_params.dot11MeshHWMPpreqMinInterval) ||
5155 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5156 cur_params.dot11MeshHWMPperrMinInterval) ||
5157 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5158 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5159 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5160 cur_params.dot11MeshHWMPRootMode) ||
5161 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5162 cur_params.dot11MeshHWMPRannInterval) ||
5163 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5164 cur_params.dot11MeshGateAnnouncementProtocol) ||
5165 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5166 cur_params.dot11MeshForwarding) ||
5167 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005168 cur_params.rssi_threshold) ||
5169 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005170 cur_params.ht_opmode) ||
5171 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5172 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5173 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005174 cur_params.dot11MeshHWMProotInterval) ||
5175 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005176 cur_params.dot11MeshHWMPconfirmationInterval) ||
5177 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5178 cur_params.power_mode) ||
5179 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005180 cur_params.dot11MeshAwakeWindowDuration) ||
5181 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5182 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005183 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005184 nla_nest_end(msg, pinfoattr);
5185 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005186 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005187
Johannes Berg3b858752009-03-12 09:55:09 +01005188 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005189 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005190 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005191 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005192 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005193}
5194
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005195static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005196 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5197 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5198 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5199 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5200 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5201 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005202 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005203 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005204 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005205 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5206 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5207 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5208 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5209 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005210 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005211 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005212 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005213 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005214 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005215 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005216 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5217 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005218 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5219 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005220 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005221 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5222 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005223 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005224};
5225
Javier Cardonac80d5452010-12-16 17:37:49 -08005226static const struct nla_policy
5227 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005228 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005229 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5230 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005231 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005232 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005233 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005234 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005235 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005236 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005237};
5238
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005239static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005240 struct mesh_config *cfg,
5241 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005242{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005243 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005244 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005245
Marco Porschea54fba2013-01-07 16:04:48 +01005246#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5247do { \
5248 if (tb[attr]) { \
5249 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5250 return -EINVAL; \
5251 cfg->param = fn(tb[attr]); \
5252 mask |= (1 << (attr - 1)); \
5253 } \
5254} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005255
5256
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005257 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005258 return -EINVAL;
5259 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005260 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005261 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005262 return -EINVAL;
5263
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005264 /* This makes sure that there aren't more than 32 mesh config
5265 * parameters (otherwise our bitfield scheme would not work.) */
5266 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5267
5268 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005269 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005270 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5271 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005272 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005273 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5274 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005275 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005276 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5277 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005278 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005279 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5280 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005281 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005282 mask, NL80211_MESHCONF_MAX_RETRIES,
5283 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005284 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005285 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005286 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005287 mask, NL80211_MESHCONF_ELEMENT_TTL,
5288 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005289 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005290 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5291 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005292 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5293 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005294 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5295 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005296 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005297 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5298 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005299 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005300 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5301 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005302 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005303 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5304 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5306 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005307 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5308 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005309 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005310 1, 65535, mask,
5311 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005312 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005313 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005314 1, 65535, mask,
5315 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005316 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005317 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005318 dot11MeshHWMPnetDiameterTraversalTime,
5319 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005320 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5321 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005322 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5323 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5324 nla_get_u8);
5325 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5326 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005327 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005328 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005329 dot11MeshGateAnnouncementProtocol, 0, 1,
5330 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005331 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005332 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005333 mask, NL80211_MESHCONF_FORWARDING,
5334 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005335 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005336 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005337 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005338 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005339 mask, NL80211_MESHCONF_HT_OPMODE,
5340 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005341 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005342 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005343 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5344 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005345 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005346 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5347 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005348 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005349 dot11MeshHWMPconfirmationInterval,
5350 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005351 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5352 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005353 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5354 NL80211_MESH_POWER_ACTIVE,
5355 NL80211_MESH_POWER_MAX,
5356 mask, NL80211_MESHCONF_POWER_MODE,
5357 nla_get_u32);
5358 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5359 0, 65535, mask,
5360 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005361 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005362 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5363 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005364 if (mask_out)
5365 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005366
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005367 return 0;
5368
5369#undef FILL_IN_MESH_PARAM_IF_SET
5370}
5371
Javier Cardonac80d5452010-12-16 17:37:49 -08005372static int nl80211_parse_mesh_setup(struct genl_info *info,
5373 struct mesh_setup *setup)
5374{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005376 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5377
5378 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5379 return -EINVAL;
5380 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5381 info->attrs[NL80211_ATTR_MESH_SETUP],
5382 nl80211_mesh_setup_params_policy))
5383 return -EINVAL;
5384
Javier Cardonad299a1f2012-03-31 11:31:33 -07005385 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5386 setup->sync_method =
5387 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5388 IEEE80211_SYNC_METHOD_VENDOR :
5389 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5390
Javier Cardonac80d5452010-12-16 17:37:49 -08005391 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5392 setup->path_sel_proto =
5393 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5394 IEEE80211_PATH_PROTOCOL_VENDOR :
5395 IEEE80211_PATH_PROTOCOL_HWMP;
5396
5397 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5398 setup->path_metric =
5399 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5400 IEEE80211_PATH_METRIC_VENDOR :
5401 IEEE80211_PATH_METRIC_AIRTIME;
5402
Javier Cardona581a8b02011-04-07 15:08:27 -07005403
5404 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005405 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005406 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005407 if (!is_valid_ie_attr(ieattr))
5408 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005409 setup->ie = nla_data(ieattr);
5410 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005411 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005412 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5413 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5414 return -EINVAL;
5415 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005416 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5417 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005418 if (setup->is_secure)
5419 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005420
Colleen Twitty6e16d902013-05-08 11:45:59 -07005421 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5422 if (!setup->user_mpm)
5423 return -EINVAL;
5424 setup->auth_id =
5425 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5426 }
5427
Javier Cardonac80d5452010-12-16 17:37:49 -08005428 return 0;
5429}
5430
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005431static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005432 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005433{
5434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5435 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005436 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005437 struct mesh_config cfg;
5438 u32 mask;
5439 int err;
5440
Johannes Berg29cbe682010-12-03 09:20:44 +01005441 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5442 return -EOPNOTSUPP;
5443
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005444 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005445 return -EOPNOTSUPP;
5446
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005447 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005448 if (err)
5449 return err;
5450
Johannes Berg29cbe682010-12-03 09:20:44 +01005451 wdev_lock(wdev);
5452 if (!wdev->mesh_id_len)
5453 err = -ENOLINK;
5454
5455 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005456 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005457
5458 wdev_unlock(wdev);
5459
5460 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005461}
5462
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005463static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5464 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005465{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005466 struct nlattr *nl_reg_rules;
5467 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005468
Johannes Berg458f4f92012-12-06 15:47:38 +01005469 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5470 (regdom->dfs_region &&
5471 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005472 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005473
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005474 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5475 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005476 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005477
Johannes Berg458f4f92012-12-06 15:47:38 +01005478 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005479 struct nlattr *nl_reg_rule;
5480 const struct ieee80211_reg_rule *reg_rule;
5481 const struct ieee80211_freq_range *freq_range;
5482 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005483 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005484
Johannes Berg458f4f92012-12-06 15:47:38 +01005485 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005486 freq_range = &reg_rule->freq_range;
5487 power_rule = &reg_rule->power_rule;
5488
5489 nl_reg_rule = nla_nest_start(msg, i);
5490 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005491 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005492
Janusz Dziedzic97524822014-01-30 09:52:20 +01005493 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5494 if (!max_bandwidth_khz)
5495 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5496 reg_rule);
5497
David S. Miller9360ffd2012-03-29 04:41:26 -04005498 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5499 reg_rule->flags) ||
5500 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5501 freq_range->start_freq_khz) ||
5502 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5503 freq_range->end_freq_khz) ||
5504 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005505 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005506 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5507 power_rule->max_antenna_gain) ||
5508 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005509 power_rule->max_eirp) ||
5510 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5511 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005512 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005513
5514 nla_nest_end(msg, nl_reg_rule);
5515 }
5516
5517 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005518 return 0;
5519
5520nla_put_failure:
5521 return -EMSGSIZE;
5522}
5523
5524static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5525{
5526 const struct ieee80211_regdomain *regdom = NULL;
5527 struct cfg80211_registered_device *rdev;
5528 struct wiphy *wiphy = NULL;
5529 struct sk_buff *msg;
5530 void *hdr;
5531
5532 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5533 if (!msg)
5534 return -ENOBUFS;
5535
5536 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5537 NL80211_CMD_GET_REG);
5538 if (!hdr)
5539 goto put_failure;
5540
5541 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005542 bool self_managed;
5543
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005544 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5545 if (IS_ERR(rdev)) {
5546 nlmsg_free(msg);
5547 return PTR_ERR(rdev);
5548 }
5549
5550 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005551 self_managed = wiphy->regulatory_flags &
5552 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005553 regdom = get_wiphy_regdom(wiphy);
5554
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005555 /* a self-managed-reg device must have a private regdom */
5556 if (WARN_ON(!regdom && self_managed)) {
5557 nlmsg_free(msg);
5558 return -EINVAL;
5559 }
5560
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005561 if (regdom &&
5562 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5563 goto nla_put_failure;
5564 }
5565
5566 if (!wiphy && reg_last_request_cell_base() &&
5567 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5568 NL80211_USER_REG_HINT_CELL_BASE))
5569 goto nla_put_failure;
5570
5571 rcu_read_lock();
5572
5573 if (!regdom)
5574 regdom = rcu_dereference(cfg80211_regdomain);
5575
5576 if (nl80211_put_regdom(regdom, msg))
5577 goto nla_put_failure_rcu;
5578
5579 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005580
5581 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005582 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005583
Johannes Berg458f4f92012-12-06 15:47:38 +01005584nla_put_failure_rcu:
5585 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005586nla_put_failure:
5587 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005588put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005589 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005590 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005591}
5592
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005593static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5594 u32 seq, int flags, struct wiphy *wiphy,
5595 const struct ieee80211_regdomain *regdom)
5596{
5597 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5598 NL80211_CMD_GET_REG);
5599
5600 if (!hdr)
5601 return -1;
5602
5603 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5604
5605 if (nl80211_put_regdom(regdom, msg))
5606 goto nla_put_failure;
5607
5608 if (!wiphy && reg_last_request_cell_base() &&
5609 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5610 NL80211_USER_REG_HINT_CELL_BASE))
5611 goto nla_put_failure;
5612
5613 if (wiphy &&
5614 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5615 goto nla_put_failure;
5616
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005617 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5618 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5619 goto nla_put_failure;
5620
Johannes Berg053c0952015-01-16 22:09:00 +01005621 genlmsg_end(msg, hdr);
5622 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005623
5624nla_put_failure:
5625 genlmsg_cancel(msg, hdr);
5626 return -EMSGSIZE;
5627}
5628
5629static int nl80211_get_reg_dump(struct sk_buff *skb,
5630 struct netlink_callback *cb)
5631{
5632 const struct ieee80211_regdomain *regdom = NULL;
5633 struct cfg80211_registered_device *rdev;
5634 int err, reg_idx, start = cb->args[2];
5635
5636 rtnl_lock();
5637
5638 if (cfg80211_regdomain && start == 0) {
5639 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5640 NLM_F_MULTI, NULL,
5641 rtnl_dereference(cfg80211_regdomain));
5642 if (err < 0)
5643 goto out_err;
5644 }
5645
5646 /* the global regdom is idx 0 */
5647 reg_idx = 1;
5648 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5649 regdom = get_wiphy_regdom(&rdev->wiphy);
5650 if (!regdom)
5651 continue;
5652
5653 if (++reg_idx <= start)
5654 continue;
5655
5656 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5657 NLM_F_MULTI, &rdev->wiphy, regdom);
5658 if (err < 0) {
5659 reg_idx--;
5660 break;
5661 }
5662 }
5663
5664 cb->args[2] = reg_idx;
5665 err = skb->len;
5666out_err:
5667 rtnl_unlock();
5668 return err;
5669}
5670
Johannes Bergb6863032015-10-15 09:25:18 +02005671#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5672static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5673 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5674 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5675 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5676 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5677 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5678 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5679 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5680};
5681
5682static int parse_reg_rule(struct nlattr *tb[],
5683 struct ieee80211_reg_rule *reg_rule)
5684{
5685 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5686 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5687
5688 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5689 return -EINVAL;
5690 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5691 return -EINVAL;
5692 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5693 return -EINVAL;
5694 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5695 return -EINVAL;
5696 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5697 return -EINVAL;
5698
5699 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5700
5701 freq_range->start_freq_khz =
5702 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5703 freq_range->end_freq_khz =
5704 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5705 freq_range->max_bandwidth_khz =
5706 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5707
5708 power_rule->max_eirp =
5709 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5710
5711 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5712 power_rule->max_antenna_gain =
5713 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5714
5715 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5716 reg_rule->dfs_cac_ms =
5717 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5718
5719 return 0;
5720}
5721
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005722static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5723{
5724 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5725 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005726 char *alpha2;
5727 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005728 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005729 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005730 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005731
5732 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5733 return -EINVAL;
5734
5735 if (!info->attrs[NL80211_ATTR_REG_RULES])
5736 return -EINVAL;
5737
5738 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5739
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005740 if (info->attrs[NL80211_ATTR_DFS_REGION])
5741 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5742
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005743 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005744 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005745 num_rules++;
5746 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005747 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005748 }
5749
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005750 if (!reg_is_valid_request(alpha2))
5751 return -EINVAL;
5752
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005753 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005754 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005755
5756 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005757 if (!rd)
5758 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005759
5760 rd->n_reg_rules = num_rules;
5761 rd->alpha2[0] = alpha2[0];
5762 rd->alpha2[1] = alpha2[1];
5763
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005764 /*
5765 * Disable DFS master mode if the DFS region was
5766 * not supported or known on this kernel.
5767 */
5768 if (reg_supported_dfs_region(dfs_region))
5769 rd->dfs_region = dfs_region;
5770
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005771 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005772 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005773 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5774 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5775 reg_rule_policy);
5776 if (r)
5777 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005778 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5779 if (r)
5780 goto bad_reg;
5781
5782 rule_idx++;
5783
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005784 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5785 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005786 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005787 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005788 }
5789
Ilan peerc37722b2015-03-30 15:15:49 +03005790 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005791 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005792 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005793
Johannes Bergd2372b32008-10-24 20:32:20 +02005794 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005795 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005796 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005797}
Johannes Bergb6863032015-10-15 09:25:18 +02005798#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005799
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005800static int validate_scan_freqs(struct nlattr *freqs)
5801{
5802 struct nlattr *attr1, *attr2;
5803 int n_channels = 0, tmp1, tmp2;
5804
5805 nla_for_each_nested(attr1, freqs, tmp1) {
5806 n_channels++;
5807 /*
5808 * Some hardware has a limited channel list for
5809 * scanning, and it is pretty much nonsensical
5810 * to scan for a channel twice, so disallow that
5811 * and don't require drivers to check that the
5812 * channel list they get isn't longer than what
5813 * they can scan, as long as they can scan all
5814 * the channels they registered at once.
5815 */
5816 nla_for_each_nested(attr2, freqs, tmp2)
5817 if (attr1 != attr2 &&
5818 nla_get_u32(attr1) == nla_get_u32(attr2))
5819 return 0;
5820 }
5821
5822 return n_channels;
5823}
5824
Johannes Berg57fbcce2016-04-12 15:56:15 +02005825static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005826{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005827 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005828}
5829
5830static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5831 struct cfg80211_bss_selection *bss_select)
5832{
5833 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5834 struct nlattr *nest;
5835 int err;
5836 bool found = false;
5837 int i;
5838
5839 /* only process one nested attribute */
5840 nest = nla_data(nla);
5841 if (!nla_ok(nest, nla_len(nest)))
5842 return -EINVAL;
5843
5844 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5845 nla_len(nest), nl80211_bss_select_policy);
5846 if (err)
5847 return err;
5848
5849 /* only one attribute may be given */
5850 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
5851 if (attr[i]) {
5852 if (found)
5853 return -EINVAL;
5854 found = true;
5855 }
5856 }
5857
5858 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
5859
5860 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
5861 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
5862
5863 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
5864 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
5865 bss_select->param.band_pref =
5866 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
5867 if (!is_band_valid(wiphy, bss_select->param.band_pref))
5868 return -EINVAL;
5869 }
5870
5871 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
5872 struct nl80211_bss_select_rssi_adjust *adj_param;
5873
5874 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
5875 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
5876 bss_select->param.adjust.band = adj_param->band;
5877 bss_select->param.adjust.delta = adj_param->delta;
5878 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
5879 return -EINVAL;
5880 }
5881
5882 /* user-space did not provide behaviour attribute */
5883 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
5884 return -EINVAL;
5885
5886 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
5887 return -EINVAL;
5888
5889 return 0;
5890}
5891
Johannes Bergad2b26a2014-06-12 21:39:05 +02005892static int nl80211_parse_random_mac(struct nlattr **attrs,
5893 u8 *mac_addr, u8 *mac_addr_mask)
5894{
5895 int i;
5896
5897 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005898 eth_zero_addr(mac_addr);
5899 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005900 mac_addr[0] = 0x2;
5901 mac_addr_mask[0] = 0x3;
5902
5903 return 0;
5904 }
5905
5906 /* need both or none */
5907 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5908 return -EINVAL;
5909
5910 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5911 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5912
5913 /* don't allow or configure an mcast address */
5914 if (!is_multicast_ether_addr(mac_addr_mask) ||
5915 is_multicast_ether_addr(mac_addr))
5916 return -EINVAL;
5917
5918 /*
5919 * allow users to pass a MAC address that has bits set outside
5920 * of the mask, but don't bother drivers with having to deal
5921 * with such bits
5922 */
5923 for (i = 0; i < ETH_ALEN; i++)
5924 mac_addr[i] &= mac_addr_mask[i];
5925
5926 return 0;
5927}
5928
Johannes Berg2a519312009-02-10 21:25:55 +01005929static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5930{
Johannes Berg4c476992010-10-04 21:36:35 +02005931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005932 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005933 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005934 struct nlattr *attr;
5935 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005936 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005937 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005938
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005939 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5940 return -EINVAL;
5941
Johannes Berg79c97e92009-07-07 03:56:12 +02005942 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005943
Johannes Berg4c476992010-10-04 21:36:35 +02005944 if (!rdev->ops->scan)
5945 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005946
Johannes Bergf9d15d12014-01-22 11:14:19 +02005947 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005948 err = -EBUSY;
5949 goto unlock;
5950 }
Johannes Berg2a519312009-02-10 21:25:55 +01005951
5952 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005953 n_channels = validate_scan_freqs(
5954 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005955 if (!n_channels) {
5956 err = -EINVAL;
5957 goto unlock;
5958 }
Johannes Berg2a519312009-02-10 21:25:55 +01005959 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005960 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005961 }
5962
5963 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5964 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5965 n_ssids++;
5966
Johannes Bergf9f47522013-03-19 15:04:07 +01005967 if (n_ssids > wiphy->max_scan_ssids) {
5968 err = -EINVAL;
5969 goto unlock;
5970 }
Johannes Berg2a519312009-02-10 21:25:55 +01005971
Jouni Malinen70692ad2009-02-16 19:39:13 +02005972 if (info->attrs[NL80211_ATTR_IE])
5973 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5974 else
5975 ie_len = 0;
5976
Johannes Bergf9f47522013-03-19 15:04:07 +01005977 if (ie_len > wiphy->max_scan_ie_len) {
5978 err = -EINVAL;
5979 goto unlock;
5980 }
Johannes Berg18a83652009-03-31 12:12:05 +02005981
Johannes Berg2a519312009-02-10 21:25:55 +01005982 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005983 + sizeof(*request->ssids) * n_ssids
5984 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005985 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005986 if (!request) {
5987 err = -ENOMEM;
5988 goto unlock;
5989 }
Johannes Berg2a519312009-02-10 21:25:55 +01005990
Johannes Berg2a519312009-02-10 21:25:55 +01005991 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005992 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005993 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005994 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005995 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005996 request->ie = (void *)(request->ssids + n_ssids);
5997 else
5998 request->ie = (void *)(request->channels + n_channels);
5999 }
Johannes Berg2a519312009-02-10 21:25:55 +01006000
Johannes Berg584991d2009-11-02 13:32:03 +01006001 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006002 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6003 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006004 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006005 struct ieee80211_channel *chan;
6006
6007 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6008
6009 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006010 err = -EINVAL;
6011 goto out_free;
6012 }
Johannes Berg584991d2009-11-02 13:32:03 +01006013
6014 /* ignore disabled channels */
6015 if (chan->flags & IEEE80211_CHAN_DISABLED)
6016 continue;
6017
6018 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006019 i++;
6020 }
6021 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006022 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006023
Johannes Berg2a519312009-02-10 21:25:55 +01006024 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006025 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006026 int j;
6027 if (!wiphy->bands[band])
6028 continue;
6029 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006030 struct ieee80211_channel *chan;
6031
6032 chan = &wiphy->bands[band]->channels[j];
6033
6034 if (chan->flags & IEEE80211_CHAN_DISABLED)
6035 continue;
6036
6037 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006038 i++;
6039 }
6040 }
6041 }
6042
Johannes Berg584991d2009-11-02 13:32:03 +01006043 if (!i) {
6044 err = -EINVAL;
6045 goto out_free;
6046 }
6047
6048 request->n_channels = i;
6049
Johannes Berg2a519312009-02-10 21:25:55 +01006050 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006051 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006052 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006053 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006054 err = -EINVAL;
6055 goto out_free;
6056 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006057 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006058 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006059 i++;
6060 }
6061 }
6062
Jouni Malinen70692ad2009-02-16 19:39:13 +02006063 if (info->attrs[NL80211_ATTR_IE]) {
6064 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006065 memcpy((void *)request->ie,
6066 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006067 request->ie_len);
6068 }
6069
Johannes Berg57fbcce2016-04-12 15:56:15 +02006070 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006071 if (wiphy->bands[i])
6072 request->rates[i] =
6073 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006074
6075 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6076 nla_for_each_nested(attr,
6077 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6078 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006079 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006080
Johannes Berg57fbcce2016-04-12 15:56:15 +02006081 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006082 err = -EINVAL;
6083 goto out_free;
6084 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006085
6086 if (!wiphy->bands[band])
6087 continue;
6088
Johannes Berg34850ab2011-07-18 18:08:35 +02006089 err = ieee80211_get_ratemask(wiphy->bands[band],
6090 nla_data(attr),
6091 nla_len(attr),
6092 &request->rates[band]);
6093 if (err)
6094 goto out_free;
6095 }
6096 }
6097
Sam Leffler46856bb2012-10-11 21:03:32 -07006098 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006099 request->flags = nla_get_u32(
6100 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006101 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6102 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006103 err = -EOPNOTSUPP;
6104 goto out_free;
6105 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006106
6107 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6108 if (!(wiphy->features &
6109 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6110 err = -EOPNOTSUPP;
6111 goto out_free;
6112 }
6113
6114 if (wdev->current_bss) {
6115 err = -EOPNOTSUPP;
6116 goto out_free;
6117 }
6118
6119 err = nl80211_parse_random_mac(info->attrs,
6120 request->mac_addr,
6121 request->mac_addr_mask);
6122 if (err)
6123 goto out_free;
6124 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006125 }
Sam Lefflered4737712012-10-11 21:03:31 -07006126
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306127 request->no_cck =
6128 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6129
Jouni Malinen818965d2016-02-26 22:12:47 +02006130 if (info->attrs[NL80211_ATTR_MAC])
6131 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6132 ETH_ALEN);
6133 else
6134 eth_broadcast_addr(request->bssid);
6135
Johannes Bergfd014282012-06-18 19:17:03 +02006136 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006137 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006138 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006139
Johannes Berg79c97e92009-07-07 03:56:12 +02006140 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006141 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006142
Johannes Berg463d0182009-07-14 00:33:35 +02006143 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006144 nl80211_send_scan_start(rdev, wdev);
6145 if (wdev->netdev)
6146 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006147 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006148 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006149 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006150 kfree(request);
6151 }
Johannes Berg3b858752009-03-12 09:55:09 +01006152
Johannes Bergf9f47522013-03-19 15:04:07 +01006153 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006154 return err;
6155}
6156
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306157static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6158{
6159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6160 struct wireless_dev *wdev = info->user_ptr[1];
6161
6162 if (!rdev->ops->abort_scan)
6163 return -EOPNOTSUPP;
6164
6165 if (rdev->scan_msg)
6166 return 0;
6167
6168 if (!rdev->scan_req)
6169 return -ENOENT;
6170
6171 rdev_abort_scan(rdev, wdev);
6172 return 0;
6173}
6174
Avraham Stern3b06d272015-10-12 09:51:34 +03006175static int
6176nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6177 struct cfg80211_sched_scan_request *request,
6178 struct nlattr **attrs)
6179{
6180 int tmp, err, i = 0;
6181 struct nlattr *attr;
6182
6183 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6184 u32 interval;
6185
6186 /*
6187 * If scan plans are not specified,
6188 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6189 * case one scan plan will be set with the specified scan
6190 * interval and infinite number of iterations.
6191 */
6192 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6193 return -EINVAL;
6194
6195 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6196 if (!interval)
6197 return -EINVAL;
6198
6199 request->scan_plans[0].interval =
6200 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6201 if (!request->scan_plans[0].interval)
6202 return -EINVAL;
6203
6204 if (request->scan_plans[0].interval >
6205 wiphy->max_sched_scan_plan_interval)
6206 request->scan_plans[0].interval =
6207 wiphy->max_sched_scan_plan_interval;
6208
6209 return 0;
6210 }
6211
6212 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6213 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6214
6215 if (WARN_ON(i >= n_plans))
6216 return -EINVAL;
6217
6218 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6219 nla_data(attr), nla_len(attr),
6220 nl80211_plan_policy);
6221 if (err)
6222 return err;
6223
6224 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6225 return -EINVAL;
6226
6227 request->scan_plans[i].interval =
6228 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6229 if (!request->scan_plans[i].interval ||
6230 request->scan_plans[i].interval >
6231 wiphy->max_sched_scan_plan_interval)
6232 return -EINVAL;
6233
6234 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6235 request->scan_plans[i].iterations =
6236 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6237 if (!request->scan_plans[i].iterations ||
6238 (request->scan_plans[i].iterations >
6239 wiphy->max_sched_scan_plan_iterations))
6240 return -EINVAL;
6241 } else if (i < n_plans - 1) {
6242 /*
6243 * All scan plans but the last one must specify
6244 * a finite number of iterations
6245 */
6246 return -EINVAL;
6247 }
6248
6249 i++;
6250 }
6251
6252 /*
6253 * The last scan plan must not specify the number of
6254 * iterations, it is supposed to run infinitely
6255 */
6256 if (request->scan_plans[n_plans - 1].iterations)
6257 return -EINVAL;
6258
6259 return 0;
6260}
6261
Luciano Coelho256da022014-11-10 16:13:46 +02006262static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006263nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006264 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006265{
6266 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006267 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006268 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006269 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006270 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006271 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006272 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006273
Luciano Coelho256da022014-11-10 16:13:46 +02006274 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6275 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006276
Luciano Coelho256da022014-11-10 16:13:46 +02006277 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006278 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006279 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006280 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006281 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006282 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006283 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006284 }
6285
Luciano Coelho256da022014-11-10 16:13:46 +02006286 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6287 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006288 tmp)
6289 n_ssids++;
6290
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006291 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006292 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006293
Johannes Bergea73cbc2014-01-24 10:53:53 +01006294 /*
6295 * First, count the number of 'real' matchsets. Due to an issue with
6296 * the old implementation, matchsets containing only the RSSI attribute
6297 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6298 * RSSI for all matchsets, rather than their own matchset for reporting
6299 * all APs with a strong RSSI. This is needed to be compatible with
6300 * older userspace that treated a matchset with only the RSSI as the
6301 * global RSSI for all other matchsets - if there are other matchsets.
6302 */
Luciano Coelho256da022014-11-10 16:13:46 +02006303 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006304 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006305 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006306 tmp) {
6307 struct nlattr *rssi;
6308
6309 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6310 nla_data(attr), nla_len(attr),
6311 nl80211_match_policy);
6312 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006313 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006314 /* add other standalone attributes here */
6315 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6316 n_match_sets++;
6317 continue;
6318 }
6319 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6320 if (rssi)
6321 default_match_rssi = nla_get_s32(rssi);
6322 }
6323 }
6324
6325 /* However, if there's no other matchset, add the RSSI one */
6326 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6327 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006328
6329 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006330 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006331
Luciano Coelho256da022014-11-10 16:13:46 +02006332 if (attrs[NL80211_ATTR_IE])
6333 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006334 else
6335 ie_len = 0;
6336
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006337 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006338 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006339
Avraham Stern3b06d272015-10-12 09:51:34 +03006340 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6341 /*
6342 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6343 * each scan plan already specifies its own interval
6344 */
6345 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6346 return ERR_PTR(-EINVAL);
6347
6348 nla_for_each_nested(attr,
6349 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6350 n_plans++;
6351 } else {
6352 /*
6353 * The scan interval attribute is kept for backward
6354 * compatibility. If no scan plans are specified and sched scan
6355 * interval is specified, one scan plan will be set with this
6356 * scan interval and infinite number of iterations.
6357 */
6358 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6359 return ERR_PTR(-EINVAL);
6360
6361 n_plans = 1;
6362 }
6363
6364 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6365 return ERR_PTR(-EINVAL);
6366
Luciano Coelho807f8a82011-05-11 17:09:35 +03006367 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006368 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006369 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006370 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006371 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006372 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006373 if (!request)
6374 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006375
6376 if (n_ssids)
6377 request->ssids = (void *)&request->channels[n_channels];
6378 request->n_ssids = n_ssids;
6379 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006380 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006381 request->ie = (void *)(request->ssids + n_ssids);
6382 else
6383 request->ie = (void *)(request->channels + n_channels);
6384 }
6385
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006386 if (n_match_sets) {
6387 if (request->ie)
6388 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006389 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006390 request->match_sets =
6391 (void *)(request->ssids + n_ssids);
6392 else
6393 request->match_sets =
6394 (void *)(request->channels + n_channels);
6395 }
6396 request->n_match_sets = n_match_sets;
6397
Avraham Stern3b06d272015-10-12 09:51:34 +03006398 if (n_match_sets)
6399 request->scan_plans = (void *)(request->match_sets +
6400 n_match_sets);
6401 else if (request->ie)
6402 request->scan_plans = (void *)(request->ie + ie_len);
6403 else if (n_ssids)
6404 request->scan_plans = (void *)(request->ssids + n_ssids);
6405 else
6406 request->scan_plans = (void *)(request->channels + n_channels);
6407
6408 request->n_scan_plans = n_plans;
6409
Luciano Coelho807f8a82011-05-11 17:09:35 +03006410 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006411 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006412 /* user specified, bail out if channel not found */
6413 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006414 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006415 tmp) {
6416 struct ieee80211_channel *chan;
6417
6418 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6419
6420 if (!chan) {
6421 err = -EINVAL;
6422 goto out_free;
6423 }
6424
6425 /* ignore disabled channels */
6426 if (chan->flags & IEEE80211_CHAN_DISABLED)
6427 continue;
6428
6429 request->channels[i] = chan;
6430 i++;
6431 }
6432 } else {
6433 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006434 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006435 int j;
6436 if (!wiphy->bands[band])
6437 continue;
6438 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6439 struct ieee80211_channel *chan;
6440
6441 chan = &wiphy->bands[band]->channels[j];
6442
6443 if (chan->flags & IEEE80211_CHAN_DISABLED)
6444 continue;
6445
6446 request->channels[i] = chan;
6447 i++;
6448 }
6449 }
6450 }
6451
6452 if (!i) {
6453 err = -EINVAL;
6454 goto out_free;
6455 }
6456
6457 request->n_channels = i;
6458
6459 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006460 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006461 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006462 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006463 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006464 err = -EINVAL;
6465 goto out_free;
6466 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006467 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006468 memcpy(request->ssids[i].ssid, nla_data(attr),
6469 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006470 i++;
6471 }
6472 }
6473
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006474 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006475 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006476 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006477 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006478 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006479 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006480
Johannes Bergae811e22014-01-24 10:17:47 +01006481 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6482 nla_data(attr), nla_len(attr),
6483 nl80211_match_policy);
6484 if (err)
6485 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006486 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006487 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006488 if (WARN_ON(i >= n_match_sets)) {
6489 /* this indicates a programming error,
6490 * the loop above should have verified
6491 * things properly
6492 */
6493 err = -EINVAL;
6494 goto out_free;
6495 }
6496
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006497 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6498 err = -EINVAL;
6499 goto out_free;
6500 }
6501 memcpy(request->match_sets[i].ssid.ssid,
6502 nla_data(ssid), nla_len(ssid));
6503 request->match_sets[i].ssid.ssid_len =
6504 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006505 /* special attribute - old implemenation w/a */
6506 request->match_sets[i].rssi_thold =
6507 default_match_rssi;
6508 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6509 if (rssi)
6510 request->match_sets[i].rssi_thold =
6511 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006512 }
6513 i++;
6514 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006515
6516 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006517 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006518 request->match_sets[0].rssi_thold = default_match_rssi;
6519
6520 request->min_rssi_thold = INT_MAX;
6521 for (i = 0; i < n_match_sets; i++)
6522 request->min_rssi_thold =
6523 min(request->match_sets[i].rssi_thold,
6524 request->min_rssi_thold);
6525 } else {
6526 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006527 }
6528
Johannes Berg9900e482014-02-04 21:01:25 +01006529 if (ie_len) {
6530 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006531 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006532 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006533 request->ie_len);
6534 }
6535
Luciano Coelho256da022014-11-10 16:13:46 +02006536 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006537 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006538 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006539 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6540 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006541 err = -EOPNOTSUPP;
6542 goto out_free;
6543 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006544
6545 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6546 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6547
6548 if (!wdev) /* must be net-detect */
6549 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6550
6551 if (!(wiphy->features & flg)) {
6552 err = -EOPNOTSUPP;
6553 goto out_free;
6554 }
6555
6556 if (wdev && wdev->current_bss) {
6557 err = -EOPNOTSUPP;
6558 goto out_free;
6559 }
6560
6561 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6562 request->mac_addr_mask);
6563 if (err)
6564 goto out_free;
6565 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006566 }
Sam Lefflered4737712012-10-11 21:03:31 -07006567
Luciano Coelho9c748932015-01-16 16:04:09 +02006568 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6569 request->delay =
6570 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6571
Avraham Stern3b06d272015-10-12 09:51:34 +03006572 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6573 if (err)
6574 goto out_free;
6575
Sam Leffler15d60302012-10-11 21:03:34 -07006576 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006577
Luciano Coelho256da022014-11-10 16:13:46 +02006578 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006579
6580out_free:
6581 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006582 return ERR_PTR(err);
6583}
6584
6585static int nl80211_start_sched_scan(struct sk_buff *skb,
6586 struct genl_info *info)
6587{
6588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6589 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006590 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006591 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006592 int err;
6593
6594 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6595 !rdev->ops->sched_scan_start)
6596 return -EOPNOTSUPP;
6597
6598 if (rdev->sched_scan_req)
6599 return -EINPROGRESS;
6600
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006601 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6602 info->attrs);
6603
6604 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006605 if (err)
6606 goto out_err;
6607
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006608 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006609 if (err)
6610 goto out_free;
6611
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006612 sched_scan_req->dev = dev;
6613 sched_scan_req->wiphy = &rdev->wiphy;
6614
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006615 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6616 sched_scan_req->owner_nlportid = info->snd_portid;
6617
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006618 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006619
6620 nl80211_send_sched_scan(rdev, dev,
6621 NL80211_CMD_START_SCHED_SCAN);
6622 return 0;
6623
6624out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006625 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006626out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006627 return err;
6628}
6629
6630static int nl80211_stop_sched_scan(struct sk_buff *skb,
6631 struct genl_info *info)
6632{
6633 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6634
6635 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6636 !rdev->ops->sched_scan_stop)
6637 return -EOPNOTSUPP;
6638
Johannes Berg5fe231e2013-05-08 21:45:15 +02006639 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006640}
6641
Simon Wunderlich04f39042013-02-08 18:16:19 +01006642static int nl80211_start_radar_detection(struct sk_buff *skb,
6643 struct genl_info *info)
6644{
6645 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6646 struct net_device *dev = info->user_ptr[1];
6647 struct wireless_dev *wdev = dev->ieee80211_ptr;
6648 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006649 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006650 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006651 int err;
6652
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006653 dfs_region = reg_get_dfs_region(wdev->wiphy);
6654 if (dfs_region == NL80211_DFS_UNSET)
6655 return -EINVAL;
6656
Simon Wunderlich04f39042013-02-08 18:16:19 +01006657 err = nl80211_parse_chandef(rdev, info, &chandef);
6658 if (err)
6659 return err;
6660
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006661 if (netif_carrier_ok(dev))
6662 return -EBUSY;
6663
Simon Wunderlich04f39042013-02-08 18:16:19 +01006664 if (wdev->cac_started)
6665 return -EBUSY;
6666
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006667 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006668 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006669 if (err < 0)
6670 return err;
6671
6672 if (err == 0)
6673 return -EINVAL;
6674
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006675 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006676 return -EINVAL;
6677
6678 if (!rdev->ops->start_radar_detection)
6679 return -EOPNOTSUPP;
6680
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006681 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6682 if (WARN_ON(!cac_time_ms))
6683 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6684
Ilan Peera1056b12015-10-22 22:27:46 +03006685 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006686 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006687 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006688 wdev->cac_started = true;
6689 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006690 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006691 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006692 return err;
6693}
6694
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006695static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6696{
6697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6698 struct net_device *dev = info->user_ptr[1];
6699 struct wireless_dev *wdev = dev->ieee80211_ptr;
6700 struct cfg80211_csa_settings params;
6701 /* csa_attrs is defined static to avoid waste of stack size - this
6702 * function is called under RTNL lock, so this should not be a problem.
6703 */
6704 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006705 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006706 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006707 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006708 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006709
6710 if (!rdev->ops->channel_switch ||
6711 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6712 return -EOPNOTSUPP;
6713
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006714 switch (dev->ieee80211_ptr->iftype) {
6715 case NL80211_IFTYPE_AP:
6716 case NL80211_IFTYPE_P2P_GO:
6717 need_new_beacon = true;
6718
6719 /* useless if AP is not running */
6720 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006721 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006722 break;
6723 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006724 if (!wdev->ssid_len)
6725 return -ENOTCONN;
6726 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006727 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006728 if (!wdev->mesh_id_len)
6729 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006730 break;
6731 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006732 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006733 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006734
6735 memset(&params, 0, sizeof(params));
6736
6737 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6738 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6739 return -EINVAL;
6740
6741 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006742 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006743 return -EINVAL;
6744
Luciano Coelho252e07c2014-10-08 09:48:34 +03006745 /* Even though the attribute is u32, the specification says
6746 * u8, so let's make sure we don't overflow.
6747 */
6748 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6749 if (cs_count > 255)
6750 return -EINVAL;
6751
6752 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006753
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006754 if (!need_new_beacon)
6755 goto skip_beacons;
6756
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006757 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6758 if (err)
6759 return err;
6760
6761 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6762 info->attrs[NL80211_ATTR_CSA_IES],
6763 nl80211_policy);
6764 if (err)
6765 return err;
6766
6767 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6768 if (err)
6769 return err;
6770
6771 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6772 return -EINVAL;
6773
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006774 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6775 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006776 return -EINVAL;
6777
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006778 params.n_counter_offsets_beacon = len / sizeof(u16);
6779 if (rdev->wiphy.max_num_csa_counters &&
6780 (params.n_counter_offsets_beacon >
6781 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006782 return -EINVAL;
6783
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006784 params.counter_offsets_beacon =
6785 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6786
6787 /* sanity checks - counters should fit and be the same */
6788 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6789 u16 offset = params.counter_offsets_beacon[i];
6790
6791 if (offset >= params.beacon_csa.tail_len)
6792 return -EINVAL;
6793
6794 if (params.beacon_csa.tail[offset] != params.count)
6795 return -EINVAL;
6796 }
6797
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006798 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006799 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6800 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006801 return -EINVAL;
6802
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006803 params.n_counter_offsets_presp = len / sizeof(u16);
6804 if (rdev->wiphy.max_num_csa_counters &&
6805 (params.n_counter_offsets_beacon >
6806 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006807 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006808
6809 params.counter_offsets_presp =
6810 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6811
6812 /* sanity checks - counters should fit and be the same */
6813 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6814 u16 offset = params.counter_offsets_presp[i];
6815
6816 if (offset >= params.beacon_csa.probe_resp_len)
6817 return -EINVAL;
6818
6819 if (params.beacon_csa.probe_resp[offset] !=
6820 params.count)
6821 return -EINVAL;
6822 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006823 }
6824
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006825skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006826 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6827 if (err)
6828 return err;
6829
Arik Nemtsov923b3522015-07-08 15:41:44 +03006830 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6831 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006832 return -EINVAL;
6833
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006834 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6835 &params.chandef,
6836 wdev->iftype);
6837 if (err < 0)
6838 return err;
6839
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006840 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006841 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006842
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006843 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6844 params.block_tx = true;
6845
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006846 wdev_lock(wdev);
6847 err = rdev_channel_switch(rdev, dev, &params);
6848 wdev_unlock(wdev);
6849
6850 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006851}
6852
Johannes Berg9720bb32011-06-21 09:45:33 +02006853static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6854 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006855 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006856 struct wireless_dev *wdev,
6857 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006858{
Johannes Berg48ab9052009-07-10 18:42:31 +02006859 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006860 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006861 void *hdr;
6862 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006863
6864 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006865
Eric W. Biederman15e47302012-09-07 20:12:54 +00006866 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006867 NL80211_CMD_NEW_SCAN_RESULTS);
6868 if (!hdr)
6869 return -1;
6870
Johannes Berg9720bb32011-06-21 09:45:33 +02006871 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6872
Johannes Berg97990a02013-04-19 01:02:55 +02006873 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6874 goto nla_put_failure;
6875 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006876 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6877 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006878 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
6879 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02006880 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006881
6882 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6883 if (!bss)
6884 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006885 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006886 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006887 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006888
6889 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006890 /* indicate whether we have probe response data or not */
6891 if (rcu_access_pointer(res->proberesp_ies) &&
6892 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6893 goto fail_unlock_rcu;
6894
6895 /* this pointer prefers to be pointed to probe response data
6896 * but is always valid
6897 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006898 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006899 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006900 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
6901 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006902 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006903 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6904 ies->len, ies->data))
6905 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006906 }
Johannes Berg0e227082014-08-12 20:34:30 +02006907
6908 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006909 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006910 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006911 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
6912 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006913 goto fail_unlock_rcu;
6914 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6915 ies->len, ies->data))
6916 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006917 }
6918 rcu_read_unlock();
6919
David S. Miller9360ffd2012-03-29 04:41:26 -04006920 if (res->beacon_interval &&
6921 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6922 goto nla_put_failure;
6923 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6924 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006925 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006926 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6927 jiffies_to_msecs(jiffies - intbss->ts)))
6928 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006929
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006930 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006931 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6932 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006933 goto nla_put_failure;
6934
Johannes Berg77965c92009-02-18 18:45:06 +01006935 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006936 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006937 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6938 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006939 break;
6940 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006941 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6942 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006943 break;
6944 default:
6945 break;
6946 }
6947
Johannes Berg48ab9052009-07-10 18:42:31 +02006948 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006949 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006950 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006951 if (intbss == wdev->current_bss &&
6952 nla_put_u32(msg, NL80211_BSS_STATUS,
6953 NL80211_BSS_STATUS_ASSOCIATED))
6954 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006955 break;
6956 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006957 if (intbss == wdev->current_bss &&
6958 nla_put_u32(msg, NL80211_BSS_STATUS,
6959 NL80211_BSS_STATUS_IBSS_JOINED))
6960 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006961 break;
6962 default:
6963 break;
6964 }
6965
Johannes Berg2a519312009-02-10 21:25:55 +01006966 nla_nest_end(msg, bss);
6967
Johannes Berg053c0952015-01-16 22:09:00 +01006968 genlmsg_end(msg, hdr);
6969 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006970
Johannes Berg8cef2c92013-02-05 16:54:31 +01006971 fail_unlock_rcu:
6972 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006973 nla_put_failure:
6974 genlmsg_cancel(msg, hdr);
6975 return -EMSGSIZE;
6976}
6977
Johannes Berg97990a02013-04-19 01:02:55 +02006978static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006979{
Johannes Berg48ab9052009-07-10 18:42:31 +02006980 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006981 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006982 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006983 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006984 int err;
6985
Johannes Berg97990a02013-04-19 01:02:55 +02006986 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006987 if (err)
6988 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006989
Johannes Berg48ab9052009-07-10 18:42:31 +02006990 wdev_lock(wdev);
6991 spin_lock_bh(&rdev->bss_lock);
6992 cfg80211_bss_expire(rdev);
6993
Johannes Berg9720bb32011-06-21 09:45:33 +02006994 cb->seq = rdev->bss_generation;
6995
Johannes Berg48ab9052009-07-10 18:42:31 +02006996 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006997 if (++idx <= start)
6998 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006999 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007000 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007001 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007002 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007003 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007004 }
7005 }
7006
Johannes Berg48ab9052009-07-10 18:42:31 +02007007 spin_unlock_bh(&rdev->bss_lock);
7008 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007009
Johannes Berg97990a02013-04-19 01:02:55 +02007010 cb->args[2] = idx;
7011 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007012
Johannes Berg67748892010-10-04 21:14:06 +02007013 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007014}
7015
Eric W. Biederman15e47302012-09-07 20:12:54 +00007016static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007017 int flags, struct net_device *dev,
7018 bool allow_radio_stats,
7019 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007020{
7021 void *hdr;
7022 struct nlattr *infoattr;
7023
Johannes Berg11f78ac2014-11-14 16:43:50 +01007024 /* skip radio stats if userspace didn't request them */
7025 if (!survey->channel && !allow_radio_stats)
7026 return 0;
7027
Eric W. Biederman15e47302012-09-07 20:12:54 +00007028 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007029 NL80211_CMD_NEW_SURVEY_RESULTS);
7030 if (!hdr)
7031 return -ENOMEM;
7032
David S. Miller9360ffd2012-03-29 04:41:26 -04007033 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7034 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007035
7036 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7037 if (!infoattr)
7038 goto nla_put_failure;
7039
Johannes Berg11f78ac2014-11-14 16:43:50 +01007040 if (survey->channel &&
7041 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007042 survey->channel->center_freq))
7043 goto nla_put_failure;
7044
7045 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7046 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7047 goto nla_put_failure;
7048 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7049 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7050 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007051 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007052 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7053 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007054 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007055 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007056 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7057 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007058 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007059 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007060 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7061 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007062 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007063 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007064 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7065 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007066 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007067 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007068 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7069 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007070 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007071 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007072 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7073 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007074 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007075
7076 nla_nest_end(msg, infoattr);
7077
Johannes Berg053c0952015-01-16 22:09:00 +01007078 genlmsg_end(msg, hdr);
7079 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007080
7081 nla_put_failure:
7082 genlmsg_cancel(msg, hdr);
7083 return -EMSGSIZE;
7084}
7085
Johannes Berg11f78ac2014-11-14 16:43:50 +01007086static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007087{
7088 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007089 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007090 struct wireless_dev *wdev;
7091 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007092 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007093 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007094
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007095 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007096 if (res)
7097 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007098
Johannes Berg11f78ac2014-11-14 16:43:50 +01007099 /* prepare_wdev_dump parsed the attributes */
7100 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7101
Johannes Berg97990a02013-04-19 01:02:55 +02007102 if (!wdev->netdev) {
7103 res = -EINVAL;
7104 goto out_err;
7105 }
7106
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007107 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007108 res = -EOPNOTSUPP;
7109 goto out_err;
7110 }
7111
7112 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007113 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007114 if (res == -ENOENT)
7115 break;
7116 if (res)
7117 goto out_err;
7118
Johannes Berg11f78ac2014-11-14 16:43:50 +01007119 /* don't send disabled channels, but do send non-channel data */
7120 if (survey.channel &&
7121 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007122 survey_idx++;
7123 continue;
7124 }
7125
Holger Schurig61fa7132009-11-11 12:25:40 +01007126 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007127 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007128 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007129 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007130 goto out;
7131 survey_idx++;
7132 }
7133
7134 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007135 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007136 res = skb->len;
7137 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007138 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007139 return res;
7140}
7141
Samuel Ortizb23aa672009-07-01 21:26:54 +02007142static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7143{
7144 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7145 NL80211_WPA_VERSION_2));
7146}
7147
Jouni Malinen636a5d32009-03-19 13:39:22 +02007148static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7149{
Johannes Berg4c476992010-10-04 21:36:35 +02007150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7151 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007152 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007153 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7154 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007155 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007156 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007157 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007158
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007159 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7160 return -EINVAL;
7161
7162 if (!info->attrs[NL80211_ATTR_MAC])
7163 return -EINVAL;
7164
Jouni Malinen17780922009-03-27 20:52:47 +02007165 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7166 return -EINVAL;
7167
Johannes Berg19957bb2009-07-02 17:20:43 +02007168 if (!info->attrs[NL80211_ATTR_SSID])
7169 return -EINVAL;
7170
7171 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7172 return -EINVAL;
7173
Johannes Bergfffd0932009-07-08 14:22:54 +02007174 err = nl80211_parse_key(info, &key);
7175 if (err)
7176 return err;
7177
7178 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007179 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7180 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007181 if (!key.p.key || !key.p.key_len)
7182 return -EINVAL;
7183 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7184 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7185 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7186 key.p.key_len != WLAN_KEY_LEN_WEP104))
7187 return -EINVAL;
7188 if (key.idx > 4)
7189 return -EINVAL;
7190 } else {
7191 key.p.key_len = 0;
7192 key.p.key = NULL;
7193 }
7194
Johannes Bergafea0b72010-08-10 09:46:42 +02007195 if (key.idx >= 0) {
7196 int i;
7197 bool ok = false;
7198 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7199 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7200 ok = true;
7201 break;
7202 }
7203 }
Johannes Berg4c476992010-10-04 21:36:35 +02007204 if (!ok)
7205 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007206 }
7207
Johannes Berg4c476992010-10-04 21:36:35 +02007208 if (!rdev->ops->auth)
7209 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007210
Johannes Berg074ac8d2010-09-16 14:58:22 +02007211 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007212 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7213 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007214
Johannes Berg19957bb2009-07-02 17:20:43 +02007215 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007216 chan = nl80211_get_valid_chan(&rdev->wiphy,
7217 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7218 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007219 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007220
Johannes Berg19957bb2009-07-02 17:20:43 +02007221 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7222 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7223
7224 if (info->attrs[NL80211_ATTR_IE]) {
7225 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7226 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7227 }
7228
7229 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007230 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007231 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007232
Jouni Malinene39e5b52012-09-30 19:29:39 +03007233 if (auth_type == NL80211_AUTHTYPE_SAE &&
7234 !info->attrs[NL80211_ATTR_SAE_DATA])
7235 return -EINVAL;
7236
7237 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7238 if (auth_type != NL80211_AUTHTYPE_SAE)
7239 return -EINVAL;
7240 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7241 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7242 /* need to include at least Auth Transaction and Status Code */
7243 if (sae_data_len < 4)
7244 return -EINVAL;
7245 }
7246
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007247 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7248
Johannes Berg95de8172012-01-20 13:55:25 +01007249 /*
7250 * Since we no longer track auth state, ignore
7251 * requests to only change local state.
7252 */
7253 if (local_state_change)
7254 return 0;
7255
Johannes Berg91bf9b22013-05-15 17:44:01 +02007256 wdev_lock(dev->ieee80211_ptr);
7257 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7258 ssid, ssid_len, ie, ie_len,
7259 key.p.key, key.p.key_len, key.idx,
7260 sae_data, sae_data_len);
7261 wdev_unlock(dev->ieee80211_ptr);
7262 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007263}
7264
Johannes Bergc0692b82010-08-27 14:26:53 +03007265static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7266 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007267 struct cfg80211_crypto_settings *settings,
7268 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007269{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007270 memset(settings, 0, sizeof(*settings));
7271
Samuel Ortizb23aa672009-07-01 21:26:54 +02007272 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7273
Johannes Bergc0692b82010-08-27 14:26:53 +03007274 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7275 u16 proto;
7276 proto = nla_get_u16(
7277 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7278 settings->control_port_ethertype = cpu_to_be16(proto);
7279 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7280 proto != ETH_P_PAE)
7281 return -EINVAL;
7282 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7283 settings->control_port_no_encrypt = true;
7284 } else
7285 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7286
Samuel Ortizb23aa672009-07-01 21:26:54 +02007287 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7288 void *data;
7289 int len, i;
7290
7291 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7292 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7293 settings->n_ciphers_pairwise = len / sizeof(u32);
7294
7295 if (len % sizeof(u32))
7296 return -EINVAL;
7297
Johannes Berg3dc27d22009-07-02 21:36:37 +02007298 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007299 return -EINVAL;
7300
7301 memcpy(settings->ciphers_pairwise, data, len);
7302
7303 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007304 if (!cfg80211_supported_cipher_suite(
7305 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007306 settings->ciphers_pairwise[i]))
7307 return -EINVAL;
7308 }
7309
7310 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7311 settings->cipher_group =
7312 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007313 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7314 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007315 return -EINVAL;
7316 }
7317
7318 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7319 settings->wpa_versions =
7320 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7321 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7322 return -EINVAL;
7323 }
7324
7325 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7326 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007327 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007328
7329 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7330 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7331 settings->n_akm_suites = len / sizeof(u32);
7332
7333 if (len % sizeof(u32))
7334 return -EINVAL;
7335
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007336 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7337 return -EINVAL;
7338
Samuel Ortizb23aa672009-07-01 21:26:54 +02007339 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007340 }
7341
7342 return 0;
7343}
7344
Jouni Malinen636a5d32009-03-19 13:39:22 +02007345static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7346{
Johannes Berg4c476992010-10-04 21:36:35 +02007347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7348 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007349 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007350 struct cfg80211_assoc_request req = {};
7351 const u8 *bssid, *ssid;
7352 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007353
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007354 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7355 return -EINVAL;
7356
7357 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007358 !info->attrs[NL80211_ATTR_SSID] ||
7359 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007360 return -EINVAL;
7361
Johannes Berg4c476992010-10-04 21:36:35 +02007362 if (!rdev->ops->assoc)
7363 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007364
Johannes Berg074ac8d2010-09-16 14:58:22 +02007365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007366 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7367 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007368
Johannes Berg19957bb2009-07-02 17:20:43 +02007369 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007370
Jouni Malinen664834d2014-01-15 00:01:44 +02007371 chan = nl80211_get_valid_chan(&rdev->wiphy,
7372 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7373 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007374 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007375
Johannes Berg19957bb2009-07-02 17:20:43 +02007376 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7377 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007378
7379 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007380 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7381 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007382 }
7383
Jouni Malinendc6382c2009-05-06 22:09:37 +03007384 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007385 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007386 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007387 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007388 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007389 else if (mfp != NL80211_MFP_NO)
7390 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007391 }
7392
Johannes Berg3e5d7642009-07-07 14:37:26 +02007393 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007394 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007395
Ben Greear7e7c8922011-11-18 11:31:59 -08007396 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007397 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007398
7399 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007400 memcpy(&req.ht_capa_mask,
7401 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7402 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007403
7404 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007405 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007406 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007407 memcpy(&req.ht_capa,
7408 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7409 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007410 }
7411
Johannes Bergee2aca32013-02-21 17:36:01 +01007412 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007413 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007414
7415 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007416 memcpy(&req.vht_capa_mask,
7417 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7418 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007419
7420 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007421 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007422 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007423 memcpy(&req.vht_capa,
7424 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7425 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007426 }
7427
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007428 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007429 if (!((rdev->wiphy.features &
7430 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7431 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7432 !wiphy_ext_feature_isset(&rdev->wiphy,
7433 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007434 return -EINVAL;
7435 req.flags |= ASSOC_REQ_USE_RRM;
7436 }
7437
Johannes Bergf62fab72013-02-21 20:09:09 +01007438 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007439 if (!err) {
7440 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007441 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7442 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007443 wdev_unlock(dev->ieee80211_ptr);
7444 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007445
Jouni Malinen636a5d32009-03-19 13:39:22 +02007446 return err;
7447}
7448
7449static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7450{
Johannes Berg4c476992010-10-04 21:36:35 +02007451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7452 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007453 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007454 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007455 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007456 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007457
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007458 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7459 return -EINVAL;
7460
7461 if (!info->attrs[NL80211_ATTR_MAC])
7462 return -EINVAL;
7463
7464 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7465 return -EINVAL;
7466
Johannes Berg4c476992010-10-04 21:36:35 +02007467 if (!rdev->ops->deauth)
7468 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007469
Johannes Berg074ac8d2010-09-16 14:58:22 +02007470 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007471 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7472 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007473
Johannes Berg19957bb2009-07-02 17:20:43 +02007474 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007475
Johannes Berg19957bb2009-07-02 17:20:43 +02007476 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7477 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007478 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007479 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007480 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007481
7482 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007483 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7484 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007485 }
7486
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007487 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7488
Johannes Berg91bf9b22013-05-15 17:44:01 +02007489 wdev_lock(dev->ieee80211_ptr);
7490 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7491 local_state_change);
7492 wdev_unlock(dev->ieee80211_ptr);
7493 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007494}
7495
7496static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7497{
Johannes Berg4c476992010-10-04 21:36:35 +02007498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7499 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007500 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007501 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007502 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007503 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007504
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007505 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7506 return -EINVAL;
7507
7508 if (!info->attrs[NL80211_ATTR_MAC])
7509 return -EINVAL;
7510
7511 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7512 return -EINVAL;
7513
Johannes Berg4c476992010-10-04 21:36:35 +02007514 if (!rdev->ops->disassoc)
7515 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007516
Johannes Berg074ac8d2010-09-16 14:58:22 +02007517 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007518 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7519 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007520
Johannes Berg19957bb2009-07-02 17:20:43 +02007521 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007522
Johannes Berg19957bb2009-07-02 17:20:43 +02007523 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7524 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007525 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007526 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007527 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007528
7529 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007530 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7531 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007532 }
7533
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007534 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7535
Johannes Berg91bf9b22013-05-15 17:44:01 +02007536 wdev_lock(dev->ieee80211_ptr);
7537 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7538 local_state_change);
7539 wdev_unlock(dev->ieee80211_ptr);
7540 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007541}
7542
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007543static bool
7544nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007545 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007546 int rateval)
7547{
7548 struct wiphy *wiphy = &rdev->wiphy;
7549 bool found = false;
7550 int band, i;
7551
Johannes Berg57fbcce2016-04-12 15:56:15 +02007552 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007553 struct ieee80211_supported_band *sband;
7554
7555 sband = wiphy->bands[band];
7556 if (!sband)
7557 continue;
7558
7559 for (i = 0; i < sband->n_bitrates; i++) {
7560 if (sband->bitrates[i].bitrate == rateval) {
7561 mcast_rate[band] = i + 1;
7562 found = true;
7563 break;
7564 }
7565 }
7566 }
7567
7568 return found;
7569}
7570
Johannes Berg04a773a2009-04-19 21:24:32 +02007571static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7572{
Johannes Berg4c476992010-10-04 21:36:35 +02007573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7574 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007575 struct cfg80211_ibss_params ibss;
7576 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007577 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007578 int err;
7579
Johannes Berg8e30bc52009-04-22 17:45:38 +02007580 memset(&ibss, 0, sizeof(ibss));
7581
Johannes Berg04a773a2009-04-19 21:24:32 +02007582 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7583 return -EINVAL;
7584
Johannes Berg683b6d32012-11-08 21:25:48 +01007585 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007586 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7587 return -EINVAL;
7588
Johannes Berg8e30bc52009-04-22 17:45:38 +02007589 ibss.beacon_interval = 100;
7590
7591 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7592 ibss.beacon_interval =
7593 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7594 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7595 return -EINVAL;
7596 }
7597
Johannes Berg4c476992010-10-04 21:36:35 +02007598 if (!rdev->ops->join_ibss)
7599 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007600
Johannes Berg4c476992010-10-04 21:36:35 +02007601 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7602 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007603
Johannes Berg79c97e92009-07-07 03:56:12 +02007604 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007605
Johannes Berg39193492011-09-16 13:45:25 +02007606 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007607 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007608
7609 if (!is_valid_ether_addr(ibss.bssid))
7610 return -EINVAL;
7611 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007612 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7613 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7614
7615 if (info->attrs[NL80211_ATTR_IE]) {
7616 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7617 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7618 }
7619
Johannes Berg683b6d32012-11-08 21:25:48 +01007620 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7621 if (err)
7622 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007623
Ilan Peer174e0cd2014-02-23 09:13:01 +02007624 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7625 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007626 return -EINVAL;
7627
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007628 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007629 case NL80211_CHAN_WIDTH_5:
7630 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007631 case NL80211_CHAN_WIDTH_20_NOHT:
7632 break;
7633 case NL80211_CHAN_WIDTH_20:
7634 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007635 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7636 return -EINVAL;
7637 break;
7638 case NL80211_CHAN_WIDTH_80:
7639 case NL80211_CHAN_WIDTH_80P80:
7640 case NL80211_CHAN_WIDTH_160:
7641 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7642 return -EINVAL;
7643 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7644 NL80211_EXT_FEATURE_VHT_IBSS))
7645 return -EINVAL;
7646 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007647 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007648 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007649 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007650
Johannes Berg04a773a2009-04-19 21:24:32 +02007651 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007652 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007653
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007654 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7655 u8 *rates =
7656 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7657 int n_rates =
7658 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7659 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007660 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007661
Johannes Berg34850ab2011-07-18 18:08:35 +02007662 err = ieee80211_get_ratemask(sband, rates, n_rates,
7663 &ibss.basic_rates);
7664 if (err)
7665 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007666 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007667
Simon Wunderlich803768f2013-06-28 10:39:58 +02007668 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7669 memcpy(&ibss.ht_capa_mask,
7670 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7671 sizeof(ibss.ht_capa_mask));
7672
7673 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7674 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7675 return -EINVAL;
7676 memcpy(&ibss.ht_capa,
7677 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7678 sizeof(ibss.ht_capa));
7679 }
7680
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007681 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7682 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7683 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7684 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007685
Johannes Berg4c476992010-10-04 21:36:35 +02007686 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307687 bool no_ht = false;
7688
Johannes Berg4c476992010-10-04 21:36:35 +02007689 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307690 info->attrs[NL80211_ATTR_KEYS],
7691 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007692 if (IS_ERR(connkeys))
7693 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307694
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007695 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7696 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007697 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307698 return -EINVAL;
7699 }
Johannes Berg4c476992010-10-04 21:36:35 +02007700 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007701
Antonio Quartulli267335d2012-01-31 20:25:47 +01007702 ibss.control_port =
7703 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7704
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007705 ibss.userspace_handles_dfs =
7706 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7707
Johannes Berg4c476992010-10-04 21:36:35 +02007708 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007709 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007710 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007711 return err;
7712}
7713
7714static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7715{
Johannes Berg4c476992010-10-04 21:36:35 +02007716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7717 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007718
Johannes Berg4c476992010-10-04 21:36:35 +02007719 if (!rdev->ops->leave_ibss)
7720 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007721
Johannes Berg4c476992010-10-04 21:36:35 +02007722 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7723 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007724
Johannes Berg4c476992010-10-04 21:36:35 +02007725 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007726}
7727
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007728static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7729{
7730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7731 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007732 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007733 u32 nla_rate;
7734 int err;
7735
7736 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007737 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7738 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007739 return -EOPNOTSUPP;
7740
7741 if (!rdev->ops->set_mcast_rate)
7742 return -EOPNOTSUPP;
7743
7744 memset(mcast_rate, 0, sizeof(mcast_rate));
7745
7746 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7747 return -EINVAL;
7748
7749 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7750 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7751 return -EINVAL;
7752
Ilan Peera1056b12015-10-22 22:27:46 +03007753 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007754
7755 return err;
7756}
7757
Johannes Bergad7e7182013-11-13 13:37:47 +01007758static struct sk_buff *
7759__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007760 struct wireless_dev *wdev, int approxlen,
7761 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007762 enum nl80211_attrs attr,
7763 const struct nl80211_vendor_cmd_info *info,
7764 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007765{
7766 struct sk_buff *skb;
7767 void *hdr;
7768 struct nlattr *data;
7769
7770 skb = nlmsg_new(approxlen + 100, gfp);
7771 if (!skb)
7772 return NULL;
7773
7774 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7775 if (!hdr) {
7776 kfree_skb(skb);
7777 return NULL;
7778 }
7779
7780 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7781 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007782
7783 if (info) {
7784 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7785 info->vendor_id))
7786 goto nla_put_failure;
7787 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7788 info->subcmd))
7789 goto nla_put_failure;
7790 }
7791
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007792 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007793 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7794 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007795 goto nla_put_failure;
7796 if (wdev->netdev &&
7797 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7798 wdev->netdev->ifindex))
7799 goto nla_put_failure;
7800 }
7801
Johannes Bergad7e7182013-11-13 13:37:47 +01007802 data = nla_nest_start(skb, attr);
7803
7804 ((void **)skb->cb)[0] = rdev;
7805 ((void **)skb->cb)[1] = hdr;
7806 ((void **)skb->cb)[2] = data;
7807
7808 return skb;
7809
7810 nla_put_failure:
7811 kfree_skb(skb);
7812 return NULL;
7813}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007814
Johannes Berge03ad6e2014-01-01 17:22:30 +01007815struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007816 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007817 enum nl80211_commands cmd,
7818 enum nl80211_attrs attr,
7819 int vendor_event_idx,
7820 int approxlen, gfp_t gfp)
7821{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007822 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007823 const struct nl80211_vendor_cmd_info *info;
7824
7825 switch (cmd) {
7826 case NL80211_CMD_TESTMODE:
7827 if (WARN_ON(vendor_event_idx != -1))
7828 return NULL;
7829 info = NULL;
7830 break;
7831 case NL80211_CMD_VENDOR:
7832 if (WARN_ON(vendor_event_idx < 0 ||
7833 vendor_event_idx >= wiphy->n_vendor_events))
7834 return NULL;
7835 info = &wiphy->vendor_events[vendor_event_idx];
7836 break;
7837 default:
7838 WARN_ON(1);
7839 return NULL;
7840 }
7841
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007842 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007843 cmd, attr, info, gfp);
7844}
7845EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7846
7847void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7848{
7849 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7850 void *hdr = ((void **)skb->cb)[1];
7851 struct nlattr *data = ((void **)skb->cb)[2];
7852 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7853
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007854 /* clear CB data for netlink core to own from now on */
7855 memset(skb->cb, 0, sizeof(skb->cb));
7856
Johannes Berge03ad6e2014-01-01 17:22:30 +01007857 nla_nest_end(skb, data);
7858 genlmsg_end(skb, hdr);
7859
7860 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7861 mcgrp = NL80211_MCGRP_VENDOR;
7862
7863 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7864 mcgrp, gfp);
7865}
7866EXPORT_SYMBOL(__cfg80211_send_event_skb);
7867
Johannes Bergaff89a92009-07-01 21:26:51 +02007868#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007869static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7870{
Johannes Berg4c476992010-10-04 21:36:35 +02007871 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007872 struct wireless_dev *wdev =
7873 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007874 int err;
7875
David Spinadelfc73f112013-07-31 18:04:15 +03007876 if (!rdev->ops->testmode_cmd)
7877 return -EOPNOTSUPP;
7878
7879 if (IS_ERR(wdev)) {
7880 err = PTR_ERR(wdev);
7881 if (err != -EINVAL)
7882 return err;
7883 wdev = NULL;
7884 } else if (wdev->wiphy != &rdev->wiphy) {
7885 return -EINVAL;
7886 }
7887
Johannes Bergaff89a92009-07-01 21:26:51 +02007888 if (!info->attrs[NL80211_ATTR_TESTDATA])
7889 return -EINVAL;
7890
Johannes Bergad7e7182013-11-13 13:37:47 +01007891 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007892 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007893 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7894 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007895 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007896
Johannes Bergaff89a92009-07-01 21:26:51 +02007897 return err;
7898}
7899
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007900static int nl80211_testmode_dump(struct sk_buff *skb,
7901 struct netlink_callback *cb)
7902{
Johannes Berg00918d32011-12-13 17:22:05 +01007903 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007904 int err;
7905 long phy_idx;
7906 void *data = NULL;
7907 int data_len = 0;
7908
Johannes Berg5fe231e2013-05-08 21:45:15 +02007909 rtnl_lock();
7910
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007911 if (cb->args[0]) {
7912 /*
7913 * 0 is a valid index, but not valid for args[0],
7914 * so we need to offset by 1.
7915 */
7916 phy_idx = cb->args[0] - 1;
7917 } else {
7918 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7919 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7920 nl80211_policy);
7921 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007922 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007923
Johannes Berg2bd7e352012-06-15 14:23:16 +02007924 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7925 nl80211_fam.attrbuf);
7926 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007927 err = PTR_ERR(rdev);
7928 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007929 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007930 phy_idx = rdev->wiphy_idx;
7931 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007932
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007933 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7934 cb->args[1] =
7935 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7936 }
7937
7938 if (cb->args[1]) {
7939 data = nla_data((void *)cb->args[1]);
7940 data_len = nla_len((void *)cb->args[1]);
7941 }
7942
Johannes Berg00918d32011-12-13 17:22:05 +01007943 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7944 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007945 err = -ENOENT;
7946 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007947 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007948
Johannes Berg00918d32011-12-13 17:22:05 +01007949 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007950 err = -EOPNOTSUPP;
7951 goto out_err;
7952 }
7953
7954 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007955 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007956 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7957 NL80211_CMD_TESTMODE);
7958 struct nlattr *tmdata;
7959
Dan Carpentercb35fba2013-08-14 14:50:01 +03007960 if (!hdr)
7961 break;
7962
David S. Miller9360ffd2012-03-29 04:41:26 -04007963 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007964 genlmsg_cancel(skb, hdr);
7965 break;
7966 }
7967
7968 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7969 if (!tmdata) {
7970 genlmsg_cancel(skb, hdr);
7971 break;
7972 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007973 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007974 nla_nest_end(skb, tmdata);
7975
7976 if (err == -ENOBUFS || err == -ENOENT) {
7977 genlmsg_cancel(skb, hdr);
7978 break;
7979 } else if (err) {
7980 genlmsg_cancel(skb, hdr);
7981 goto out_err;
7982 }
7983
7984 genlmsg_end(skb, hdr);
7985 }
7986
7987 err = skb->len;
7988 /* see above */
7989 cb->args[0] = phy_idx + 1;
7990 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007991 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007992 return err;
7993}
Johannes Bergaff89a92009-07-01 21:26:51 +02007994#endif
7995
Samuel Ortizb23aa672009-07-01 21:26:54 +02007996static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7997{
Johannes Berg4c476992010-10-04 21:36:35 +02007998 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7999 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008000 struct cfg80211_connect_params connect;
8001 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008002 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008003 int err;
8004
8005 memset(&connect, 0, sizeof(connect));
8006
8007 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8008 return -EINVAL;
8009
8010 if (!info->attrs[NL80211_ATTR_SSID] ||
8011 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8012 return -EINVAL;
8013
8014 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8015 connect.auth_type =
8016 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008017 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8018 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008019 return -EINVAL;
8020 } else
8021 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8022
8023 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8024
Johannes Bergc0692b82010-08-27 14:26:53 +03008025 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008026 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008027 if (err)
8028 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008029
Johannes Berg074ac8d2010-09-16 14:58:22 +02008030 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008031 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8032 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008033
Johannes Berg79c97e92009-07-07 03:56:12 +02008034 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008035
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308036 connect.bg_scan_period = -1;
8037 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8038 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8039 connect.bg_scan_period =
8040 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8041 }
8042
Samuel Ortizb23aa672009-07-01 21:26:54 +02008043 if (info->attrs[NL80211_ATTR_MAC])
8044 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008045 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8046 connect.bssid_hint =
8047 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008048 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8049 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8050
8051 if (info->attrs[NL80211_ATTR_IE]) {
8052 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8053 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8054 }
8055
Jouni Malinencee00a92013-01-15 17:15:57 +02008056 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8057 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8058 if (connect.mfp != NL80211_MFP_REQUIRED &&
8059 connect.mfp != NL80211_MFP_NO)
8060 return -EINVAL;
8061 } else {
8062 connect.mfp = NL80211_MFP_NO;
8063 }
8064
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008065 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8066 connect.prev_bssid =
8067 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8068
Samuel Ortizb23aa672009-07-01 21:26:54 +02008069 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008070 connect.channel = nl80211_get_valid_chan(
8071 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8072 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008073 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008074 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008075 connect.channel_hint = nl80211_get_valid_chan(
8076 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8077 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008078 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008079 }
8080
Johannes Bergfffd0932009-07-08 14:22:54 +02008081 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8082 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308083 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008084 if (IS_ERR(connkeys))
8085 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008086 }
8087
Ben Greear7e7c8922011-11-18 11:31:59 -08008088 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8089 connect.flags |= ASSOC_REQ_DISABLE_HT;
8090
8091 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8092 memcpy(&connect.ht_capa_mask,
8093 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8094 sizeof(connect.ht_capa_mask));
8095
8096 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008097 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008098 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008099 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008100 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008101 memcpy(&connect.ht_capa,
8102 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8103 sizeof(connect.ht_capa));
8104 }
8105
Johannes Bergee2aca32013-02-21 17:36:01 +01008106 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8107 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8108
8109 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8110 memcpy(&connect.vht_capa_mask,
8111 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8112 sizeof(connect.vht_capa_mask));
8113
8114 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8115 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008116 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008117 return -EINVAL;
8118 }
8119 memcpy(&connect.vht_capa,
8120 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8121 sizeof(connect.vht_capa));
8122 }
8123
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008124 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008125 if (!((rdev->wiphy.features &
8126 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8127 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8128 !wiphy_ext_feature_isset(&rdev->wiphy,
8129 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008130 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008131 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008132 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008133 connect.flags |= ASSOC_REQ_USE_RRM;
8134 }
8135
Lior David34d50512016-01-28 10:58:25 +02008136 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008137 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008138 kzfree(connkeys);
8139 return -EOPNOTSUPP;
8140 }
8141
Arend van Spriel38de03d2016-03-02 20:37:18 +01008142 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8143 /* bss selection makes no sense if bssid is set */
8144 if (connect.bssid) {
8145 kzfree(connkeys);
8146 return -EINVAL;
8147 }
8148
8149 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8150 wiphy, &connect.bss_select);
8151 if (err) {
8152 kzfree(connkeys);
8153 return err;
8154 }
8155 }
8156
Johannes Berg83739b02013-05-15 17:44:01 +02008157 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008158 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8159 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008160 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008161 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008162 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008163 return err;
8164}
8165
8166static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8167{
Johannes Berg4c476992010-10-04 21:36:35 +02008168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8169 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008170 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008171 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008172
8173 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8174 reason = WLAN_REASON_DEAUTH_LEAVING;
8175 else
8176 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8177
8178 if (reason == 0)
8179 return -EINVAL;
8180
Johannes Berg074ac8d2010-09-16 14:58:22 +02008181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8183 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008184
Johannes Berg83739b02013-05-15 17:44:01 +02008185 wdev_lock(dev->ieee80211_ptr);
8186 ret = cfg80211_disconnect(rdev, dev, reason, true);
8187 wdev_unlock(dev->ieee80211_ptr);
8188 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008189}
8190
Johannes Berg463d0182009-07-14 00:33:35 +02008191static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8192{
Johannes Berg4c476992010-10-04 21:36:35 +02008193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008194 struct net *net;
8195 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008196
Vadim Kochan4b681c82015-01-12 16:34:05 +02008197 if (info->attrs[NL80211_ATTR_PID]) {
8198 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8199
8200 net = get_net_ns_by_pid(pid);
8201 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8202 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8203
8204 net = get_net_ns_by_fd(fd);
8205 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008206 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008207 }
Johannes Berg463d0182009-07-14 00:33:35 +02008208
Johannes Berg4c476992010-10-04 21:36:35 +02008209 if (IS_ERR(net))
8210 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008211
8212 err = 0;
8213
8214 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008215 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8216 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008217
Johannes Berg463d0182009-07-14 00:33:35 +02008218 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008219 return err;
8220}
8221
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008222static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8223{
Johannes Berg4c476992010-10-04 21:36:35 +02008224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008225 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8226 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008227 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008228 struct cfg80211_pmksa pmksa;
8229
8230 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8231
8232 if (!info->attrs[NL80211_ATTR_MAC])
8233 return -EINVAL;
8234
8235 if (!info->attrs[NL80211_ATTR_PMKID])
8236 return -EINVAL;
8237
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008238 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8239 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8240
Johannes Berg074ac8d2010-09-16 14:58:22 +02008241 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008242 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8243 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008244
8245 switch (info->genlhdr->cmd) {
8246 case NL80211_CMD_SET_PMKSA:
8247 rdev_ops = rdev->ops->set_pmksa;
8248 break;
8249 case NL80211_CMD_DEL_PMKSA:
8250 rdev_ops = rdev->ops->del_pmksa;
8251 break;
8252 default:
8253 WARN_ON(1);
8254 break;
8255 }
8256
Johannes Berg4c476992010-10-04 21:36:35 +02008257 if (!rdev_ops)
8258 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008259
Johannes Berg4c476992010-10-04 21:36:35 +02008260 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008261}
8262
8263static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8264{
Johannes Berg4c476992010-10-04 21:36:35 +02008265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8266 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008267
Johannes Berg074ac8d2010-09-16 14:58:22 +02008268 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008269 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8270 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008271
Johannes Berg4c476992010-10-04 21:36:35 +02008272 if (!rdev->ops->flush_pmksa)
8273 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008274
Hila Gonene35e4d22012-06-27 17:19:42 +03008275 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008276}
8277
Arik Nemtsov109086c2011-09-28 14:12:50 +03008278static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8279{
8280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8281 struct net_device *dev = info->user_ptr[1];
8282 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308283 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008284 u16 status_code;
8285 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008286 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008287
8288 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8289 !rdev->ops->tdls_mgmt)
8290 return -EOPNOTSUPP;
8291
8292 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8293 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8294 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8295 !info->attrs[NL80211_ATTR_IE] ||
8296 !info->attrs[NL80211_ATTR_MAC])
8297 return -EINVAL;
8298
8299 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8300 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8301 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8302 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008303 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308304 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8305 peer_capability =
8306 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008307
Hila Gonene35e4d22012-06-27 17:19:42 +03008308 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308309 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008310 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008311 nla_data(info->attrs[NL80211_ATTR_IE]),
8312 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008313}
8314
8315static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8316{
8317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8318 struct net_device *dev = info->user_ptr[1];
8319 enum nl80211_tdls_operation operation;
8320 u8 *peer;
8321
8322 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8323 !rdev->ops->tdls_oper)
8324 return -EOPNOTSUPP;
8325
8326 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8327 !info->attrs[NL80211_ATTR_MAC])
8328 return -EINVAL;
8329
8330 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8331 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8332
Hila Gonene35e4d22012-06-27 17:19:42 +03008333 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008334}
8335
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008336static int nl80211_remain_on_channel(struct sk_buff *skb,
8337 struct genl_info *info)
8338{
Johannes Berg4c476992010-10-04 21:36:35 +02008339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008340 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008341 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008342 struct sk_buff *msg;
8343 void *hdr;
8344 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008345 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008346 int err;
8347
8348 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8349 !info->attrs[NL80211_ATTR_DURATION])
8350 return -EINVAL;
8351
8352 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8353
Johannes Berg7c4ef712011-11-18 15:33:48 +01008354 if (!rdev->ops->remain_on_channel ||
8355 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008356 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008357
Johannes Bergebf348f2012-06-01 12:50:54 +02008358 /*
8359 * We should be on that channel for at least a minimum amount of
8360 * time (10ms) but no longer than the driver supports.
8361 */
8362 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8363 duration > rdev->wiphy.max_remain_on_channel_duration)
8364 return -EINVAL;
8365
Johannes Berg683b6d32012-11-08 21:25:48 +01008366 err = nl80211_parse_chandef(rdev, info, &chandef);
8367 if (err)
8368 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008369
8370 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008371 if (!msg)
8372 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008373
Eric W. Biederman15e47302012-09-07 20:12:54 +00008374 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008375 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008376 if (!hdr) {
8377 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008378 goto free_msg;
8379 }
8380
Johannes Berg683b6d32012-11-08 21:25:48 +01008381 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8382 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008383
8384 if (err)
8385 goto free_msg;
8386
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008387 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8388 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008389 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008390
8391 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008392
8393 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008394
8395 nla_put_failure:
8396 err = -ENOBUFS;
8397 free_msg:
8398 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008399 return err;
8400}
8401
8402static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8403 struct genl_info *info)
8404{
Johannes Berg4c476992010-10-04 21:36:35 +02008405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008406 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008407 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008408
8409 if (!info->attrs[NL80211_ATTR_COOKIE])
8410 return -EINVAL;
8411
Johannes Berg4c476992010-10-04 21:36:35 +02008412 if (!rdev->ops->cancel_remain_on_channel)
8413 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008414
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008415 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8416
Hila Gonene35e4d22012-06-27 17:19:42 +03008417 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008418}
8419
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008420static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8421 u8 *rates, u8 rates_len)
8422{
8423 u8 i;
8424 u32 mask = 0;
8425
8426 for (i = 0; i < rates_len; i++) {
8427 int rate = (rates[i] & 0x7f) * 5;
8428 int ridx;
8429 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8430 struct ieee80211_rate *srate =
8431 &sband->bitrates[ridx];
8432 if (rate == srate->bitrate) {
8433 mask |= 1 << ridx;
8434 break;
8435 }
8436 }
8437 if (ridx == sband->n_bitrates)
8438 return 0; /* rate not found */
8439 }
8440
8441 return mask;
8442}
8443
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008444static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8445 u8 *rates, u8 rates_len,
8446 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8447{
8448 u8 i;
8449
8450 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8451
8452 for (i = 0; i < rates_len; i++) {
8453 int ridx, rbit;
8454
8455 ridx = rates[i] / 8;
8456 rbit = BIT(rates[i] % 8);
8457
8458 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008459 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008460 return false;
8461
8462 /* check availability */
8463 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8464 mcs[ridx] |= rbit;
8465 else
8466 return false;
8467 }
8468
8469 return true;
8470}
8471
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008472static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8473{
8474 u16 mcs_mask = 0;
8475
8476 switch (vht_mcs_map) {
8477 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8478 break;
8479 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8480 mcs_mask = 0x00FF;
8481 break;
8482 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8483 mcs_mask = 0x01FF;
8484 break;
8485 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8486 mcs_mask = 0x03FF;
8487 break;
8488 default:
8489 break;
8490 }
8491
8492 return mcs_mask;
8493}
8494
8495static void vht_build_mcs_mask(u16 vht_mcs_map,
8496 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8497{
8498 u8 nss;
8499
8500 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8501 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8502 vht_mcs_map >>= 2;
8503 }
8504}
8505
8506static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8507 struct nl80211_txrate_vht *txrate,
8508 u16 mcs[NL80211_VHT_NSS_MAX])
8509{
8510 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8511 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8512 u8 i;
8513
8514 if (!sband->vht_cap.vht_supported)
8515 return false;
8516
8517 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8518
8519 /* Build vht_mcs_mask from VHT capabilities */
8520 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8521
8522 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8523 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8524 mcs[i] = txrate->mcs[i];
8525 else
8526 return false;
8527 }
8528
8529 return true;
8530}
8531
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008532static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008533 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8534 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008535 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8536 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008537 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008538 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008539};
8540
8541static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8542 struct genl_info *info)
8543{
8544 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008546 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008547 int rem, i;
8548 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008549 struct nlattr *tx_rates;
8550 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008551 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008552
Johannes Berg4c476992010-10-04 21:36:35 +02008553 if (!rdev->ops->set_bitrate_mask)
8554 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008555
8556 memset(&mask, 0, sizeof(mask));
8557 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008558 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008559 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008560
8561 if (!sband)
8562 continue;
8563
8564 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008565 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008566 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008567 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008568
8569 if (!sband->vht_cap.vht_supported)
8570 continue;
8571
8572 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8573 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008574 }
8575
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008576 /* if no rates are given set it back to the defaults */
8577 if (!info->attrs[NL80211_ATTR_TX_RATES])
8578 goto out;
8579
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008580 /*
8581 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008582 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008583 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008584 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008585 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008586 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008587 int err;
8588
Johannes Berg57fbcce2016-04-12 15:56:15 +02008589 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008590 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008591 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008592 if (sband == NULL)
8593 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008594 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8595 nla_len(tx_rates), nl80211_txattr_policy);
8596 if (err)
8597 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008598 if (tb[NL80211_TXRATE_LEGACY]) {
8599 mask.control[band].legacy = rateset_to_mask(
8600 sband,
8601 nla_data(tb[NL80211_TXRATE_LEGACY]),
8602 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308603 if ((mask.control[band].legacy == 0) &&
8604 nla_len(tb[NL80211_TXRATE_LEGACY]))
8605 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008606 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008607 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008608 if (!ht_rateset_to_mask(
8609 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008610 nla_data(tb[NL80211_TXRATE_HT]),
8611 nla_len(tb[NL80211_TXRATE_HT]),
8612 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008613 return -EINVAL;
8614 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008615 if (tb[NL80211_TXRATE_VHT]) {
8616 if (!vht_set_mcs_mask(
8617 sband,
8618 nla_data(tb[NL80211_TXRATE_VHT]),
8619 mask.control[band].vht_mcs))
8620 return -EINVAL;
8621 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008622 if (tb[NL80211_TXRATE_GI]) {
8623 mask.control[band].gi =
8624 nla_get_u8(tb[NL80211_TXRATE_GI]);
8625 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8626 return -EINVAL;
8627 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008628
8629 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008630 /* don't allow empty legacy rates if HT or VHT
8631 * are not even supported.
8632 */
8633 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8634 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008635 return -EINVAL;
8636
8637 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008638 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008639 goto out;
8640
8641 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8642 if (mask.control[band].vht_mcs[i])
8643 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008644
8645 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008646 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008647 }
8648 }
8649
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008650out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008651 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008652}
8653
Johannes Berg2e161f72010-08-12 15:38:38 +02008654static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008655{
Johannes Berg4c476992010-10-04 21:36:35 +02008656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008657 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008658 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008659
8660 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8661 return -EINVAL;
8662
Johannes Berg2e161f72010-08-12 15:38:38 +02008663 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8664 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008665
Johannes Berg71bbc992012-06-15 15:30:18 +02008666 switch (wdev->iftype) {
8667 case NL80211_IFTYPE_STATION:
8668 case NL80211_IFTYPE_ADHOC:
8669 case NL80211_IFTYPE_P2P_CLIENT:
8670 case NL80211_IFTYPE_AP:
8671 case NL80211_IFTYPE_AP_VLAN:
8672 case NL80211_IFTYPE_MESH_POINT:
8673 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008674 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008675 break;
8676 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008677 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008678 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008679
8680 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008681 if (!rdev->ops->mgmt_tx)
8682 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008683
Eric W. Biederman15e47302012-09-07 20:12:54 +00008684 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008685 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8686 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008687}
8688
Johannes Berg2e161f72010-08-12 15:38:38 +02008689static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008690{
Johannes Berg4c476992010-10-04 21:36:35 +02008691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008692 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008693 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008694 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008695 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008696 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008697 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008698 struct cfg80211_mgmt_tx_params params = {
8699 .dont_wait_for_ack =
8700 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8701 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008702
Johannes Berg683b6d32012-11-08 21:25:48 +01008703 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008704 return -EINVAL;
8705
Johannes Berg4c476992010-10-04 21:36:35 +02008706 if (!rdev->ops->mgmt_tx)
8707 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008708
Johannes Berg71bbc992012-06-15 15:30:18 +02008709 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008710 case NL80211_IFTYPE_P2P_DEVICE:
8711 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8712 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008713 case NL80211_IFTYPE_STATION:
8714 case NL80211_IFTYPE_ADHOC:
8715 case NL80211_IFTYPE_P2P_CLIENT:
8716 case NL80211_IFTYPE_AP:
8717 case NL80211_IFTYPE_AP_VLAN:
8718 case NL80211_IFTYPE_MESH_POINT:
8719 case NL80211_IFTYPE_P2P_GO:
8720 break;
8721 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008722 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008723 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008724
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008725 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008726 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008727 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008728 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008729
8730 /*
8731 * We should wait on the channel for at least a minimum amount
8732 * of time (10ms) but no longer than the driver supports.
8733 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008734 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8735 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008736 return -EINVAL;
8737
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008738 }
8739
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008740 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008741
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008742 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008743 return -EINVAL;
8744
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008745 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308746
Antonio Quartulliea141b752013-06-11 14:20:03 +02008747 /* get the channel if any has been specified, otherwise pass NULL to
8748 * the driver. The latter will use the current one
8749 */
8750 chandef.chan = NULL;
8751 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8752 err = nl80211_parse_chandef(rdev, info, &chandef);
8753 if (err)
8754 return err;
8755 }
8756
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008757 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008758 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008759
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008760 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8761 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8762
8763 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8764 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8765 int i;
8766
8767 if (len % sizeof(u16))
8768 return -EINVAL;
8769
8770 params.n_csa_offsets = len / sizeof(u16);
8771 params.csa_offsets =
8772 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8773
8774 /* check that all the offsets fit the frame */
8775 for (i = 0; i < params.n_csa_offsets; i++) {
8776 if (params.csa_offsets[i] >= params.len)
8777 return -EINVAL;
8778 }
8779 }
8780
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008781 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008782 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8783 if (!msg)
8784 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008785
Eric W. Biederman15e47302012-09-07 20:12:54 +00008786 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008787 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008788 if (!hdr) {
8789 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008790 goto free_msg;
8791 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008792 }
Johannes Berge247bd902011-11-04 11:18:21 +01008793
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008794 params.chan = chandef.chan;
8795 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008796 if (err)
8797 goto free_msg;
8798
Johannes Berge247bd902011-11-04 11:18:21 +01008799 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008800 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8801 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008802 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008803
Johannes Berge247bd902011-11-04 11:18:21 +01008804 genlmsg_end(msg, hdr);
8805 return genlmsg_reply(msg, info);
8806 }
8807
8808 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008809
8810 nla_put_failure:
8811 err = -ENOBUFS;
8812 free_msg:
8813 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008814 return err;
8815}
8816
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008817static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8818{
8819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008820 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008821 u64 cookie;
8822
8823 if (!info->attrs[NL80211_ATTR_COOKIE])
8824 return -EINVAL;
8825
8826 if (!rdev->ops->mgmt_tx_cancel_wait)
8827 return -EOPNOTSUPP;
8828
Johannes Berg71bbc992012-06-15 15:30:18 +02008829 switch (wdev->iftype) {
8830 case NL80211_IFTYPE_STATION:
8831 case NL80211_IFTYPE_ADHOC:
8832 case NL80211_IFTYPE_P2P_CLIENT:
8833 case NL80211_IFTYPE_AP:
8834 case NL80211_IFTYPE_AP_VLAN:
8835 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008836 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008837 break;
8838 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008839 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008840 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008841
8842 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8843
Hila Gonene35e4d22012-06-27 17:19:42 +03008844 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008845}
8846
Kalle Valoffb9eb32010-02-17 17:58:10 +02008847static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8848{
Johannes Berg4c476992010-10-04 21:36:35 +02008849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008850 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008851 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008852 u8 ps_state;
8853 bool state;
8854 int err;
8855
Johannes Berg4c476992010-10-04 21:36:35 +02008856 if (!info->attrs[NL80211_ATTR_PS_STATE])
8857 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008858
8859 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8860
Johannes Berg4c476992010-10-04 21:36:35 +02008861 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8862 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008863
8864 wdev = dev->ieee80211_ptr;
8865
Johannes Berg4c476992010-10-04 21:36:35 +02008866 if (!rdev->ops->set_power_mgmt)
8867 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008868
8869 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8870
8871 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008872 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008873
Hila Gonene35e4d22012-06-27 17:19:42 +03008874 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008875 if (!err)
8876 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008877 return err;
8878}
8879
8880static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8881{
Johannes Berg4c476992010-10-04 21:36:35 +02008882 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008883 enum nl80211_ps_state ps_state;
8884 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008885 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008886 struct sk_buff *msg;
8887 void *hdr;
8888 int err;
8889
Kalle Valoffb9eb32010-02-17 17:58:10 +02008890 wdev = dev->ieee80211_ptr;
8891
Johannes Berg4c476992010-10-04 21:36:35 +02008892 if (!rdev->ops->set_power_mgmt)
8893 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008894
8895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008896 if (!msg)
8897 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008898
Eric W. Biederman15e47302012-09-07 20:12:54 +00008899 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008900 NL80211_CMD_GET_POWER_SAVE);
8901 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008902 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008903 goto free_msg;
8904 }
8905
8906 if (wdev->ps)
8907 ps_state = NL80211_PS_ENABLED;
8908 else
8909 ps_state = NL80211_PS_DISABLED;
8910
David S. Miller9360ffd2012-03-29 04:41:26 -04008911 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8912 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008913
8914 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008915 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008916
Johannes Berg4c476992010-10-04 21:36:35 +02008917 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008918 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008919 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008920 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008921 return err;
8922}
8923
Johannes Berg94e860f2014-01-20 23:58:15 +01008924static const struct nla_policy
8925nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008926 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8927 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8928 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008929 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8930 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8931 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008932};
8933
Thomas Pedersen84f10702012-07-12 16:17:33 -07008934static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008935 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008936{
8937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008938 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008939 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008940
Johannes Bergd9d8b012012-11-26 12:51:52 +01008941 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008942 return -EINVAL;
8943
Thomas Pedersen84f10702012-07-12 16:17:33 -07008944 if (!rdev->ops->set_cqm_txe_config)
8945 return -EOPNOTSUPP;
8946
8947 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8948 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8949 return -EOPNOTSUPP;
8950
Hila Gonene35e4d22012-06-27 17:19:42 +03008951 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008952}
8953
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008954static int nl80211_set_cqm_rssi(struct genl_info *info,
8955 s32 threshold, u32 hysteresis)
8956{
Johannes Berg4c476992010-10-04 21:36:35 +02008957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008958 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008959 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008960
8961 if (threshold > 0)
8962 return -EINVAL;
8963
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008964 /* disabling - hysteresis should also be zero then */
8965 if (threshold == 0)
8966 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008967
Johannes Berg4c476992010-10-04 21:36:35 +02008968 if (!rdev->ops->set_cqm_rssi_config)
8969 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008970
Johannes Berg074ac8d2010-09-16 14:58:22 +02008971 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008972 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8973 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008974
Hila Gonene35e4d22012-06-27 17:19:42 +03008975 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008976}
8977
8978static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8979{
8980 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8981 struct nlattr *cqm;
8982 int err;
8983
8984 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008985 if (!cqm)
8986 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008987
8988 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8989 nl80211_attr_cqm_policy);
8990 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008991 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008992
8993 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8994 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008995 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8996 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008997
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008998 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8999 }
9000
9001 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9002 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9003 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9004 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9005 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9006 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9007
9008 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9009 }
9010
9011 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009012}
9013
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009014static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9015{
9016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9017 struct net_device *dev = info->user_ptr[1];
9018 struct ocb_setup setup = {};
9019 int err;
9020
9021 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9022 if (err)
9023 return err;
9024
9025 return cfg80211_join_ocb(rdev, dev, &setup);
9026}
9027
9028static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9029{
9030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9031 struct net_device *dev = info->user_ptr[1];
9032
9033 return cfg80211_leave_ocb(rdev, dev);
9034}
9035
Johannes Berg29cbe682010-12-03 09:20:44 +01009036static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9037{
9038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9039 struct net_device *dev = info->user_ptr[1];
9040 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009041 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009042 int err;
9043
9044 /* start with default */
9045 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009046 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009047
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009048 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009049 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009050 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009051 if (err)
9052 return err;
9053 }
9054
9055 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9056 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9057 return -EINVAL;
9058
Javier Cardonac80d5452010-12-16 17:37:49 -08009059 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9060 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9061
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009062 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9063 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9064 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9065 return -EINVAL;
9066
Marco Porsch9bdbf042013-01-07 16:04:51 +01009067 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9068 setup.beacon_interval =
9069 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9070 if (setup.beacon_interval < 10 ||
9071 setup.beacon_interval > 10000)
9072 return -EINVAL;
9073 }
9074
9075 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9076 setup.dtim_period =
9077 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9078 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9079 return -EINVAL;
9080 }
9081
Javier Cardonac80d5452010-12-16 17:37:49 -08009082 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9083 /* parse additional setup parameters if given */
9084 err = nl80211_parse_mesh_setup(info, &setup);
9085 if (err)
9086 return err;
9087 }
9088
Thomas Pedersend37bb182013-03-04 13:06:13 -08009089 if (setup.user_mpm)
9090 cfg.auto_open_plinks = false;
9091
Johannes Bergcc1d2802012-05-16 23:50:20 +02009092 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009093 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9094 if (err)
9095 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009096 } else {
9097 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009098 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009099 }
9100
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009101 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9102 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9103 int n_rates =
9104 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9105 struct ieee80211_supported_band *sband;
9106
9107 if (!setup.chandef.chan)
9108 return -EINVAL;
9109
9110 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9111
9112 err = ieee80211_get_ratemask(sband, rates, n_rates,
9113 &setup.basic_rates);
9114 if (err)
9115 return err;
9116 }
9117
Javier Cardonac80d5452010-12-16 17:37:49 -08009118 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009119}
9120
9121static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9122{
9123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9124 struct net_device *dev = info->user_ptr[1];
9125
9126 return cfg80211_leave_mesh(rdev, dev);
9127}
9128
Johannes Bergdfb89c52012-06-27 09:23:48 +02009129#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009130static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9131 struct cfg80211_registered_device *rdev)
9132{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009133 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009134 struct nlattr *nl_pats, *nl_pat;
9135 int i, pat_len;
9136
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009137 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009138 return 0;
9139
9140 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9141 if (!nl_pats)
9142 return -ENOBUFS;
9143
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009144 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009145 nl_pat = nla_nest_start(msg, i + 1);
9146 if (!nl_pat)
9147 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009148 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009149 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009150 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009151 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9152 wowlan->patterns[i].pattern) ||
9153 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009154 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009155 return -ENOBUFS;
9156 nla_nest_end(msg, nl_pat);
9157 }
9158 nla_nest_end(msg, nl_pats);
9159
9160 return 0;
9161}
9162
Johannes Berg2a0e0472013-01-23 22:57:40 +01009163static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9164 struct cfg80211_wowlan_tcp *tcp)
9165{
9166 struct nlattr *nl_tcp;
9167
9168 if (!tcp)
9169 return 0;
9170
9171 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9172 if (!nl_tcp)
9173 return -ENOBUFS;
9174
Jiri Benc930345e2015-03-29 16:59:25 +02009175 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9176 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009177 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9178 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9179 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9180 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9181 tcp->payload_len, tcp->payload) ||
9182 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9183 tcp->data_interval) ||
9184 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9185 tcp->wake_len, tcp->wake_data) ||
9186 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9187 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9188 return -ENOBUFS;
9189
9190 if (tcp->payload_seq.len &&
9191 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9192 sizeof(tcp->payload_seq), &tcp->payload_seq))
9193 return -ENOBUFS;
9194
9195 if (tcp->payload_tok.len &&
9196 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9197 sizeof(tcp->payload_tok) + tcp->tokens_size,
9198 &tcp->payload_tok))
9199 return -ENOBUFS;
9200
Johannes Berge248ad32013-05-16 10:24:28 +02009201 nla_nest_end(msg, nl_tcp);
9202
Johannes Berg2a0e0472013-01-23 22:57:40 +01009203 return 0;
9204}
9205
Luciano Coelho75453cc2015-01-09 14:06:37 +02009206static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9207 struct cfg80211_sched_scan_request *req)
9208{
Avraham Stern3b06d272015-10-12 09:51:34 +03009209 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009210 int i;
9211
9212 if (!req)
9213 return 0;
9214
9215 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9216 if (!nd)
9217 return -ENOBUFS;
9218
Avraham Stern3b06d272015-10-12 09:51:34 +03009219 if (req->n_scan_plans == 1 &&
9220 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9221 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009222 return -ENOBUFS;
9223
Luciano Coelho21fea562015-03-17 16:36:01 +02009224 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9225 return -ENOBUFS;
9226
Luciano Coelho75453cc2015-01-09 14:06:37 +02009227 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9228 if (!freqs)
9229 return -ENOBUFS;
9230
9231 for (i = 0; i < req->n_channels; i++)
9232 nla_put_u32(msg, i, req->channels[i]->center_freq);
9233
9234 nla_nest_end(msg, freqs);
9235
9236 if (req->n_match_sets) {
9237 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9238 for (i = 0; i < req->n_match_sets; i++) {
9239 match = nla_nest_start(msg, i);
9240 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9241 req->match_sets[i].ssid.ssid_len,
9242 req->match_sets[i].ssid.ssid);
9243 nla_nest_end(msg, match);
9244 }
9245 nla_nest_end(msg, matches);
9246 }
9247
Avraham Stern3b06d272015-10-12 09:51:34 +03009248 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9249 if (!scan_plans)
9250 return -ENOBUFS;
9251
9252 for (i = 0; i < req->n_scan_plans; i++) {
9253 scan_plan = nla_nest_start(msg, i + 1);
9254 if (!scan_plan ||
9255 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9256 req->scan_plans[i].interval) ||
9257 (req->scan_plans[i].iterations &&
9258 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9259 req->scan_plans[i].iterations)))
9260 return -ENOBUFS;
9261 nla_nest_end(msg, scan_plan);
9262 }
9263 nla_nest_end(msg, scan_plans);
9264
Luciano Coelho75453cc2015-01-09 14:06:37 +02009265 nla_nest_end(msg, nd);
9266
9267 return 0;
9268}
9269
Johannes Bergff1b6e62011-05-04 15:37:28 +02009270static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9271{
9272 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9273 struct sk_buff *msg;
9274 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009275 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009276
Johannes Berg964dc9e2013-06-03 17:25:34 +02009277 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009278 return -EOPNOTSUPP;
9279
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009280 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009281 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009282 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9283 rdev->wiphy.wowlan_config->tcp->payload_len +
9284 rdev->wiphy.wowlan_config->tcp->wake_len +
9285 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009286 }
9287
9288 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009289 if (!msg)
9290 return -ENOMEM;
9291
Eric W. Biederman15e47302012-09-07 20:12:54 +00009292 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009293 NL80211_CMD_GET_WOWLAN);
9294 if (!hdr)
9295 goto nla_put_failure;
9296
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009297 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009298 struct nlattr *nl_wowlan;
9299
9300 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9301 if (!nl_wowlan)
9302 goto nla_put_failure;
9303
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009304 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009305 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009306 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009307 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009308 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009309 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009310 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009311 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009312 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009313 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009314 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009315 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009316 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009317 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9318 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009319
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009320 if (nl80211_send_wowlan_patterns(msg, rdev))
9321 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009322
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009323 if (nl80211_send_wowlan_tcp(msg,
9324 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009325 goto nla_put_failure;
9326
Luciano Coelho75453cc2015-01-09 14:06:37 +02009327 if (nl80211_send_wowlan_nd(
9328 msg,
9329 rdev->wiphy.wowlan_config->nd_config))
9330 goto nla_put_failure;
9331
Johannes Bergff1b6e62011-05-04 15:37:28 +02009332 nla_nest_end(msg, nl_wowlan);
9333 }
9334
9335 genlmsg_end(msg, hdr);
9336 return genlmsg_reply(msg, info);
9337
9338nla_put_failure:
9339 nlmsg_free(msg);
9340 return -ENOBUFS;
9341}
9342
Johannes Berg2a0e0472013-01-23 22:57:40 +01009343static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9344 struct nlattr *attr,
9345 struct cfg80211_wowlan *trig)
9346{
9347 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9348 struct cfg80211_wowlan_tcp *cfg;
9349 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9350 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9351 u32 size;
9352 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9353 int err, port;
9354
Johannes Berg964dc9e2013-06-03 17:25:34 +02009355 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009356 return -EINVAL;
9357
9358 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9359 nla_data(attr), nla_len(attr),
9360 nl80211_wowlan_tcp_policy);
9361 if (err)
9362 return err;
9363
9364 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9365 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9366 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9367 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9368 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9369 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9370 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9371 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9372 return -EINVAL;
9373
9374 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009375 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009376 return -EINVAL;
9377
9378 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009379 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009380 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009381 return -EINVAL;
9382
9383 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009384 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009385 return -EINVAL;
9386
9387 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9388 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9389 return -EINVAL;
9390
9391 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9392 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9393
9394 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9395 tokens_size = tokln - sizeof(*tok);
9396
9397 if (!tok->len || tokens_size % tok->len)
9398 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009399 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009400 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009401 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009402 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009403 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009404 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009405 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009406 return -EINVAL;
9407 if (tok->offset + tok->len > data_size)
9408 return -EINVAL;
9409 }
9410
9411 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9412 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009413 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009414 return -EINVAL;
9415 if (seq->len == 0 || seq->len > 4)
9416 return -EINVAL;
9417 if (seq->len + seq->offset > data_size)
9418 return -EINVAL;
9419 }
9420
9421 size = sizeof(*cfg);
9422 size += data_size;
9423 size += wake_size + wake_mask_size;
9424 size += tokens_size;
9425
9426 cfg = kzalloc(size, GFP_KERNEL);
9427 if (!cfg)
9428 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009429 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9430 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009431 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9432 ETH_ALEN);
9433 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9434 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9435 else
9436 port = 0;
9437#ifdef CONFIG_INET
9438 /* allocate a socket and port for it and use it */
9439 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9440 IPPROTO_TCP, &cfg->sock, 1);
9441 if (err) {
9442 kfree(cfg);
9443 return err;
9444 }
9445 if (inet_csk_get_port(cfg->sock->sk, port)) {
9446 sock_release(cfg->sock);
9447 kfree(cfg);
9448 return -EADDRINUSE;
9449 }
9450 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9451#else
9452 if (!port) {
9453 kfree(cfg);
9454 return -EINVAL;
9455 }
9456 cfg->src_port = port;
9457#endif
9458
9459 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9460 cfg->payload_len = data_size;
9461 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9462 memcpy((void *)cfg->payload,
9463 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9464 data_size);
9465 if (seq)
9466 cfg->payload_seq = *seq;
9467 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9468 cfg->wake_len = wake_size;
9469 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9470 memcpy((void *)cfg->wake_data,
9471 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9472 wake_size);
9473 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9474 data_size + wake_size;
9475 memcpy((void *)cfg->wake_mask,
9476 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9477 wake_mask_size);
9478 if (tok) {
9479 cfg->tokens_size = tokens_size;
9480 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9481 }
9482
9483 trig->tcp = cfg;
9484
9485 return 0;
9486}
9487
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009488static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9489 const struct wiphy_wowlan_support *wowlan,
9490 struct nlattr *attr,
9491 struct cfg80211_wowlan *trig)
9492{
9493 struct nlattr **tb;
9494 int err;
9495
9496 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9497 if (!tb)
9498 return -ENOMEM;
9499
9500 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9501 err = -EOPNOTSUPP;
9502 goto out;
9503 }
9504
9505 err = nla_parse(tb, NL80211_ATTR_MAX,
9506 nla_data(attr), nla_len(attr),
9507 nl80211_policy);
9508 if (err)
9509 goto out;
9510
Johannes Bergad2b26a2014-06-12 21:39:05 +02009511 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009512 err = PTR_ERR_OR_ZERO(trig->nd_config);
9513 if (err)
9514 trig->nd_config = NULL;
9515
9516out:
9517 kfree(tb);
9518 return err;
9519}
9520
Johannes Bergff1b6e62011-05-04 15:37:28 +02009521static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9522{
9523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9524 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009525 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009526 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009527 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009528 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009529 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009530 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009531
Johannes Berg964dc9e2013-06-03 17:25:34 +02009532 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009533 return -EOPNOTSUPP;
9534
Johannes Bergae33bd82012-07-12 16:25:02 +02009535 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9536 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009537 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009538 goto set_wakeup;
9539 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009540
9541 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9542 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9543 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9544 nl80211_wowlan_policy);
9545 if (err)
9546 return err;
9547
9548 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9549 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9550 return -EINVAL;
9551 new_triggers.any = true;
9552 }
9553
9554 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9555 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9556 return -EINVAL;
9557 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009558 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009559 }
9560
9561 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9562 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9563 return -EINVAL;
9564 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009565 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009566 }
9567
Johannes Berg77dbbb12011-07-13 10:48:55 +02009568 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9569 return -EINVAL;
9570
9571 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9572 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9573 return -EINVAL;
9574 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009575 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009576 }
9577
9578 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9579 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9580 return -EINVAL;
9581 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009582 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009583 }
9584
9585 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9586 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9587 return -EINVAL;
9588 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009589 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009590 }
9591
9592 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9593 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9594 return -EINVAL;
9595 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009596 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009597 }
9598
Johannes Bergff1b6e62011-05-04 15:37:28 +02009599 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9600 struct nlattr *pat;
9601 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009602 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009603 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009604
Johannes Berg98fc4382015-03-01 09:10:13 +02009605 regular = true;
9606
Johannes Bergff1b6e62011-05-04 15:37:28 +02009607 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9608 rem)
9609 n_patterns++;
9610 if (n_patterns > wowlan->n_patterns)
9611 return -EINVAL;
9612
9613 new_triggers.patterns = kcalloc(n_patterns,
9614 sizeof(new_triggers.patterns[0]),
9615 GFP_KERNEL);
9616 if (!new_triggers.patterns)
9617 return -ENOMEM;
9618
9619 new_triggers.n_patterns = n_patterns;
9620 i = 0;
9621
9622 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9623 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009624 u8 *mask_pat;
9625
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009626 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9627 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009628 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009629 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9630 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009631 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009632 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009633 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009634 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009635 goto error;
9636 if (pat_len > wowlan->pattern_max_len ||
9637 pat_len < wowlan->pattern_min_len)
9638 goto error;
9639
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009640 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009641 pkt_offset = 0;
9642 else
9643 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009644 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009645 if (pkt_offset > wowlan->max_pkt_offset)
9646 goto error;
9647 new_triggers.patterns[i].pkt_offset = pkt_offset;
9648
Johannes Berg922bd802014-05-19 17:59:50 +02009649 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9650 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009651 err = -ENOMEM;
9652 goto error;
9653 }
Johannes Berg922bd802014-05-19 17:59:50 +02009654 new_triggers.patterns[i].mask = mask_pat;
9655 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009656 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009657 mask_pat += mask_len;
9658 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009659 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009660 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009661 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009662 pat_len);
9663 i++;
9664 }
9665 }
9666
Johannes Berg2a0e0472013-01-23 22:57:40 +01009667 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009668 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009669 err = nl80211_parse_wowlan_tcp(
9670 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9671 &new_triggers);
9672 if (err)
9673 goto error;
9674 }
9675
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009676 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009677 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009678 err = nl80211_parse_wowlan_nd(
9679 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9680 &new_triggers);
9681 if (err)
9682 goto error;
9683 }
9684
Johannes Berg98fc4382015-03-01 09:10:13 +02009685 /* The 'any' trigger means the device continues operating more or less
9686 * as in its normal operation mode and wakes up the host on most of the
9687 * normal interrupts (like packet RX, ...)
9688 * It therefore makes little sense to combine with the more constrained
9689 * wakeup trigger modes.
9690 */
9691 if (new_triggers.any && regular) {
9692 err = -EINVAL;
9693 goto error;
9694 }
9695
Johannes Bergae33bd82012-07-12 16:25:02 +02009696 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9697 if (!ntrig) {
9698 err = -ENOMEM;
9699 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009700 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009701 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009702 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009703
Johannes Bergae33bd82012-07-12 16:25:02 +02009704 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009705 if (rdev->ops->set_wakeup &&
9706 prev_enabled != !!rdev->wiphy.wowlan_config)
9707 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009708
Johannes Bergff1b6e62011-05-04 15:37:28 +02009709 return 0;
9710 error:
9711 for (i = 0; i < new_triggers.n_patterns; i++)
9712 kfree(new_triggers.patterns[i].mask);
9713 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009714 if (new_triggers.tcp && new_triggers.tcp->sock)
9715 sock_release(new_triggers.tcp->sock);
9716 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009717 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009718 return err;
9719}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009720#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009721
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009722static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9723 struct cfg80211_registered_device *rdev)
9724{
9725 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9726 int i, j, pat_len;
9727 struct cfg80211_coalesce_rules *rule;
9728
9729 if (!rdev->coalesce->n_rules)
9730 return 0;
9731
9732 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9733 if (!nl_rules)
9734 return -ENOBUFS;
9735
9736 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9737 nl_rule = nla_nest_start(msg, i + 1);
9738 if (!nl_rule)
9739 return -ENOBUFS;
9740
9741 rule = &rdev->coalesce->rules[i];
9742 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9743 rule->delay))
9744 return -ENOBUFS;
9745
9746 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9747 rule->condition))
9748 return -ENOBUFS;
9749
9750 nl_pats = nla_nest_start(msg,
9751 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9752 if (!nl_pats)
9753 return -ENOBUFS;
9754
9755 for (j = 0; j < rule->n_patterns; j++) {
9756 nl_pat = nla_nest_start(msg, j + 1);
9757 if (!nl_pat)
9758 return -ENOBUFS;
9759 pat_len = rule->patterns[j].pattern_len;
9760 if (nla_put(msg, NL80211_PKTPAT_MASK,
9761 DIV_ROUND_UP(pat_len, 8),
9762 rule->patterns[j].mask) ||
9763 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9764 rule->patterns[j].pattern) ||
9765 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9766 rule->patterns[j].pkt_offset))
9767 return -ENOBUFS;
9768 nla_nest_end(msg, nl_pat);
9769 }
9770 nla_nest_end(msg, nl_pats);
9771 nla_nest_end(msg, nl_rule);
9772 }
9773 nla_nest_end(msg, nl_rules);
9774
9775 return 0;
9776}
9777
9778static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9779{
9780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9781 struct sk_buff *msg;
9782 void *hdr;
9783
9784 if (!rdev->wiphy.coalesce)
9785 return -EOPNOTSUPP;
9786
9787 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9788 if (!msg)
9789 return -ENOMEM;
9790
9791 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9792 NL80211_CMD_GET_COALESCE);
9793 if (!hdr)
9794 goto nla_put_failure;
9795
9796 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9797 goto nla_put_failure;
9798
9799 genlmsg_end(msg, hdr);
9800 return genlmsg_reply(msg, info);
9801
9802nla_put_failure:
9803 nlmsg_free(msg);
9804 return -ENOBUFS;
9805}
9806
9807void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9808{
9809 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9810 int i, j;
9811 struct cfg80211_coalesce_rules *rule;
9812
9813 if (!coalesce)
9814 return;
9815
9816 for (i = 0; i < coalesce->n_rules; i++) {
9817 rule = &coalesce->rules[i];
9818 for (j = 0; j < rule->n_patterns; j++)
9819 kfree(rule->patterns[j].mask);
9820 kfree(rule->patterns);
9821 }
9822 kfree(coalesce->rules);
9823 kfree(coalesce);
9824 rdev->coalesce = NULL;
9825}
9826
9827static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9828 struct nlattr *rule,
9829 struct cfg80211_coalesce_rules *new_rule)
9830{
9831 int err, i;
9832 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9833 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9834 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9835 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9836
9837 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9838 nla_len(rule), nl80211_coalesce_policy);
9839 if (err)
9840 return err;
9841
9842 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9843 new_rule->delay =
9844 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9845 if (new_rule->delay > coalesce->max_delay)
9846 return -EINVAL;
9847
9848 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9849 new_rule->condition =
9850 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9851 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9852 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9853 return -EINVAL;
9854
9855 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9856 return -EINVAL;
9857
9858 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9859 rem)
9860 n_patterns++;
9861 if (n_patterns > coalesce->n_patterns)
9862 return -EINVAL;
9863
9864 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9865 GFP_KERNEL);
9866 if (!new_rule->patterns)
9867 return -ENOMEM;
9868
9869 new_rule->n_patterns = n_patterns;
9870 i = 0;
9871
9872 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9873 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009874 u8 *mask_pat;
9875
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009876 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9877 nla_len(pat), NULL);
9878 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9879 !pat_tb[NL80211_PKTPAT_PATTERN])
9880 return -EINVAL;
9881 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9882 mask_len = DIV_ROUND_UP(pat_len, 8);
9883 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9884 return -EINVAL;
9885 if (pat_len > coalesce->pattern_max_len ||
9886 pat_len < coalesce->pattern_min_len)
9887 return -EINVAL;
9888
9889 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9890 pkt_offset = 0;
9891 else
9892 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9893 if (pkt_offset > coalesce->max_pkt_offset)
9894 return -EINVAL;
9895 new_rule->patterns[i].pkt_offset = pkt_offset;
9896
Johannes Berg922bd802014-05-19 17:59:50 +02009897 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9898 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009899 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009900
9901 new_rule->patterns[i].mask = mask_pat;
9902 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9903 mask_len);
9904
9905 mask_pat += mask_len;
9906 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009907 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009908 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9909 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009910 i++;
9911 }
9912
9913 return 0;
9914}
9915
9916static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9917{
9918 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9919 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9920 struct cfg80211_coalesce new_coalesce = {};
9921 struct cfg80211_coalesce *n_coalesce;
9922 int err, rem_rule, n_rules = 0, i, j;
9923 struct nlattr *rule;
9924 struct cfg80211_coalesce_rules *tmp_rule;
9925
9926 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9927 return -EOPNOTSUPP;
9928
9929 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9930 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +03009931 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009932 return 0;
9933 }
9934
9935 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9936 rem_rule)
9937 n_rules++;
9938 if (n_rules > coalesce->n_rules)
9939 return -EINVAL;
9940
9941 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9942 GFP_KERNEL);
9943 if (!new_coalesce.rules)
9944 return -ENOMEM;
9945
9946 new_coalesce.n_rules = n_rules;
9947 i = 0;
9948
9949 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9950 rem_rule) {
9951 err = nl80211_parse_coalesce_rule(rdev, rule,
9952 &new_coalesce.rules[i]);
9953 if (err)
9954 goto error;
9955
9956 i++;
9957 }
9958
Ilan Peera1056b12015-10-22 22:27:46 +03009959 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009960 if (err)
9961 goto error;
9962
9963 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9964 if (!n_coalesce) {
9965 err = -ENOMEM;
9966 goto error;
9967 }
9968 cfg80211_rdev_free_coalesce(rdev);
9969 rdev->coalesce = n_coalesce;
9970
9971 return 0;
9972error:
9973 for (i = 0; i < new_coalesce.n_rules; i++) {
9974 tmp_rule = &new_coalesce.rules[i];
9975 for (j = 0; j < tmp_rule->n_patterns; j++)
9976 kfree(tmp_rule->patterns[j].mask);
9977 kfree(tmp_rule->patterns);
9978 }
9979 kfree(new_coalesce.rules);
9980
9981 return err;
9982}
9983
Johannes Berge5497d72011-07-05 16:35:40 +02009984static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9985{
9986 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9987 struct net_device *dev = info->user_ptr[1];
9988 struct wireless_dev *wdev = dev->ieee80211_ptr;
9989 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9990 struct cfg80211_gtk_rekey_data rekey_data;
9991 int err;
9992
9993 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9994 return -EINVAL;
9995
9996 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9997 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9998 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9999 nl80211_rekey_policy);
10000 if (err)
10001 return err;
10002
10003 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10004 return -ERANGE;
10005 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10006 return -ERANGE;
10007 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10008 return -ERANGE;
10009
Johannes Berg78f686c2014-09-10 22:28:06 +030010010 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10011 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10012 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010013
10014 wdev_lock(wdev);
10015 if (!wdev->current_bss) {
10016 err = -ENOTCONN;
10017 goto out;
10018 }
10019
10020 if (!rdev->ops->set_rekey_data) {
10021 err = -EOPNOTSUPP;
10022 goto out;
10023 }
10024
Hila Gonene35e4d22012-06-27 17:19:42 +030010025 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010026 out:
10027 wdev_unlock(wdev);
10028 return err;
10029}
10030
Johannes Berg28946da2011-11-04 11:18:12 +010010031static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10032 struct genl_info *info)
10033{
10034 struct net_device *dev = info->user_ptr[1];
10035 struct wireless_dev *wdev = dev->ieee80211_ptr;
10036
10037 if (wdev->iftype != NL80211_IFTYPE_AP &&
10038 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10039 return -EINVAL;
10040
Eric W. Biederman15e47302012-09-07 20:12:54 +000010041 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010042 return -EBUSY;
10043
Eric W. Biederman15e47302012-09-07 20:12:54 +000010044 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010045 return 0;
10046}
10047
Johannes Berg7f6cf312011-11-04 11:18:15 +010010048static int nl80211_probe_client(struct sk_buff *skb,
10049 struct genl_info *info)
10050{
10051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10052 struct net_device *dev = info->user_ptr[1];
10053 struct wireless_dev *wdev = dev->ieee80211_ptr;
10054 struct sk_buff *msg;
10055 void *hdr;
10056 const u8 *addr;
10057 u64 cookie;
10058 int err;
10059
10060 if (wdev->iftype != NL80211_IFTYPE_AP &&
10061 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10062 return -EOPNOTSUPP;
10063
10064 if (!info->attrs[NL80211_ATTR_MAC])
10065 return -EINVAL;
10066
10067 if (!rdev->ops->probe_client)
10068 return -EOPNOTSUPP;
10069
10070 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10071 if (!msg)
10072 return -ENOMEM;
10073
Eric W. Biederman15e47302012-09-07 20:12:54 +000010074 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010075 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010076 if (!hdr) {
10077 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010078 goto free_msg;
10079 }
10080
10081 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10082
Hila Gonene35e4d22012-06-27 17:19:42 +030010083 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010084 if (err)
10085 goto free_msg;
10086
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010087 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10088 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010089 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010090
10091 genlmsg_end(msg, hdr);
10092
10093 return genlmsg_reply(msg, info);
10094
10095 nla_put_failure:
10096 err = -ENOBUFS;
10097 free_msg:
10098 nlmsg_free(msg);
10099 return err;
10100}
10101
Johannes Berg5e7602302011-11-04 11:18:17 +010010102static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10103{
10104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010105 struct cfg80211_beacon_registration *reg, *nreg;
10106 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010107
10108 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10109 return -EOPNOTSUPP;
10110
Ben Greear37c73b52012-10-26 14:49:25 -070010111 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10112 if (!nreg)
10113 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010114
Ben Greear37c73b52012-10-26 14:49:25 -070010115 /* First, check if already registered. */
10116 spin_lock_bh(&rdev->beacon_registrations_lock);
10117 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10118 if (reg->nlportid == info->snd_portid) {
10119 rv = -EALREADY;
10120 goto out_err;
10121 }
10122 }
10123 /* Add it to the list */
10124 nreg->nlportid = info->snd_portid;
10125 list_add(&nreg->list, &rdev->beacon_registrations);
10126
10127 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010128
10129 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010130out_err:
10131 spin_unlock_bh(&rdev->beacon_registrations_lock);
10132 kfree(nreg);
10133 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010134}
10135
Johannes Berg98104fde2012-06-16 00:19:54 +020010136static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10137{
10138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10139 struct wireless_dev *wdev = info->user_ptr[1];
10140 int err;
10141
10142 if (!rdev->ops->start_p2p_device)
10143 return -EOPNOTSUPP;
10144
10145 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10146 return -EOPNOTSUPP;
10147
10148 if (wdev->p2p_started)
10149 return 0;
10150
Luciano Coelhob6a55012014-02-27 11:07:21 +020010151 if (rfkill_blocked(rdev->rfkill))
10152 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010153
Johannes Bergeeb126e2012-10-23 15:16:50 +020010154 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010155 if (err)
10156 return err;
10157
10158 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010159 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010160
10161 return 0;
10162}
10163
10164static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10165{
10166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10167 struct wireless_dev *wdev = info->user_ptr[1];
10168
10169 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10170 return -EOPNOTSUPP;
10171
10172 if (!rdev->ops->stop_p2p_device)
10173 return -EOPNOTSUPP;
10174
Johannes Bergf9f47522013-03-19 15:04:07 +010010175 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010176
10177 return 0;
10178}
10179
Johannes Berg3713b4e2013-02-14 16:19:38 +010010180static int nl80211_get_protocol_features(struct sk_buff *skb,
10181 struct genl_info *info)
10182{
10183 void *hdr;
10184 struct sk_buff *msg;
10185
10186 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10187 if (!msg)
10188 return -ENOMEM;
10189
10190 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10191 NL80211_CMD_GET_PROTOCOL_FEATURES);
10192 if (!hdr)
10193 goto nla_put_failure;
10194
10195 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10196 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10197 goto nla_put_failure;
10198
10199 genlmsg_end(msg, hdr);
10200 return genlmsg_reply(msg, info);
10201
10202 nla_put_failure:
10203 kfree_skb(msg);
10204 return -ENOBUFS;
10205}
10206
Jouni Malinen355199e2013-02-27 17:14:27 +020010207static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10208{
10209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10210 struct cfg80211_update_ft_ies_params ft_params;
10211 struct net_device *dev = info->user_ptr[1];
10212
10213 if (!rdev->ops->update_ft_ies)
10214 return -EOPNOTSUPP;
10215
10216 if (!info->attrs[NL80211_ATTR_MDID] ||
10217 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10218 return -EINVAL;
10219
10220 memset(&ft_params, 0, sizeof(ft_params));
10221 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10222 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10223 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10224
10225 return rdev_update_ft_ies(rdev, dev, &ft_params);
10226}
10227
Arend van Spriel5de17982013-04-18 15:49:00 +020010228static int nl80211_crit_protocol_start(struct sk_buff *skb,
10229 struct genl_info *info)
10230{
10231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10232 struct wireless_dev *wdev = info->user_ptr[1];
10233 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10234 u16 duration;
10235 int ret;
10236
10237 if (!rdev->ops->crit_proto_start)
10238 return -EOPNOTSUPP;
10239
10240 if (WARN_ON(!rdev->ops->crit_proto_stop))
10241 return -EINVAL;
10242
10243 if (rdev->crit_proto_nlportid)
10244 return -EBUSY;
10245
10246 /* determine protocol if provided */
10247 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10248 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10249
10250 if (proto >= NUM_NL80211_CRIT_PROTO)
10251 return -EINVAL;
10252
10253 /* timeout must be provided */
10254 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10255 return -EINVAL;
10256
10257 duration =
10258 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10259
10260 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10261 return -ERANGE;
10262
10263 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10264 if (!ret)
10265 rdev->crit_proto_nlportid = info->snd_portid;
10266
10267 return ret;
10268}
10269
10270static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10271 struct genl_info *info)
10272{
10273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10274 struct wireless_dev *wdev = info->user_ptr[1];
10275
10276 if (!rdev->ops->crit_proto_stop)
10277 return -EOPNOTSUPP;
10278
10279 if (rdev->crit_proto_nlportid) {
10280 rdev->crit_proto_nlportid = 0;
10281 rdev_crit_proto_stop(rdev, wdev);
10282 }
10283 return 0;
10284}
10285
Johannes Bergad7e7182013-11-13 13:37:47 +010010286static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10287{
10288 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10289 struct wireless_dev *wdev =
10290 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10291 int i, err;
10292 u32 vid, subcmd;
10293
10294 if (!rdev->wiphy.vendor_commands)
10295 return -EOPNOTSUPP;
10296
10297 if (IS_ERR(wdev)) {
10298 err = PTR_ERR(wdev);
10299 if (err != -EINVAL)
10300 return err;
10301 wdev = NULL;
10302 } else if (wdev->wiphy != &rdev->wiphy) {
10303 return -EINVAL;
10304 }
10305
10306 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10307 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10308 return -EINVAL;
10309
10310 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10311 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10312 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10313 const struct wiphy_vendor_command *vcmd;
10314 void *data = NULL;
10315 int len = 0;
10316
10317 vcmd = &rdev->wiphy.vendor_commands[i];
10318
10319 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10320 continue;
10321
10322 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10323 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10324 if (!wdev)
10325 return -EINVAL;
10326 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10327 !wdev->netdev)
10328 return -EINVAL;
10329
10330 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10331 if (wdev->netdev &&
10332 !netif_running(wdev->netdev))
10333 return -ENETDOWN;
10334 if (!wdev->netdev && !wdev->p2p_started)
10335 return -ENETDOWN;
10336 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010337
10338 if (!vcmd->doit)
10339 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010340 } else {
10341 wdev = NULL;
10342 }
10343
10344 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10345 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10346 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10347 }
10348
10349 rdev->cur_cmd_info = info;
10350 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10351 data, len);
10352 rdev->cur_cmd_info = NULL;
10353 return err;
10354 }
10355
10356 return -EOPNOTSUPP;
10357}
10358
Johannes Berg7bdbe402015-08-15 22:39:49 +030010359static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10360 struct netlink_callback *cb,
10361 struct cfg80211_registered_device **rdev,
10362 struct wireless_dev **wdev)
10363{
10364 u32 vid, subcmd;
10365 unsigned int i;
10366 int vcmd_idx = -1;
10367 int err;
10368 void *data = NULL;
10369 unsigned int data_len = 0;
10370
10371 rtnl_lock();
10372
10373 if (cb->args[0]) {
10374 /* subtract the 1 again here */
10375 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10376 struct wireless_dev *tmp;
10377
10378 if (!wiphy) {
10379 err = -ENODEV;
10380 goto out_unlock;
10381 }
10382 *rdev = wiphy_to_rdev(wiphy);
10383 *wdev = NULL;
10384
10385 if (cb->args[1]) {
10386 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10387 if (tmp->identifier == cb->args[1] - 1) {
10388 *wdev = tmp;
10389 break;
10390 }
10391 }
10392 }
10393
10394 /* keep rtnl locked in successful case */
10395 return 0;
10396 }
10397
10398 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10399 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10400 nl80211_policy);
10401 if (err)
10402 goto out_unlock;
10403
10404 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10405 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10406 err = -EINVAL;
10407 goto out_unlock;
10408 }
10409
10410 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10411 nl80211_fam.attrbuf);
10412 if (IS_ERR(*wdev))
10413 *wdev = NULL;
10414
10415 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10416 nl80211_fam.attrbuf);
10417 if (IS_ERR(*rdev)) {
10418 err = PTR_ERR(*rdev);
10419 goto out_unlock;
10420 }
10421
10422 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10423 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10424
10425 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10426 const struct wiphy_vendor_command *vcmd;
10427
10428 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10429
10430 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10431 continue;
10432
10433 if (!vcmd->dumpit) {
10434 err = -EOPNOTSUPP;
10435 goto out_unlock;
10436 }
10437
10438 vcmd_idx = i;
10439 break;
10440 }
10441
10442 if (vcmd_idx < 0) {
10443 err = -EOPNOTSUPP;
10444 goto out_unlock;
10445 }
10446
10447 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10448 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10449 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10450 }
10451
10452 /* 0 is the first index - add 1 to parse only once */
10453 cb->args[0] = (*rdev)->wiphy_idx + 1;
10454 /* add 1 to know if it was NULL */
10455 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10456 cb->args[2] = vcmd_idx;
10457 cb->args[3] = (unsigned long)data;
10458 cb->args[4] = data_len;
10459
10460 /* keep rtnl locked in successful case */
10461 return 0;
10462 out_unlock:
10463 rtnl_unlock();
10464 return err;
10465}
10466
10467static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10468 struct netlink_callback *cb)
10469{
10470 struct cfg80211_registered_device *rdev;
10471 struct wireless_dev *wdev;
10472 unsigned int vcmd_idx;
10473 const struct wiphy_vendor_command *vcmd;
10474 void *data;
10475 int data_len;
10476 int err;
10477 struct nlattr *vendor_data;
10478
10479 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10480 if (err)
10481 return err;
10482
10483 vcmd_idx = cb->args[2];
10484 data = (void *)cb->args[3];
10485 data_len = cb->args[4];
10486 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10487
10488 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10489 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10490 if (!wdev)
10491 return -EINVAL;
10492 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10493 !wdev->netdev)
10494 return -EINVAL;
10495
10496 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10497 if (wdev->netdev &&
10498 !netif_running(wdev->netdev))
10499 return -ENETDOWN;
10500 if (!wdev->netdev && !wdev->p2p_started)
10501 return -ENETDOWN;
10502 }
10503 }
10504
10505 while (1) {
10506 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10507 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10508 NL80211_CMD_VENDOR);
10509 if (!hdr)
10510 break;
10511
10512 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010513 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10514 wdev_id(wdev),
10515 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010516 genlmsg_cancel(skb, hdr);
10517 break;
10518 }
10519
10520 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10521 if (!vendor_data) {
10522 genlmsg_cancel(skb, hdr);
10523 break;
10524 }
10525
10526 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10527 (unsigned long *)&cb->args[5]);
10528 nla_nest_end(skb, vendor_data);
10529
10530 if (err == -ENOBUFS || err == -ENOENT) {
10531 genlmsg_cancel(skb, hdr);
10532 break;
10533 } else if (err) {
10534 genlmsg_cancel(skb, hdr);
10535 goto out;
10536 }
10537
10538 genlmsg_end(skb, hdr);
10539 }
10540
10541 err = skb->len;
10542 out:
10543 rtnl_unlock();
10544 return err;
10545}
10546
Johannes Bergad7e7182013-11-13 13:37:47 +010010547struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10548 enum nl80211_commands cmd,
10549 enum nl80211_attrs attr,
10550 int approxlen)
10551{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010552 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010553
10554 if (WARN_ON(!rdev->cur_cmd_info))
10555 return NULL;
10556
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010557 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010558 rdev->cur_cmd_info->snd_portid,
10559 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010560 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010561}
10562EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10563
10564int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10565{
10566 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10567 void *hdr = ((void **)skb->cb)[1];
10568 struct nlattr *data = ((void **)skb->cb)[2];
10569
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010570 /* clear CB data for netlink core to own from now on */
10571 memset(skb->cb, 0, sizeof(skb->cb));
10572
Johannes Bergad7e7182013-11-13 13:37:47 +010010573 if (WARN_ON(!rdev->cur_cmd_info)) {
10574 kfree_skb(skb);
10575 return -EINVAL;
10576 }
10577
10578 nla_nest_end(skb, data);
10579 genlmsg_end(skb, hdr);
10580 return genlmsg_reply(skb, rdev->cur_cmd_info);
10581}
10582EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10583
10584
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010585static int nl80211_set_qos_map(struct sk_buff *skb,
10586 struct genl_info *info)
10587{
10588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10589 struct cfg80211_qos_map *qos_map = NULL;
10590 struct net_device *dev = info->user_ptr[1];
10591 u8 *pos, len, num_des, des_len, des;
10592 int ret;
10593
10594 if (!rdev->ops->set_qos_map)
10595 return -EOPNOTSUPP;
10596
10597 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10598 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10599 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10600
10601 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10602 len > IEEE80211_QOS_MAP_LEN_MAX)
10603 return -EINVAL;
10604
10605 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10606 if (!qos_map)
10607 return -ENOMEM;
10608
10609 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10610 if (num_des) {
10611 des_len = num_des *
10612 sizeof(struct cfg80211_dscp_exception);
10613 memcpy(qos_map->dscp_exception, pos, des_len);
10614 qos_map->num_des = num_des;
10615 for (des = 0; des < num_des; des++) {
10616 if (qos_map->dscp_exception[des].up > 7) {
10617 kfree(qos_map);
10618 return -EINVAL;
10619 }
10620 }
10621 pos += des_len;
10622 }
10623 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10624 }
10625
10626 wdev_lock(dev->ieee80211_ptr);
10627 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10628 if (!ret)
10629 ret = rdev_set_qos_map(rdev, dev, qos_map);
10630 wdev_unlock(dev->ieee80211_ptr);
10631
10632 kfree(qos_map);
10633 return ret;
10634}
10635
Johannes Berg960d01a2014-09-09 22:55:35 +030010636static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10637{
10638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10639 struct net_device *dev = info->user_ptr[1];
10640 struct wireless_dev *wdev = dev->ieee80211_ptr;
10641 const u8 *peer;
10642 u8 tsid, up;
10643 u16 admitted_time = 0;
10644 int err;
10645
Johannes Berg723e73a2014-10-22 09:25:06 +020010646 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010647 return -EOPNOTSUPP;
10648
10649 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10650 !info->attrs[NL80211_ATTR_USER_PRIO])
10651 return -EINVAL;
10652
10653 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10654 if (tsid >= IEEE80211_NUM_TIDS)
10655 return -EINVAL;
10656
10657 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10658 if (up >= IEEE80211_NUM_UPS)
10659 return -EINVAL;
10660
10661 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010662 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010663 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010664 * need more attributes for that (e.g. BA session requirement);
10665 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010666 */
10667 return -EINVAL;
10668 }
10669
10670 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10671
10672 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10673 admitted_time =
10674 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10675 if (!admitted_time)
10676 return -EINVAL;
10677 }
10678
10679 wdev_lock(wdev);
10680 switch (wdev->iftype) {
10681 case NL80211_IFTYPE_STATION:
10682 case NL80211_IFTYPE_P2P_CLIENT:
10683 if (wdev->current_bss)
10684 break;
10685 err = -ENOTCONN;
10686 goto out;
10687 default:
10688 err = -EOPNOTSUPP;
10689 goto out;
10690 }
10691
10692 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10693
10694 out:
10695 wdev_unlock(wdev);
10696 return err;
10697}
10698
10699static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10700{
10701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10702 struct net_device *dev = info->user_ptr[1];
10703 struct wireless_dev *wdev = dev->ieee80211_ptr;
10704 const u8 *peer;
10705 u8 tsid;
10706 int err;
10707
10708 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10709 return -EINVAL;
10710
10711 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10712 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10713
10714 wdev_lock(wdev);
10715 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10716 wdev_unlock(wdev);
10717
10718 return err;
10719}
10720
Arik Nemtsov1057d352014-11-19 12:54:26 +020010721static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10722 struct genl_info *info)
10723{
10724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10725 struct net_device *dev = info->user_ptr[1];
10726 struct wireless_dev *wdev = dev->ieee80211_ptr;
10727 struct cfg80211_chan_def chandef = {};
10728 const u8 *addr;
10729 u8 oper_class;
10730 int err;
10731
10732 if (!rdev->ops->tdls_channel_switch ||
10733 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10734 return -EOPNOTSUPP;
10735
10736 switch (dev->ieee80211_ptr->iftype) {
10737 case NL80211_IFTYPE_STATION:
10738 case NL80211_IFTYPE_P2P_CLIENT:
10739 break;
10740 default:
10741 return -EOPNOTSUPP;
10742 }
10743
10744 if (!info->attrs[NL80211_ATTR_MAC] ||
10745 !info->attrs[NL80211_ATTR_OPER_CLASS])
10746 return -EINVAL;
10747
10748 err = nl80211_parse_chandef(rdev, info, &chandef);
10749 if (err)
10750 return err;
10751
10752 /*
10753 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10754 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10755 * specification is not defined for them.
10756 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010757 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010758 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10759 chandef.width != NL80211_CHAN_WIDTH_20)
10760 return -EINVAL;
10761
10762 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010763 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10764 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010765 return -EINVAL;
10766
10767 /* don't allow switching to DFS channels */
10768 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10769 return -EINVAL;
10770
10771 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10772 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10773
10774 wdev_lock(wdev);
10775 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10776 wdev_unlock(wdev);
10777
10778 return err;
10779}
10780
10781static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10782 struct genl_info *info)
10783{
10784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10785 struct net_device *dev = info->user_ptr[1];
10786 struct wireless_dev *wdev = dev->ieee80211_ptr;
10787 const u8 *addr;
10788
10789 if (!rdev->ops->tdls_channel_switch ||
10790 !rdev->ops->tdls_cancel_channel_switch ||
10791 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10792 return -EOPNOTSUPP;
10793
10794 switch (dev->ieee80211_ptr->iftype) {
10795 case NL80211_IFTYPE_STATION:
10796 case NL80211_IFTYPE_P2P_CLIENT:
10797 break;
10798 default:
10799 return -EOPNOTSUPP;
10800 }
10801
10802 if (!info->attrs[NL80211_ATTR_MAC])
10803 return -EINVAL;
10804
10805 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10806
10807 wdev_lock(wdev);
10808 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10809 wdev_unlock(wdev);
10810
10811 return 0;
10812}
10813
Johannes Berg4c476992010-10-04 21:36:35 +020010814#define NL80211_FLAG_NEED_WIPHY 0x01
10815#define NL80211_FLAG_NEED_NETDEV 0x02
10816#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010817#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10818#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10819 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010820#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010821/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010822#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10823 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010824#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010825
Johannes Bergf84f7712013-11-14 17:14:45 +010010826static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010827 struct genl_info *info)
10828{
10829 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010830 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010831 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010832 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10833
10834 if (rtnl)
10835 rtnl_lock();
10836
10837 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010838 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010839 if (IS_ERR(rdev)) {
10840 if (rtnl)
10841 rtnl_unlock();
10842 return PTR_ERR(rdev);
10843 }
10844 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010845 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10846 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010847 ASSERT_RTNL();
10848
Johannes Berg89a54e42012-06-15 14:33:17 +020010849 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10850 info->attrs);
10851 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010852 if (rtnl)
10853 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010854 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010855 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010856
Johannes Berg89a54e42012-06-15 14:33:17 +020010857 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010858 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010859
Johannes Berg1bf614e2012-06-15 15:23:36 +020010860 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10861 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010862 if (rtnl)
10863 rtnl_unlock();
10864 return -EINVAL;
10865 }
10866
10867 info->user_ptr[1] = dev;
10868 } else {
10869 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010870 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010871
Johannes Berg1bf614e2012-06-15 15:23:36 +020010872 if (dev) {
10873 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10874 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010875 if (rtnl)
10876 rtnl_unlock();
10877 return -ENETDOWN;
10878 }
10879
10880 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010881 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10882 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010883 if (rtnl)
10884 rtnl_unlock();
10885 return -ENETDOWN;
10886 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010887 }
10888
Johannes Berg4c476992010-10-04 21:36:35 +020010889 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010890 }
10891
10892 return 0;
10893}
10894
Johannes Bergf84f7712013-11-14 17:14:45 +010010895static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010896 struct genl_info *info)
10897{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010898 if (info->user_ptr[1]) {
10899 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10900 struct wireless_dev *wdev = info->user_ptr[1];
10901
10902 if (wdev->netdev)
10903 dev_put(wdev->netdev);
10904 } else {
10905 dev_put(info->user_ptr[1]);
10906 }
10907 }
Johannes Berg5393b912014-09-10 15:00:16 +030010908
Johannes Berg4c476992010-10-04 21:36:35 +020010909 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10910 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010911
10912 /* If needed, clear the netlink message payload from the SKB
10913 * as it might contain key data that shouldn't stick around on
10914 * the heap after the SKB is freed. The netlink message header
10915 * is still needed for further processing, so leave it intact.
10916 */
10917 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10918 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10919
10920 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10921 }
Johannes Berg4c476992010-10-04 21:36:35 +020010922}
10923
Johannes Berg4534de82013-11-14 17:14:46 +010010924static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010925 {
10926 .cmd = NL80211_CMD_GET_WIPHY,
10927 .doit = nl80211_get_wiphy,
10928 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010929 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010930 .policy = nl80211_policy,
10931 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010932 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10933 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010934 },
10935 {
10936 .cmd = NL80211_CMD_SET_WIPHY,
10937 .doit = nl80211_set_wiphy,
10938 .policy = nl80211_policy,
10939 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010940 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010941 },
10942 {
10943 .cmd = NL80211_CMD_GET_INTERFACE,
10944 .doit = nl80211_get_interface,
10945 .dumpit = nl80211_dump_interface,
10946 .policy = nl80211_policy,
10947 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010948 .internal_flags = NL80211_FLAG_NEED_WDEV |
10949 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010950 },
10951 {
10952 .cmd = NL80211_CMD_SET_INTERFACE,
10953 .doit = nl80211_set_interface,
10954 .policy = nl80211_policy,
10955 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010956 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10957 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010958 },
10959 {
10960 .cmd = NL80211_CMD_NEW_INTERFACE,
10961 .doit = nl80211_new_interface,
10962 .policy = nl80211_policy,
10963 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010964 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10965 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010966 },
10967 {
10968 .cmd = NL80211_CMD_DEL_INTERFACE,
10969 .doit = nl80211_del_interface,
10970 .policy = nl80211_policy,
10971 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010972 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010973 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010974 },
Johannes Berg41ade002007-12-19 02:03:29 +010010975 {
10976 .cmd = NL80211_CMD_GET_KEY,
10977 .doit = nl80211_get_key,
10978 .policy = nl80211_policy,
10979 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010981 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010982 },
10983 {
10984 .cmd = NL80211_CMD_SET_KEY,
10985 .doit = nl80211_set_key,
10986 .policy = nl80211_policy,
10987 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010988 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010989 NL80211_FLAG_NEED_RTNL |
10990 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010991 },
10992 {
10993 .cmd = NL80211_CMD_NEW_KEY,
10994 .doit = nl80211_new_key,
10995 .policy = nl80211_policy,
10996 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010997 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010998 NL80211_FLAG_NEED_RTNL |
10999 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011000 },
11001 {
11002 .cmd = NL80211_CMD_DEL_KEY,
11003 .doit = nl80211_del_key,
11004 .policy = nl80211_policy,
11005 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011006 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011007 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011008 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011009 {
11010 .cmd = NL80211_CMD_SET_BEACON,
11011 .policy = nl80211_policy,
11012 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011013 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011014 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011015 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011016 },
11017 {
Johannes Berg88600202012-02-13 15:17:18 +010011018 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011019 .policy = nl80211_policy,
11020 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011021 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011022 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011023 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011024 },
11025 {
Johannes Berg88600202012-02-13 15:17:18 +010011026 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011027 .policy = nl80211_policy,
11028 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011029 .doit = nl80211_stop_ap,
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 Berged1b6cc2007-12-19 02:03:32 +010011032 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011033 {
11034 .cmd = NL80211_CMD_GET_STATION,
11035 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011036 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011037 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011038 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11039 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011040 },
11041 {
11042 .cmd = NL80211_CMD_SET_STATION,
11043 .doit = nl80211_set_station,
11044 .policy = nl80211_policy,
11045 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011046 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011047 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011048 },
11049 {
11050 .cmd = NL80211_CMD_NEW_STATION,
11051 .doit = nl80211_new_station,
11052 .policy = nl80211_policy,
11053 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011054 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011055 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011056 },
11057 {
11058 .cmd = NL80211_CMD_DEL_STATION,
11059 .doit = nl80211_del_station,
11060 .policy = nl80211_policy,
11061 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011062 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011063 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011064 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011065 {
11066 .cmd = NL80211_CMD_GET_MPATH,
11067 .doit = nl80211_get_mpath,
11068 .dumpit = nl80211_dump_mpath,
11069 .policy = nl80211_policy,
11070 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011071 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011072 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011073 },
11074 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011075 .cmd = NL80211_CMD_GET_MPP,
11076 .doit = nl80211_get_mpp,
11077 .dumpit = nl80211_dump_mpp,
11078 .policy = nl80211_policy,
11079 .flags = GENL_ADMIN_PERM,
11080 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11081 NL80211_FLAG_NEED_RTNL,
11082 },
11083 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011084 .cmd = NL80211_CMD_SET_MPATH,
11085 .doit = nl80211_set_mpath,
11086 .policy = nl80211_policy,
11087 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011088 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011089 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011090 },
11091 {
11092 .cmd = NL80211_CMD_NEW_MPATH,
11093 .doit = nl80211_new_mpath,
11094 .policy = nl80211_policy,
11095 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011097 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011098 },
11099 {
11100 .cmd = NL80211_CMD_DEL_MPATH,
11101 .doit = nl80211_del_mpath,
11102 .policy = nl80211_policy,
11103 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011105 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011106 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011107 {
11108 .cmd = NL80211_CMD_SET_BSS,
11109 .doit = nl80211_set_bss,
11110 .policy = nl80211_policy,
11111 .flags = GENL_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,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011114 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011115 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011116 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011117 .doit = nl80211_get_reg_do,
11118 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011119 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011120 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011121 /* can be retrieved by unprivileged users */
11122 },
Johannes Bergb6863032015-10-15 09:25:18 +020011123#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011124 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011125 .cmd = NL80211_CMD_SET_REG,
11126 .doit = nl80211_set_reg,
11127 .policy = nl80211_policy,
11128 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011129 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011130 },
Johannes Bergb6863032015-10-15 09:25:18 +020011131#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011132 {
11133 .cmd = NL80211_CMD_REQ_SET_REG,
11134 .doit = nl80211_req_set_reg,
11135 .policy = nl80211_policy,
11136 .flags = GENL_ADMIN_PERM,
11137 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011138 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011139 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11140 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011141 .policy = nl80211_policy,
11142 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011143 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011144 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011145 },
11146 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011147 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11148 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011149 .policy = nl80211_policy,
11150 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011152 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011153 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011154 {
Johannes Berg2a519312009-02-10 21:25:55 +010011155 .cmd = NL80211_CMD_TRIGGER_SCAN,
11156 .doit = nl80211_trigger_scan,
11157 .policy = nl80211_policy,
11158 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011159 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011160 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011161 },
11162 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011163 .cmd = NL80211_CMD_ABORT_SCAN,
11164 .doit = nl80211_abort_scan,
11165 .policy = nl80211_policy,
11166 .flags = GENL_ADMIN_PERM,
11167 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11168 NL80211_FLAG_NEED_RTNL,
11169 },
11170 {
Johannes Berg2a519312009-02-10 21:25:55 +010011171 .cmd = NL80211_CMD_GET_SCAN,
11172 .policy = nl80211_policy,
11173 .dumpit = nl80211_dump_scan,
11174 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011175 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011176 .cmd = NL80211_CMD_START_SCHED_SCAN,
11177 .doit = nl80211_start_sched_scan,
11178 .policy = nl80211_policy,
11179 .flags = GENL_ADMIN_PERM,
11180 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11181 NL80211_FLAG_NEED_RTNL,
11182 },
11183 {
11184 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11185 .doit = nl80211_stop_sched_scan,
11186 .policy = nl80211_policy,
11187 .flags = GENL_ADMIN_PERM,
11188 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11189 NL80211_FLAG_NEED_RTNL,
11190 },
11191 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011192 .cmd = NL80211_CMD_AUTHENTICATE,
11193 .doit = nl80211_authenticate,
11194 .policy = nl80211_policy,
11195 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011197 NL80211_FLAG_NEED_RTNL |
11198 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011199 },
11200 {
11201 .cmd = NL80211_CMD_ASSOCIATE,
11202 .doit = nl80211_associate,
11203 .policy = nl80211_policy,
11204 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011205 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011206 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011207 },
11208 {
11209 .cmd = NL80211_CMD_DEAUTHENTICATE,
11210 .doit = nl80211_deauthenticate,
11211 .policy = nl80211_policy,
11212 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011214 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011215 },
11216 {
11217 .cmd = NL80211_CMD_DISASSOCIATE,
11218 .doit = nl80211_disassociate,
11219 .policy = nl80211_policy,
11220 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011222 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011223 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011224 {
11225 .cmd = NL80211_CMD_JOIN_IBSS,
11226 .doit = nl80211_join_ibss,
11227 .policy = nl80211_policy,
11228 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011230 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011231 },
11232 {
11233 .cmd = NL80211_CMD_LEAVE_IBSS,
11234 .doit = nl80211_leave_ibss,
11235 .policy = nl80211_policy,
11236 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011238 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011239 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011240#ifdef CONFIG_NL80211_TESTMODE
11241 {
11242 .cmd = NL80211_CMD_TESTMODE,
11243 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011244 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011245 .policy = nl80211_policy,
11246 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011247 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11248 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011249 },
11250#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011251 {
11252 .cmd = NL80211_CMD_CONNECT,
11253 .doit = nl80211_connect,
11254 .policy = nl80211_policy,
11255 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011256 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011257 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011258 },
11259 {
11260 .cmd = NL80211_CMD_DISCONNECT,
11261 .doit = nl80211_disconnect,
11262 .policy = nl80211_policy,
11263 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011264 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011265 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011266 },
Johannes Berg463d0182009-07-14 00:33:35 +020011267 {
11268 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11269 .doit = nl80211_wiphy_netns,
11270 .policy = nl80211_policy,
11271 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011272 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11273 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011274 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011275 {
11276 .cmd = NL80211_CMD_GET_SURVEY,
11277 .policy = nl80211_policy,
11278 .dumpit = nl80211_dump_survey,
11279 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011280 {
11281 .cmd = NL80211_CMD_SET_PMKSA,
11282 .doit = nl80211_setdel_pmksa,
11283 .policy = nl80211_policy,
11284 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011285 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011286 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011287 },
11288 {
11289 .cmd = NL80211_CMD_DEL_PMKSA,
11290 .doit = nl80211_setdel_pmksa,
11291 .policy = nl80211_policy,
11292 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011293 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011294 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011295 },
11296 {
11297 .cmd = NL80211_CMD_FLUSH_PMKSA,
11298 .doit = nl80211_flush_pmksa,
11299 .policy = nl80211_policy,
11300 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011301 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011302 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011303 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011304 {
11305 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11306 .doit = nl80211_remain_on_channel,
11307 .policy = nl80211_policy,
11308 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011309 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011310 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011311 },
11312 {
11313 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11314 .doit = nl80211_cancel_remain_on_channel,
11315 .policy = nl80211_policy,
11316 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011317 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011318 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011319 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011320 {
11321 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11322 .doit = nl80211_set_tx_bitrate_mask,
11323 .policy = nl80211_policy,
11324 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011325 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11326 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011327 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011328 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011329 .cmd = NL80211_CMD_REGISTER_FRAME,
11330 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011331 .policy = nl80211_policy,
11332 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011333 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011334 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011335 },
11336 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011337 .cmd = NL80211_CMD_FRAME,
11338 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011339 .policy = nl80211_policy,
11340 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011341 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011342 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011343 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011344 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011345 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11346 .doit = nl80211_tx_mgmt_cancel_wait,
11347 .policy = nl80211_policy,
11348 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011349 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011350 NL80211_FLAG_NEED_RTNL,
11351 },
11352 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011353 .cmd = NL80211_CMD_SET_POWER_SAVE,
11354 .doit = nl80211_set_power_save,
11355 .policy = nl80211_policy,
11356 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011357 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11358 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011359 },
11360 {
11361 .cmd = NL80211_CMD_GET_POWER_SAVE,
11362 .doit = nl80211_get_power_save,
11363 .policy = nl80211_policy,
11364 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011365 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11366 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011367 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011368 {
11369 .cmd = NL80211_CMD_SET_CQM,
11370 .doit = nl80211_set_cqm,
11371 .policy = nl80211_policy,
11372 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011373 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11374 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011375 },
Johannes Bergf444de02010-05-05 15:25:02 +020011376 {
11377 .cmd = NL80211_CMD_SET_CHANNEL,
11378 .doit = nl80211_set_channel,
11379 .policy = nl80211_policy,
11380 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011381 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11382 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011383 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011384 {
11385 .cmd = NL80211_CMD_SET_WDS_PEER,
11386 .doit = nl80211_set_wds_peer,
11387 .policy = nl80211_policy,
11388 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011389 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11390 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011391 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011392 {
11393 .cmd = NL80211_CMD_JOIN_MESH,
11394 .doit = nl80211_join_mesh,
11395 .policy = nl80211_policy,
11396 .flags = GENL_ADMIN_PERM,
11397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11398 NL80211_FLAG_NEED_RTNL,
11399 },
11400 {
11401 .cmd = NL80211_CMD_LEAVE_MESH,
11402 .doit = nl80211_leave_mesh,
11403 .policy = nl80211_policy,
11404 .flags = GENL_ADMIN_PERM,
11405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11406 NL80211_FLAG_NEED_RTNL,
11407 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011408 {
11409 .cmd = NL80211_CMD_JOIN_OCB,
11410 .doit = nl80211_join_ocb,
11411 .policy = nl80211_policy,
11412 .flags = GENL_ADMIN_PERM,
11413 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11414 NL80211_FLAG_NEED_RTNL,
11415 },
11416 {
11417 .cmd = NL80211_CMD_LEAVE_OCB,
11418 .doit = nl80211_leave_ocb,
11419 .policy = nl80211_policy,
11420 .flags = GENL_ADMIN_PERM,
11421 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11422 NL80211_FLAG_NEED_RTNL,
11423 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011424#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011425 {
11426 .cmd = NL80211_CMD_GET_WOWLAN,
11427 .doit = nl80211_get_wowlan,
11428 .policy = nl80211_policy,
11429 /* can be retrieved by unprivileged users */
11430 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11431 NL80211_FLAG_NEED_RTNL,
11432 },
11433 {
11434 .cmd = NL80211_CMD_SET_WOWLAN,
11435 .doit = nl80211_set_wowlan,
11436 .policy = nl80211_policy,
11437 .flags = GENL_ADMIN_PERM,
11438 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11439 NL80211_FLAG_NEED_RTNL,
11440 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011441#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011442 {
11443 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11444 .doit = nl80211_set_rekey_data,
11445 .policy = nl80211_policy,
11446 .flags = GENL_ADMIN_PERM,
11447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011448 NL80211_FLAG_NEED_RTNL |
11449 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011450 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011451 {
11452 .cmd = NL80211_CMD_TDLS_MGMT,
11453 .doit = nl80211_tdls_mgmt,
11454 .policy = nl80211_policy,
11455 .flags = GENL_ADMIN_PERM,
11456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11457 NL80211_FLAG_NEED_RTNL,
11458 },
11459 {
11460 .cmd = NL80211_CMD_TDLS_OPER,
11461 .doit = nl80211_tdls_oper,
11462 .policy = nl80211_policy,
11463 .flags = GENL_ADMIN_PERM,
11464 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11465 NL80211_FLAG_NEED_RTNL,
11466 },
Johannes Berg28946da2011-11-04 11:18:12 +010011467 {
11468 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11469 .doit = nl80211_register_unexpected_frame,
11470 .policy = nl80211_policy,
11471 .flags = GENL_ADMIN_PERM,
11472 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11473 NL80211_FLAG_NEED_RTNL,
11474 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011475 {
11476 .cmd = NL80211_CMD_PROBE_CLIENT,
11477 .doit = nl80211_probe_client,
11478 .policy = nl80211_policy,
11479 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011481 NL80211_FLAG_NEED_RTNL,
11482 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011483 {
11484 .cmd = NL80211_CMD_REGISTER_BEACONS,
11485 .doit = nl80211_register_beacons,
11486 .policy = nl80211_policy,
11487 .flags = GENL_ADMIN_PERM,
11488 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11489 NL80211_FLAG_NEED_RTNL,
11490 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011491 {
11492 .cmd = NL80211_CMD_SET_NOACK_MAP,
11493 .doit = nl80211_set_noack_map,
11494 .policy = nl80211_policy,
11495 .flags = GENL_ADMIN_PERM,
11496 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11497 NL80211_FLAG_NEED_RTNL,
11498 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011499 {
11500 .cmd = NL80211_CMD_START_P2P_DEVICE,
11501 .doit = nl80211_start_p2p_device,
11502 .policy = nl80211_policy,
11503 .flags = GENL_ADMIN_PERM,
11504 .internal_flags = NL80211_FLAG_NEED_WDEV |
11505 NL80211_FLAG_NEED_RTNL,
11506 },
11507 {
11508 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11509 .doit = nl80211_stop_p2p_device,
11510 .policy = nl80211_policy,
11511 .flags = GENL_ADMIN_PERM,
11512 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11513 NL80211_FLAG_NEED_RTNL,
11514 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011515 {
11516 .cmd = NL80211_CMD_SET_MCAST_RATE,
11517 .doit = nl80211_set_mcast_rate,
11518 .policy = nl80211_policy,
11519 .flags = GENL_ADMIN_PERM,
11520 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11521 NL80211_FLAG_NEED_RTNL,
11522 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011523 {
11524 .cmd = NL80211_CMD_SET_MAC_ACL,
11525 .doit = nl80211_set_mac_acl,
11526 .policy = nl80211_policy,
11527 .flags = GENL_ADMIN_PERM,
11528 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11529 NL80211_FLAG_NEED_RTNL,
11530 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011531 {
11532 .cmd = NL80211_CMD_RADAR_DETECT,
11533 .doit = nl80211_start_radar_detection,
11534 .policy = nl80211_policy,
11535 .flags = GENL_ADMIN_PERM,
11536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11537 NL80211_FLAG_NEED_RTNL,
11538 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011539 {
11540 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11541 .doit = nl80211_get_protocol_features,
11542 .policy = nl80211_policy,
11543 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011544 {
11545 .cmd = NL80211_CMD_UPDATE_FT_IES,
11546 .doit = nl80211_update_ft_ies,
11547 .policy = nl80211_policy,
11548 .flags = GENL_ADMIN_PERM,
11549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11550 NL80211_FLAG_NEED_RTNL,
11551 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011552 {
11553 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11554 .doit = nl80211_crit_protocol_start,
11555 .policy = nl80211_policy,
11556 .flags = GENL_ADMIN_PERM,
11557 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11558 NL80211_FLAG_NEED_RTNL,
11559 },
11560 {
11561 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11562 .doit = nl80211_crit_protocol_stop,
11563 .policy = nl80211_policy,
11564 .flags = GENL_ADMIN_PERM,
11565 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11566 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011567 },
11568 {
11569 .cmd = NL80211_CMD_GET_COALESCE,
11570 .doit = nl80211_get_coalesce,
11571 .policy = nl80211_policy,
11572 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11573 NL80211_FLAG_NEED_RTNL,
11574 },
11575 {
11576 .cmd = NL80211_CMD_SET_COALESCE,
11577 .doit = nl80211_set_coalesce,
11578 .policy = nl80211_policy,
11579 .flags = GENL_ADMIN_PERM,
11580 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11581 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011582 },
11583 {
11584 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11585 .doit = nl80211_channel_switch,
11586 .policy = nl80211_policy,
11587 .flags = GENL_ADMIN_PERM,
11588 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11589 NL80211_FLAG_NEED_RTNL,
11590 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011591 {
11592 .cmd = NL80211_CMD_VENDOR,
11593 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011594 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011595 .policy = nl80211_policy,
11596 .flags = GENL_ADMIN_PERM,
11597 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11598 NL80211_FLAG_NEED_RTNL,
11599 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011600 {
11601 .cmd = NL80211_CMD_SET_QOS_MAP,
11602 .doit = nl80211_set_qos_map,
11603 .policy = nl80211_policy,
11604 .flags = GENL_ADMIN_PERM,
11605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11606 NL80211_FLAG_NEED_RTNL,
11607 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011608 {
11609 .cmd = NL80211_CMD_ADD_TX_TS,
11610 .doit = nl80211_add_tx_ts,
11611 .policy = nl80211_policy,
11612 .flags = GENL_ADMIN_PERM,
11613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11614 NL80211_FLAG_NEED_RTNL,
11615 },
11616 {
11617 .cmd = NL80211_CMD_DEL_TX_TS,
11618 .doit = nl80211_del_tx_ts,
11619 .policy = nl80211_policy,
11620 .flags = GENL_ADMIN_PERM,
11621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11622 NL80211_FLAG_NEED_RTNL,
11623 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011624 {
11625 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11626 .doit = nl80211_tdls_channel_switch,
11627 .policy = nl80211_policy,
11628 .flags = GENL_ADMIN_PERM,
11629 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11630 NL80211_FLAG_NEED_RTNL,
11631 },
11632 {
11633 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11634 .doit = nl80211_tdls_cancel_channel_switch,
11635 .policy = nl80211_policy,
11636 .flags = GENL_ADMIN_PERM,
11637 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11638 NL80211_FLAG_NEED_RTNL,
11639 },
Johannes Berg55682962007-09-20 13:09:35 -040011640};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011641
Johannes Berg55682962007-09-20 13:09:35 -040011642/* notification functions */
11643
Johannes Berg3bb20552014-05-26 13:52:25 +020011644void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11645 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011646{
11647 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011648 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011649
Johannes Berg3bb20552014-05-26 13:52:25 +020011650 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11651 cmd != NL80211_CMD_DEL_WIPHY);
11652
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011653 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011654 if (!msg)
11655 return;
11656
Johannes Berg3bb20552014-05-26 13:52:25 +020011657 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011658 nlmsg_free(msg);
11659 return;
11660 }
11661
Johannes Berg68eb5502013-11-19 15:19:38 +010011662 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011663 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011664}
11665
Johannes Berg362a4152009-05-24 16:43:15 +020011666static int nl80211_add_scan_req(struct sk_buff *msg,
11667 struct cfg80211_registered_device *rdev)
11668{
11669 struct cfg80211_scan_request *req = rdev->scan_req;
11670 struct nlattr *nest;
11671 int i;
11672
11673 if (WARN_ON(!req))
11674 return 0;
11675
11676 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11677 if (!nest)
11678 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011679 for (i = 0; i < req->n_ssids; i++) {
11680 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11681 goto nla_put_failure;
11682 }
Johannes Berg362a4152009-05-24 16:43:15 +020011683 nla_nest_end(msg, nest);
11684
11685 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11686 if (!nest)
11687 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011688 for (i = 0; i < req->n_channels; i++) {
11689 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11690 goto nla_put_failure;
11691 }
Johannes Berg362a4152009-05-24 16:43:15 +020011692 nla_nest_end(msg, nest);
11693
David S. Miller9360ffd2012-03-29 04:41:26 -040011694 if (req->ie &&
11695 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11696 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011697
Johannes Bergae917c92013-10-25 11:05:22 +020011698 if (req->flags &&
11699 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11700 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011701
Johannes Berg362a4152009-05-24 16:43:15 +020011702 return 0;
11703 nla_put_failure:
11704 return -ENOBUFS;
11705}
11706
Johannes Berga538e2d2009-06-16 19:56:42 +020011707static int nl80211_send_scan_msg(struct sk_buff *msg,
11708 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011709 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011710 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011711 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011712{
11713 void *hdr;
11714
Eric W. Biederman15e47302012-09-07 20:12:54 +000011715 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011716 if (!hdr)
11717 return -1;
11718
David S. Miller9360ffd2012-03-29 04:41:26 -040011719 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011720 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11721 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011722 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11723 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011724 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011725
Johannes Berg362a4152009-05-24 16:43:15 +020011726 /* ignore errors and send incomplete event anyway */
11727 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011728
Johannes Berg053c0952015-01-16 22:09:00 +010011729 genlmsg_end(msg, hdr);
11730 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011731
11732 nla_put_failure:
11733 genlmsg_cancel(msg, hdr);
11734 return -EMSGSIZE;
11735}
11736
Luciano Coelho807f8a82011-05-11 17:09:35 +030011737static int
11738nl80211_send_sched_scan_msg(struct sk_buff *msg,
11739 struct cfg80211_registered_device *rdev,
11740 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011741 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011742{
11743 void *hdr;
11744
Eric W. Biederman15e47302012-09-07 20:12:54 +000011745 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011746 if (!hdr)
11747 return -1;
11748
David S. Miller9360ffd2012-03-29 04:41:26 -040011749 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11750 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11751 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011752
Johannes Berg053c0952015-01-16 22:09:00 +010011753 genlmsg_end(msg, hdr);
11754 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011755
11756 nla_put_failure:
11757 genlmsg_cancel(msg, hdr);
11758 return -EMSGSIZE;
11759}
11760
Johannes Berga538e2d2009-06-16 19:56:42 +020011761void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011762 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011763{
11764 struct sk_buff *msg;
11765
Thomas Graf58050fc2012-06-28 03:57:45 +000011766 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011767 if (!msg)
11768 return;
11769
Johannes Bergfd014282012-06-18 19:17:03 +020011770 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011771 NL80211_CMD_TRIGGER_SCAN) < 0) {
11772 nlmsg_free(msg);
11773 return;
11774 }
11775
Johannes Berg68eb5502013-11-19 15:19:38 +010011776 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011777 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011778}
11779
Johannes Bergf9d15d12014-01-22 11:14:19 +020011780struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11781 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011782{
11783 struct sk_buff *msg;
11784
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011785 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011786 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011787 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011788
Johannes Bergfd014282012-06-18 19:17:03 +020011789 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011790 aborted ? NL80211_CMD_SCAN_ABORTED :
11791 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011792 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011793 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011794 }
11795
Johannes Bergf9d15d12014-01-22 11:14:19 +020011796 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011797}
11798
Johannes Bergf9d15d12014-01-22 11:14:19 +020011799void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11800 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011801{
Johannes Berg2a519312009-02-10 21:25:55 +010011802 if (!msg)
11803 return;
11804
Johannes Berg68eb5502013-11-19 15:19:38 +010011805 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011806 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011807}
11808
Luciano Coelho807f8a82011-05-11 17:09:35 +030011809void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11810 struct net_device *netdev)
11811{
11812 struct sk_buff *msg;
11813
11814 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11815 if (!msg)
11816 return;
11817
11818 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11819 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11820 nlmsg_free(msg);
11821 return;
11822 }
11823
Johannes Berg68eb5502013-11-19 15:19:38 +010011824 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011825 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011826}
11827
11828void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11829 struct net_device *netdev, u32 cmd)
11830{
11831 struct sk_buff *msg;
11832
Thomas Graf58050fc2012-06-28 03:57:45 +000011833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011834 if (!msg)
11835 return;
11836
11837 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11838 nlmsg_free(msg);
11839 return;
11840 }
11841
Johannes Berg68eb5502013-11-19 15:19:38 +010011842 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011843 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011844}
11845
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011846static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11847 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011848{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011849 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011850 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11851 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011852
David S. Miller9360ffd2012-03-29 04:41:26 -040011853 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11854 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11855 NL80211_REGDOM_TYPE_WORLD))
11856 goto nla_put_failure;
11857 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11858 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11859 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11860 goto nla_put_failure;
11861 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11862 request->intersect) {
11863 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11864 NL80211_REGDOM_TYPE_INTERSECTION))
11865 goto nla_put_failure;
11866 } else {
11867 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11868 NL80211_REGDOM_TYPE_COUNTRY) ||
11869 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11870 request->alpha2))
11871 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011872 }
11873
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011874 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11875 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11876
11877 if (wiphy &&
11878 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11879 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011880
11881 if (wiphy &&
11882 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11883 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11884 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011885 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011886
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011887 return true;
11888
11889nla_put_failure:
11890 return false;
11891}
11892
11893/*
11894 * This can happen on global regulatory changes or device specific settings
11895 * based on custom regulatory domains.
11896 */
11897void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11898 struct regulatory_request *request)
11899{
11900 struct sk_buff *msg;
11901 void *hdr;
11902
11903 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11904 if (!msg)
11905 return;
11906
11907 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11908 if (!hdr) {
11909 nlmsg_free(msg);
11910 return;
11911 }
11912
11913 if (nl80211_reg_change_event_fill(msg, request) == false)
11914 goto nla_put_failure;
11915
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011916 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011917
Johannes Bergbc43b282009-07-25 10:54:13 +020011918 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011919 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011920 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011921 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011922
11923 return;
11924
11925nla_put_failure:
11926 genlmsg_cancel(msg, hdr);
11927 nlmsg_free(msg);
11928}
11929
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011930static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11931 struct net_device *netdev,
11932 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011933 enum nl80211_commands cmd, gfp_t gfp,
11934 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011935{
11936 struct sk_buff *msg;
11937 void *hdr;
11938
Johannes Berge6d6e342009-07-01 21:26:47 +020011939 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011940 if (!msg)
11941 return;
11942
11943 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11944 if (!hdr) {
11945 nlmsg_free(msg);
11946 return;
11947 }
11948
David S. Miller9360ffd2012-03-29 04:41:26 -040011949 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11950 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11951 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11952 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011953
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011954 if (uapsd_queues >= 0) {
11955 struct nlattr *nla_wmm =
11956 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11957 if (!nla_wmm)
11958 goto nla_put_failure;
11959
11960 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11961 uapsd_queues))
11962 goto nla_put_failure;
11963
11964 nla_nest_end(msg, nla_wmm);
11965 }
11966
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011967 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011968
Johannes Berg68eb5502013-11-19 15:19:38 +010011969 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011970 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011971 return;
11972
11973 nla_put_failure:
11974 genlmsg_cancel(msg, hdr);
11975 nlmsg_free(msg);
11976}
11977
11978void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011979 struct net_device *netdev, const u8 *buf,
11980 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011981{
11982 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011983 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011984}
11985
11986void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11987 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011988 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011989{
Johannes Berge6d6e342009-07-01 21:26:47 +020011990 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011991 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011992}
11993
Jouni Malinen53b46b82009-03-27 20:53:56 +020011994void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011995 struct net_device *netdev, const u8 *buf,
11996 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011997{
11998 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011999 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012000}
12001
Jouni Malinen53b46b82009-03-27 20:53:56 +020012002void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12003 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012004 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012005{
12006 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012007 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012008}
12009
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012010void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12011 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012012{
Johannes Berg947add32013-02-22 22:05:20 +010012013 struct wireless_dev *wdev = dev->ieee80211_ptr;
12014 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012015 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012016 const struct ieee80211_mgmt *mgmt = (void *)buf;
12017 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012018
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012019 if (WARN_ON(len < 2))
12020 return;
12021
12022 if (ieee80211_is_deauth(mgmt->frame_control))
12023 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12024 else
12025 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12026
12027 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012028 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012029}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012030EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012031
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012032static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12033 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012034 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012035{
12036 struct sk_buff *msg;
12037 void *hdr;
12038
Johannes Berge6d6e342009-07-01 21:26:47 +020012039 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012040 if (!msg)
12041 return;
12042
12043 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12044 if (!hdr) {
12045 nlmsg_free(msg);
12046 return;
12047 }
12048
David S. Miller9360ffd2012-03-29 04:41:26 -040012049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12050 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12051 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12052 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12053 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012054
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012055 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012056
Johannes Berg68eb5502013-11-19 15:19:38 +010012057 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012058 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012059 return;
12060
12061 nla_put_failure:
12062 genlmsg_cancel(msg, hdr);
12063 nlmsg_free(msg);
12064}
12065
12066void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012067 struct net_device *netdev, const u8 *addr,
12068 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012069{
12070 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012071 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012072}
12073
12074void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012075 struct net_device *netdev, const u8 *addr,
12076 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012077{
Johannes Berge6d6e342009-07-01 21:26:47 +020012078 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12079 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012080}
12081
Samuel Ortizb23aa672009-07-01 21:26:54 +020012082void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12083 struct net_device *netdev, const u8 *bssid,
12084 const u8 *req_ie, size_t req_ie_len,
12085 const u8 *resp_ie, size_t resp_ie_len,
12086 u16 status, gfp_t gfp)
12087{
12088 struct sk_buff *msg;
12089 void *hdr;
12090
Thomas Graf58050fc2012-06-28 03:57:45 +000012091 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012092 if (!msg)
12093 return;
12094
12095 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12096 if (!hdr) {
12097 nlmsg_free(msg);
12098 return;
12099 }
12100
David S. Miller9360ffd2012-03-29 04:41:26 -040012101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12102 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12103 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
12104 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
12105 (req_ie &&
12106 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12107 (resp_ie &&
12108 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12109 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012110
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012111 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012112
Johannes Berg68eb5502013-11-19 15:19:38 +010012113 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012114 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012115 return;
12116
12117 nla_put_failure:
12118 genlmsg_cancel(msg, hdr);
12119 nlmsg_free(msg);
12120
12121}
12122
12123void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12124 struct net_device *netdev, const u8 *bssid,
12125 const u8 *req_ie, size_t req_ie_len,
12126 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12127{
12128 struct sk_buff *msg;
12129 void *hdr;
12130
Thomas Graf58050fc2012-06-28 03:57:45 +000012131 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012132 if (!msg)
12133 return;
12134
12135 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12136 if (!hdr) {
12137 nlmsg_free(msg);
12138 return;
12139 }
12140
David S. Miller9360ffd2012-03-29 04:41:26 -040012141 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12142 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12143 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12144 (req_ie &&
12145 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12146 (resp_ie &&
12147 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12148 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012149
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012150 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012151
Johannes Berg68eb5502013-11-19 15:19:38 +010012152 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012153 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012154 return;
12155
12156 nla_put_failure:
12157 genlmsg_cancel(msg, hdr);
12158 nlmsg_free(msg);
12159
12160}
12161
12162void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12163 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012164 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012165{
12166 struct sk_buff *msg;
12167 void *hdr;
12168
Thomas Graf58050fc2012-06-28 03:57:45 +000012169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012170 if (!msg)
12171 return;
12172
12173 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12174 if (!hdr) {
12175 nlmsg_free(msg);
12176 return;
12177 }
12178
David S. Miller9360ffd2012-03-29 04:41:26 -040012179 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12180 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12181 (from_ap && reason &&
12182 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12183 (from_ap &&
12184 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12185 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12186 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012187
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012188 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012189
Johannes Berg68eb5502013-11-19 15:19:38 +010012190 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012191 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012192 return;
12193
12194 nla_put_failure:
12195 genlmsg_cancel(msg, hdr);
12196 nlmsg_free(msg);
12197
12198}
12199
Johannes Berg04a773a2009-04-19 21:24:32 +020012200void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12201 struct net_device *netdev, const u8 *bssid,
12202 gfp_t gfp)
12203{
12204 struct sk_buff *msg;
12205 void *hdr;
12206
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012207 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012208 if (!msg)
12209 return;
12210
12211 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12212 if (!hdr) {
12213 nlmsg_free(msg);
12214 return;
12215 }
12216
David S. Miller9360ffd2012-03-29 04:41:26 -040012217 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12218 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12219 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12220 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012221
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012222 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012223
Johannes Berg68eb5502013-11-19 15:19:38 +010012224 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012225 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012226 return;
12227
12228 nla_put_failure:
12229 genlmsg_cancel(msg, hdr);
12230 nlmsg_free(msg);
12231}
12232
Johannes Berg947add32013-02-22 22:05:20 +010012233void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12234 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012235{
Johannes Berg947add32013-02-22 22:05:20 +010012236 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012237 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012238 struct sk_buff *msg;
12239 void *hdr;
12240
Johannes Berg947add32013-02-22 22:05:20 +010012241 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12242 return;
12243
12244 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12245
Javier Cardonac93b5e72011-04-07 15:08:34 -070012246 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12247 if (!msg)
12248 return;
12249
12250 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12251 if (!hdr) {
12252 nlmsg_free(msg);
12253 return;
12254 }
12255
David S. Miller9360ffd2012-03-29 04:41:26 -040012256 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012257 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12258 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012259 (ie_len && ie &&
12260 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12261 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012262
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012263 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012264
Johannes Berg68eb5502013-11-19 15:19:38 +010012265 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012266 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012267 return;
12268
12269 nla_put_failure:
12270 genlmsg_cancel(msg, hdr);
12271 nlmsg_free(msg);
12272}
Johannes Berg947add32013-02-22 22:05:20 +010012273EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012274
Jouni Malinena3b8b052009-03-27 21:59:49 +020012275void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12276 struct net_device *netdev, const u8 *addr,
12277 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012278 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012279{
12280 struct sk_buff *msg;
12281 void *hdr;
12282
Johannes Berge6d6e342009-07-01 21:26:47 +020012283 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012284 if (!msg)
12285 return;
12286
12287 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12288 if (!hdr) {
12289 nlmsg_free(msg);
12290 return;
12291 }
12292
David S. Miller9360ffd2012-03-29 04:41:26 -040012293 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12294 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12295 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12296 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12297 (key_id != -1 &&
12298 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12299 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12300 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012301
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012302 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012303
Johannes Berg68eb5502013-11-19 15:19:38 +010012304 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012305 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012306 return;
12307
12308 nla_put_failure:
12309 genlmsg_cancel(msg, hdr);
12310 nlmsg_free(msg);
12311}
12312
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012313void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12314 struct ieee80211_channel *channel_before,
12315 struct ieee80211_channel *channel_after)
12316{
12317 struct sk_buff *msg;
12318 void *hdr;
12319 struct nlattr *nl_freq;
12320
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012321 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012322 if (!msg)
12323 return;
12324
12325 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12326 if (!hdr) {
12327 nlmsg_free(msg);
12328 return;
12329 }
12330
12331 /*
12332 * Since we are applying the beacon hint to a wiphy we know its
12333 * wiphy_idx is valid
12334 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012335 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12336 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012337
12338 /* Before */
12339 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12340 if (!nl_freq)
12341 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012342 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012343 goto nla_put_failure;
12344 nla_nest_end(msg, nl_freq);
12345
12346 /* After */
12347 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12348 if (!nl_freq)
12349 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012350 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012351 goto nla_put_failure;
12352 nla_nest_end(msg, nl_freq);
12353
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012354 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012355
Johannes Berg463d0182009-07-14 00:33:35 +020012356 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012357 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012358 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012359 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012360
12361 return;
12362
12363nla_put_failure:
12364 genlmsg_cancel(msg, hdr);
12365 nlmsg_free(msg);
12366}
12367
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012368static void nl80211_send_remain_on_chan_event(
12369 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012370 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012371 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012372 unsigned int duration, gfp_t gfp)
12373{
12374 struct sk_buff *msg;
12375 void *hdr;
12376
12377 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12378 if (!msg)
12379 return;
12380
12381 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12382 if (!hdr) {
12383 nlmsg_free(msg);
12384 return;
12385 }
12386
David S. Miller9360ffd2012-03-29 04:41:26 -040012387 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012388 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12389 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012390 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12391 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012392 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012393 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12394 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012395 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12396 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012397 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012398
David S. Miller9360ffd2012-03-29 04:41:26 -040012399 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12400 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12401 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012402
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012403 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012404
Johannes Berg68eb5502013-11-19 15:19:38 +010012405 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012406 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012407 return;
12408
12409 nla_put_failure:
12410 genlmsg_cancel(msg, hdr);
12411 nlmsg_free(msg);
12412}
12413
Johannes Berg947add32013-02-22 22:05:20 +010012414void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12415 struct ieee80211_channel *chan,
12416 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012417{
Johannes Berg947add32013-02-22 22:05:20 +010012418 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012419 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012420
12421 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012422 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012423 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012424 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012425}
Johannes Berg947add32013-02-22 22:05:20 +010012426EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012427
Johannes Berg947add32013-02-22 22:05:20 +010012428void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12429 struct ieee80211_channel *chan,
12430 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012431{
Johannes Berg947add32013-02-22 22:05:20 +010012432 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012433 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012434
12435 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012436 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012437 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012438}
Johannes Berg947add32013-02-22 22:05:20 +010012439EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012440
Johannes Berg947add32013-02-22 22:05:20 +010012441void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12442 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012443{
Johannes Berg947add32013-02-22 22:05:20 +010012444 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012445 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012446 struct sk_buff *msg;
12447
Johannes Berg947add32013-02-22 22:05:20 +010012448 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12449
Thomas Graf58050fc2012-06-28 03:57:45 +000012450 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012451 if (!msg)
12452 return;
12453
Johannes Bergcf5ead82014-11-14 17:14:00 +010012454 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012455 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012456 nlmsg_free(msg);
12457 return;
12458 }
12459
Johannes Berg68eb5502013-11-19 15:19:38 +010012460 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012461 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012462}
Johannes Berg947add32013-02-22 22:05:20 +010012463EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012464
Johannes Bergcf5ead82014-11-14 17:14:00 +010012465void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12466 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012467{
Johannes Berg947add32013-02-22 22:05:20 +010012468 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012469 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012470 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012471 struct station_info empty_sinfo = {};
12472
12473 if (!sinfo)
12474 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012475
Johannes Berg947add32013-02-22 22:05:20 +010012476 trace_cfg80211_del_sta(dev, mac_addr);
12477
Thomas Graf58050fc2012-06-28 03:57:45 +000012478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012479 if (!msg)
12480 return;
12481
Johannes Bergcf5ead82014-11-14 17:14:00 +010012482 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012483 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012484 nlmsg_free(msg);
12485 return;
12486 }
12487
Johannes Berg68eb5502013-11-19 15:19:38 +010012488 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012489 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012490}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012491EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012492
Johannes Berg947add32013-02-22 22:05:20 +010012493void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12494 enum nl80211_connect_failed_reason reason,
12495 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012496{
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);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012499 struct sk_buff *msg;
12500 void *hdr;
12501
12502 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12503 if (!msg)
12504 return;
12505
12506 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12507 if (!hdr) {
12508 nlmsg_free(msg);
12509 return;
12510 }
12511
12512 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12513 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12514 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12515 goto nla_put_failure;
12516
12517 genlmsg_end(msg, hdr);
12518
Johannes Berg68eb5502013-11-19 15:19:38 +010012519 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012520 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012521 return;
12522
12523 nla_put_failure:
12524 genlmsg_cancel(msg, hdr);
12525 nlmsg_free(msg);
12526}
Johannes Berg947add32013-02-22 22:05:20 +010012527EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012528
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012529static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12530 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012531{
12532 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012533 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012534 struct sk_buff *msg;
12535 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012536 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012537
Eric W. Biederman15e47302012-09-07 20:12:54 +000012538 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012539 return false;
12540
12541 msg = nlmsg_new(100, gfp);
12542 if (!msg)
12543 return true;
12544
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012545 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012546 if (!hdr) {
12547 nlmsg_free(msg);
12548 return true;
12549 }
12550
David S. Miller9360ffd2012-03-29 04:41:26 -040012551 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12552 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12553 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12554 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012555
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012556 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012557 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012558 return true;
12559
12560 nla_put_failure:
12561 genlmsg_cancel(msg, hdr);
12562 nlmsg_free(msg);
12563 return true;
12564}
12565
Johannes Berg947add32013-02-22 22:05:20 +010012566bool cfg80211_rx_spurious_frame(struct net_device *dev,
12567 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012568{
Johannes Berg947add32013-02-22 22:05:20 +010012569 struct wireless_dev *wdev = dev->ieee80211_ptr;
12570 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012571
Johannes Berg947add32013-02-22 22:05:20 +010012572 trace_cfg80211_rx_spurious_frame(dev, addr);
12573
12574 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12575 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12576 trace_cfg80211_return_bool(false);
12577 return false;
12578 }
12579 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12580 addr, gfp);
12581 trace_cfg80211_return_bool(ret);
12582 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012583}
Johannes Berg947add32013-02-22 22:05:20 +010012584EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12585
12586bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12587 const u8 *addr, gfp_t gfp)
12588{
12589 struct wireless_dev *wdev = dev->ieee80211_ptr;
12590 bool ret;
12591
12592 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12593
12594 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12595 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12596 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12597 trace_cfg80211_return_bool(false);
12598 return false;
12599 }
12600 ret = __nl80211_unexpected_frame(dev,
12601 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12602 addr, gfp);
12603 trace_cfg80211_return_bool(ret);
12604 return ret;
12605}
12606EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012607
Johannes Berg2e161f72010-08-12 15:38:38 +020012608int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012609 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012610 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012611 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012612{
Johannes Berg71bbc992012-06-15 15:30:18 +020012613 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012614 struct sk_buff *msg;
12615 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012616
12617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12618 if (!msg)
12619 return -ENOMEM;
12620
Johannes Berg2e161f72010-08-12 15:38:38 +020012621 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012622 if (!hdr) {
12623 nlmsg_free(msg);
12624 return -ENOMEM;
12625 }
12626
David S. Miller9360ffd2012-03-29 04:41:26 -040012627 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012628 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12629 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012630 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12631 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012632 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12633 (sig_dbm &&
12634 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012635 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12636 (flags &&
12637 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012638 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012639
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012640 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012641
Eric W. Biederman15e47302012-09-07 20:12:54 +000012642 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012643
12644 nla_put_failure:
12645 genlmsg_cancel(msg, hdr);
12646 nlmsg_free(msg);
12647 return -ENOBUFS;
12648}
12649
Johannes Berg947add32013-02-22 22:05:20 +010012650void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12651 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012652{
Johannes Berg947add32013-02-22 22:05:20 +010012653 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012655 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012656 struct sk_buff *msg;
12657 void *hdr;
12658
Johannes Berg947add32013-02-22 22:05:20 +010012659 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12660
Jouni Malinen026331c2010-02-15 12:53:10 +020012661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12662 if (!msg)
12663 return;
12664
Johannes Berg2e161f72010-08-12 15:38:38 +020012665 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012666 if (!hdr) {
12667 nlmsg_free(msg);
12668 return;
12669 }
12670
David S. Miller9360ffd2012-03-29 04:41:26 -040012671 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012672 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12673 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012674 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12675 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012676 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012677 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12678 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012679 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12680 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012681
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012682 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012683
Johannes Berg68eb5502013-11-19 15:19:38 +010012684 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012685 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012686 return;
12687
12688 nla_put_failure:
12689 genlmsg_cancel(msg, hdr);
12690 nlmsg_free(msg);
12691}
Johannes Berg947add32013-02-22 22:05:20 +010012692EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012693
Johannes Berg5b97f492014-11-26 12:37:43 +010012694static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12695 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012696{
Johannes Berg947add32013-02-22 22:05:20 +010012697 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012698 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12699 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12700 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012701
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012702 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012703 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012704
Johannes Berg5b97f492014-11-26 12:37:43 +010012705 cb = (void **)msg->cb;
12706
12707 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12708 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012709 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012710 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012711 }
12712
David S. Miller9360ffd2012-03-29 04:41:26 -040012713 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012714 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012715 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012716
Johannes Berg5b97f492014-11-26 12:37:43 +010012717 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012718 goto nla_put_failure;
12719
Johannes Berg5b97f492014-11-26 12:37:43 +010012720 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12721 if (!cb[1])
12722 goto nla_put_failure;
12723
12724 cb[2] = rdev;
12725
12726 return msg;
12727 nla_put_failure:
12728 nlmsg_free(msg);
12729 return NULL;
12730}
12731
12732static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12733{
12734 void **cb = (void **)msg->cb;
12735 struct cfg80211_registered_device *rdev = cb[2];
12736
12737 nla_nest_end(msg, cb[1]);
12738 genlmsg_end(msg, cb[0]);
12739
12740 memset(msg->cb, 0, sizeof(msg->cb));
12741
12742 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12743 NL80211_MCGRP_MLME, gfp);
12744}
12745
12746void cfg80211_cqm_rssi_notify(struct net_device *dev,
12747 enum nl80211_cqm_rssi_threshold_event rssi_event,
12748 gfp_t gfp)
12749{
12750 struct sk_buff *msg;
12751
12752 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12753
Johannes Berg98f03342014-11-26 12:42:02 +010012754 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12755 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12756 return;
12757
Johannes Berg5b97f492014-11-26 12:37:43 +010012758 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12759 if (!msg)
12760 return;
12761
David S. Miller9360ffd2012-03-29 04:41:26 -040012762 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12763 rssi_event))
12764 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012765
Johannes Berg5b97f492014-11-26 12:37:43 +010012766 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012767
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012768 return;
12769
12770 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012771 nlmsg_free(msg);
12772}
Johannes Berg947add32013-02-22 22:05:20 +010012773EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012774
Johannes Berg5b97f492014-11-26 12:37:43 +010012775void cfg80211_cqm_txe_notify(struct net_device *dev,
12776 const u8 *peer, u32 num_packets,
12777 u32 rate, u32 intvl, gfp_t gfp)
12778{
12779 struct sk_buff *msg;
12780
12781 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12782 if (!msg)
12783 return;
12784
12785 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12786 goto nla_put_failure;
12787
12788 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12789 goto nla_put_failure;
12790
12791 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12792 goto nla_put_failure;
12793
12794 cfg80211_send_cqm(msg, gfp);
12795 return;
12796
12797 nla_put_failure:
12798 nlmsg_free(msg);
12799}
12800EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12801
12802void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12803 const u8 *peer, u32 num_packets, gfp_t gfp)
12804{
12805 struct sk_buff *msg;
12806
12807 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12808
12809 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12810 if (!msg)
12811 return;
12812
12813 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12814 goto nla_put_failure;
12815
12816 cfg80211_send_cqm(msg, gfp);
12817 return;
12818
12819 nla_put_failure:
12820 nlmsg_free(msg);
12821}
12822EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12823
Johannes Berg98f03342014-11-26 12:42:02 +010012824void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12825{
12826 struct sk_buff *msg;
12827
12828 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12829 if (!msg)
12830 return;
12831
12832 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12833 goto nla_put_failure;
12834
12835 cfg80211_send_cqm(msg, gfp);
12836 return;
12837
12838 nla_put_failure:
12839 nlmsg_free(msg);
12840}
12841EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12842
Johannes Berg947add32013-02-22 22:05:20 +010012843static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12844 struct net_device *netdev, const u8 *bssid,
12845 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012846{
12847 struct sk_buff *msg;
12848 struct nlattr *rekey_attr;
12849 void *hdr;
12850
Thomas Graf58050fc2012-06-28 03:57:45 +000012851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012852 if (!msg)
12853 return;
12854
12855 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12856 if (!hdr) {
12857 nlmsg_free(msg);
12858 return;
12859 }
12860
David S. Miller9360ffd2012-03-29 04:41:26 -040012861 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12862 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12863 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12864 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012865
12866 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12867 if (!rekey_attr)
12868 goto nla_put_failure;
12869
David S. Miller9360ffd2012-03-29 04:41:26 -040012870 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12871 NL80211_REPLAY_CTR_LEN, replay_ctr))
12872 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012873
12874 nla_nest_end(msg, rekey_attr);
12875
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012876 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012877
Johannes Berg68eb5502013-11-19 15:19:38 +010012878 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012879 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012880 return;
12881
12882 nla_put_failure:
12883 genlmsg_cancel(msg, hdr);
12884 nlmsg_free(msg);
12885}
12886
Johannes Berg947add32013-02-22 22:05:20 +010012887void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12888 const u8 *replay_ctr, gfp_t gfp)
12889{
12890 struct wireless_dev *wdev = dev->ieee80211_ptr;
12891 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012892 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012893
12894 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12895 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12896}
12897EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12898
12899static void
12900nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12901 struct net_device *netdev, int index,
12902 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012903{
12904 struct sk_buff *msg;
12905 struct nlattr *attr;
12906 void *hdr;
12907
Thomas Graf58050fc2012-06-28 03:57:45 +000012908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012909 if (!msg)
12910 return;
12911
12912 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12913 if (!hdr) {
12914 nlmsg_free(msg);
12915 return;
12916 }
12917
David S. Miller9360ffd2012-03-29 04:41:26 -040012918 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12919 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12920 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012921
12922 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12923 if (!attr)
12924 goto nla_put_failure;
12925
David S. Miller9360ffd2012-03-29 04:41:26 -040012926 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12927 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12928 (preauth &&
12929 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12930 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012931
12932 nla_nest_end(msg, attr);
12933
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012934 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012935
Johannes Berg68eb5502013-11-19 15:19:38 +010012936 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012937 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012938 return;
12939
12940 nla_put_failure:
12941 genlmsg_cancel(msg, hdr);
12942 nlmsg_free(msg);
12943}
12944
Johannes Berg947add32013-02-22 22:05:20 +010012945void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12946 const u8 *bssid, bool preauth, gfp_t gfp)
12947{
12948 struct wireless_dev *wdev = dev->ieee80211_ptr;
12949 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012950 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012951
12952 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12953 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12954}
12955EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12956
12957static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12958 struct net_device *netdev,
12959 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012960 gfp_t gfp,
12961 enum nl80211_commands notif,
12962 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012963{
12964 struct sk_buff *msg;
12965 void *hdr;
12966
Thomas Graf58050fc2012-06-28 03:57:45 +000012967 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012968 if (!msg)
12969 return;
12970
Luciano Coelhof8d75522014-11-07 14:31:35 +020012971 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012972 if (!hdr) {
12973 nlmsg_free(msg);
12974 return;
12975 }
12976
Johannes Berg683b6d32012-11-08 21:25:48 +010012977 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12978 goto nla_put_failure;
12979
12980 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012981 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012982
Luciano Coelhof8d75522014-11-07 14:31:35 +020012983 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12984 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12985 goto nla_put_failure;
12986
Thomas Pedersen53145262012-04-06 13:35:47 -070012987 genlmsg_end(msg, hdr);
12988
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);
Thomas Pedersen53145262012-04-06 13:35:47 -070012991 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_ch_switch_notify(struct net_device *dev,
12999 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013000{
Johannes Berg947add32013-02-22 22:05:20 +010013001 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
Simon Wunderliche487eae2013-11-21 18:19:51 +010013005 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013006
Simon Wunderliche487eae2013-11-21 18:19:51 +010013007 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013008
Michal Kazior9e0e2962014-01-29 14:22:27 +010013009 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013010 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013011 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13012 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013013}
13014EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13015
Luciano Coelhof8d75522014-11-07 14:31:35 +020013016void cfg80211_ch_switch_started_notify(struct net_device *dev,
13017 struct cfg80211_chan_def *chandef,
13018 u8 count)
13019{
13020 struct wireless_dev *wdev = dev->ieee80211_ptr;
13021 struct wiphy *wiphy = wdev->wiphy;
13022 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13023
13024 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13025
13026 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13027 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13028}
13029EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13030
Thomas Pedersen84f10702012-07-12 16:17:33 -070013031void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013032nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013033 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013034 enum nl80211_radar_event event,
13035 struct net_device *netdev, gfp_t gfp)
13036{
13037 struct sk_buff *msg;
13038 void *hdr;
13039
13040 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13041 if (!msg)
13042 return;
13043
13044 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13045 if (!hdr) {
13046 nlmsg_free(msg);
13047 return;
13048 }
13049
13050 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13051 goto nla_put_failure;
13052
13053 /* NOP and radar events don't need a netdev parameter */
13054 if (netdev) {
13055 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13056
13057 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013058 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13059 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013060 goto nla_put_failure;
13061 }
13062
13063 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13064 goto nla_put_failure;
13065
13066 if (nl80211_send_chandef(msg, chandef))
13067 goto nla_put_failure;
13068
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013069 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013070
Johannes Berg68eb5502013-11-19 15:19:38 +010013071 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013072 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013073 return;
13074
13075 nla_put_failure:
13076 genlmsg_cancel(msg, hdr);
13077 nlmsg_free(msg);
13078}
13079
Johannes Berg7f6cf312011-11-04 11:18:15 +010013080void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13081 u64 cookie, bool acked, gfp_t gfp)
13082{
13083 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013084 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013085 struct sk_buff *msg;
13086 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013087
Beni Lev4ee3e062012-08-27 12:49:39 +030013088 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13089
Thomas Graf58050fc2012-06-28 03:57:45 +000013090 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013091
Johannes Berg7f6cf312011-11-04 11:18:15 +010013092 if (!msg)
13093 return;
13094
13095 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13096 if (!hdr) {
13097 nlmsg_free(msg);
13098 return;
13099 }
13100
David S. Miller9360ffd2012-03-29 04:41:26 -040013101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13102 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13103 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013104 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13105 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013106 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13107 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013108
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013109 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013110
Johannes Berg68eb5502013-11-19 15:19:38 +010013111 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013112 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013113 return;
13114
13115 nla_put_failure:
13116 genlmsg_cancel(msg, hdr);
13117 nlmsg_free(msg);
13118}
13119EXPORT_SYMBOL(cfg80211_probe_status);
13120
Johannes Berg5e7602302011-11-04 11:18:17 +010013121void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13122 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013123 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013124{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013125 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013126 struct sk_buff *msg;
13127 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013128 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013129
Beni Lev4ee3e062012-08-27 12:49:39 +030013130 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13131
Ben Greear37c73b52012-10-26 14:49:25 -070013132 spin_lock_bh(&rdev->beacon_registrations_lock);
13133 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13134 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13135 if (!msg) {
13136 spin_unlock_bh(&rdev->beacon_registrations_lock);
13137 return;
13138 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013139
Ben Greear37c73b52012-10-26 14:49:25 -070013140 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13141 if (!hdr)
13142 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013143
Ben Greear37c73b52012-10-26 14:49:25 -070013144 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13145 (freq &&
13146 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13147 (sig_dbm &&
13148 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13149 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13150 goto nla_put_failure;
13151
13152 genlmsg_end(msg, hdr);
13153
13154 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013155 }
Ben Greear37c73b52012-10-26 14:49:25 -070013156 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013157 return;
13158
13159 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013160 spin_unlock_bh(&rdev->beacon_registrations_lock);
13161 if (hdr)
13162 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013163 nlmsg_free(msg);
13164}
13165EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13166
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013167#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013168static int cfg80211_net_detect_results(struct sk_buff *msg,
13169 struct cfg80211_wowlan_wakeup *wakeup)
13170{
13171 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13172 struct nlattr *nl_results, *nl_match, *nl_freqs;
13173 int i, j;
13174
13175 nl_results = nla_nest_start(
13176 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13177 if (!nl_results)
13178 return -EMSGSIZE;
13179
13180 for (i = 0; i < nd->n_matches; i++) {
13181 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13182
13183 nl_match = nla_nest_start(msg, i);
13184 if (!nl_match)
13185 break;
13186
13187 /* The SSID attribute is optional in nl80211, but for
13188 * simplicity reasons it's always present in the
13189 * cfg80211 structure. If a driver can't pass the
13190 * SSID, that needs to be changed. A zero length SSID
13191 * is still a valid SSID (wildcard), so it cannot be
13192 * used for this purpose.
13193 */
13194 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13195 match->ssid.ssid)) {
13196 nla_nest_cancel(msg, nl_match);
13197 goto out;
13198 }
13199
13200 if (match->n_channels) {
13201 nl_freqs = nla_nest_start(
13202 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13203 if (!nl_freqs) {
13204 nla_nest_cancel(msg, nl_match);
13205 goto out;
13206 }
13207
13208 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013209 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013210 nla_nest_cancel(msg, nl_freqs);
13211 nla_nest_cancel(msg, nl_match);
13212 goto out;
13213 }
13214 }
13215
13216 nla_nest_end(msg, nl_freqs);
13217 }
13218
13219 nla_nest_end(msg, nl_match);
13220 }
13221
13222out:
13223 nla_nest_end(msg, nl_results);
13224 return 0;
13225}
13226
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013227void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13228 struct cfg80211_wowlan_wakeup *wakeup,
13229 gfp_t gfp)
13230{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013232 struct sk_buff *msg;
13233 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013234 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013235
13236 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13237
13238 if (wakeup)
13239 size += wakeup->packet_present_len;
13240
13241 msg = nlmsg_new(size, gfp);
13242 if (!msg)
13243 return;
13244
13245 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13246 if (!hdr)
13247 goto free_msg;
13248
13249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013250 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13251 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013252 goto free_msg;
13253
13254 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13255 wdev->netdev->ifindex))
13256 goto free_msg;
13257
13258 if (wakeup) {
13259 struct nlattr *reasons;
13260
13261 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013262 if (!reasons)
13263 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013264
13265 if (wakeup->disconnect &&
13266 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13267 goto free_msg;
13268 if (wakeup->magic_pkt &&
13269 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13270 goto free_msg;
13271 if (wakeup->gtk_rekey_failure &&
13272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13273 goto free_msg;
13274 if (wakeup->eap_identity_req &&
13275 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13276 goto free_msg;
13277 if (wakeup->four_way_handshake &&
13278 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13279 goto free_msg;
13280 if (wakeup->rfkill_release &&
13281 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13282 goto free_msg;
13283
13284 if (wakeup->pattern_idx >= 0 &&
13285 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13286 wakeup->pattern_idx))
13287 goto free_msg;
13288
Johannes Bergae917c92013-10-25 11:05:22 +020013289 if (wakeup->tcp_match &&
13290 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13291 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013292
Johannes Bergae917c92013-10-25 11:05:22 +020013293 if (wakeup->tcp_connlost &&
13294 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13295 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013296
Johannes Bergae917c92013-10-25 11:05:22 +020013297 if (wakeup->tcp_nomoretokens &&
13298 nla_put_flag(msg,
13299 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13300 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013301
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013302 if (wakeup->packet) {
13303 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13304 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13305
13306 if (!wakeup->packet_80211) {
13307 pkt_attr =
13308 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13309 len_attr =
13310 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13311 }
13312
13313 if (wakeup->packet_len &&
13314 nla_put_u32(msg, len_attr, wakeup->packet_len))
13315 goto free_msg;
13316
13317 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13318 wakeup->packet))
13319 goto free_msg;
13320 }
13321
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013322 if (wakeup->net_detect &&
13323 cfg80211_net_detect_results(msg, wakeup))
13324 goto free_msg;
13325
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013326 nla_nest_end(msg, reasons);
13327 }
13328
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013329 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013330
Johannes Berg68eb5502013-11-19 15:19:38 +010013331 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013332 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013333 return;
13334
13335 free_msg:
13336 nlmsg_free(msg);
13337}
13338EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13339#endif
13340
Jouni Malinen3475b092012-11-16 22:49:57 +020013341void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13342 enum nl80211_tdls_operation oper,
13343 u16 reason_code, gfp_t gfp)
13344{
13345 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013346 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013347 struct sk_buff *msg;
13348 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013349
13350 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13351 reason_code);
13352
13353 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13354 if (!msg)
13355 return;
13356
13357 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13358 if (!hdr) {
13359 nlmsg_free(msg);
13360 return;
13361 }
13362
13363 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13364 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13365 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13366 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13367 (reason_code > 0 &&
13368 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13369 goto nla_put_failure;
13370
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013371 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013372
Johannes Berg68eb5502013-11-19 15:19:38 +010013373 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013374 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013375 return;
13376
13377 nla_put_failure:
13378 genlmsg_cancel(msg, hdr);
13379 nlmsg_free(msg);
13380}
13381EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13382
Jouni Malinen026331c2010-02-15 12:53:10 +020013383static int nl80211_netlink_notify(struct notifier_block * nb,
13384 unsigned long state,
13385 void *_notify)
13386{
13387 struct netlink_notify *notify = _notify;
13388 struct cfg80211_registered_device *rdev;
13389 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013390 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013391
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013392 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013393 return NOTIFY_DONE;
13394
13395 rcu_read_lock();
13396
Johannes Berg5e7602302011-11-04 11:18:17 +010013397 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013398 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013399 bool schedule_scan_stop = false;
13400 struct cfg80211_sched_scan_request *sched_scan_req =
13401 rcu_dereference(rdev->sched_scan_req);
13402
13403 if (sched_scan_req && notify->portid &&
13404 sched_scan_req->owner_nlportid == notify->portid)
13405 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013406
13407 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013408 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013409
Johannes Berg78f22b62014-03-24 17:57:27 +010013410 if (wdev->owner_nlportid == notify->portid)
13411 schedule_destroy_work = true;
13412 }
13413
Ben Greear37c73b52012-10-26 14:49:25 -070013414 spin_lock_bh(&rdev->beacon_registrations_lock);
13415 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13416 list) {
13417 if (reg->nlportid == notify->portid) {
13418 list_del(&reg->list);
13419 kfree(reg);
13420 break;
13421 }
13422 }
13423 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013424
13425 if (schedule_destroy_work) {
13426 struct cfg80211_iface_destroy *destroy;
13427
13428 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13429 if (destroy) {
13430 destroy->nlportid = notify->portid;
13431 spin_lock(&rdev->destroy_list_lock);
13432 list_add(&destroy->list, &rdev->destroy_list);
13433 spin_unlock(&rdev->destroy_list_lock);
13434 schedule_work(&rdev->destroy_work);
13435 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013436 } else if (schedule_scan_stop) {
13437 sched_scan_req->owner_nlportid = 0;
13438
13439 if (rdev->ops->sched_scan_stop &&
13440 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13441 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013442 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013443 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013444
13445 rcu_read_unlock();
13446
Ilan peer05050752015-03-04 00:32:06 -050013447 /*
13448 * It is possible that the user space process that is controlling the
13449 * indoor setting disappeared, so notify the regulatory core.
13450 */
13451 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013452 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013453}
13454
13455static struct notifier_block nl80211_netlink_notifier = {
13456 .notifier_call = nl80211_netlink_notify,
13457};
13458
Jouni Malinen355199e2013-02-27 17:14:27 +020013459void cfg80211_ft_event(struct net_device *netdev,
13460 struct cfg80211_ft_event_params *ft_event)
13461{
13462 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013463 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013464 struct sk_buff *msg;
13465 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013466
13467 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13468
13469 if (!ft_event->target_ap)
13470 return;
13471
13472 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13473 if (!msg)
13474 return;
13475
13476 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013477 if (!hdr)
13478 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013479
Johannes Bergae917c92013-10-25 11:05:22 +020013480 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13481 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13482 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13483 goto out;
13484
13485 if (ft_event->ies &&
13486 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13487 goto out;
13488 if (ft_event->ric_ies &&
13489 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13490 ft_event->ric_ies))
13491 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013492
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013493 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013494
Johannes Berg68eb5502013-11-19 15:19:38 +010013495 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013496 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013497 return;
13498 out:
13499 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013500}
13501EXPORT_SYMBOL(cfg80211_ft_event);
13502
Arend van Spriel5de17982013-04-18 15:49:00 +020013503void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13504{
13505 struct cfg80211_registered_device *rdev;
13506 struct sk_buff *msg;
13507 void *hdr;
13508 u32 nlportid;
13509
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013510 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013511 if (!rdev->crit_proto_nlportid)
13512 return;
13513
13514 nlportid = rdev->crit_proto_nlportid;
13515 rdev->crit_proto_nlportid = 0;
13516
13517 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13518 if (!msg)
13519 return;
13520
13521 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13522 if (!hdr)
13523 goto nla_put_failure;
13524
13525 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013526 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13527 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013528 goto nla_put_failure;
13529
13530 genlmsg_end(msg, hdr);
13531
13532 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13533 return;
13534
13535 nla_put_failure:
13536 if (hdr)
13537 genlmsg_cancel(msg, hdr);
13538 nlmsg_free(msg);
13539
13540}
13541EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13542
Johannes Berg348baf02014-01-24 14:06:29 +010013543void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13544{
13545 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013546 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013547 struct sk_buff *msg;
13548 void *hdr;
13549
13550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13551 if (!msg)
13552 return;
13553
13554 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13555 if (!hdr)
13556 goto out;
13557
13558 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13559 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013560 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13561 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013562 goto out;
13563
13564 genlmsg_end(msg, hdr);
13565
13566 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13567 NL80211_MCGRP_MLME, GFP_KERNEL);
13568 return;
13569 out:
13570 nlmsg_free(msg);
13571}
13572
Johannes Berg55682962007-09-20 13:09:35 -040013573/* initialisation/exit functions */
13574
13575int nl80211_init(void)
13576{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013577 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013578
Johannes Berg2a94fe42013-11-19 15:19:39 +010013579 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13580 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013581 if (err)
13582 return err;
13583
Jouni Malinen026331c2010-02-15 12:53:10 +020013584 err = netlink_register_notifier(&nl80211_netlink_notifier);
13585 if (err)
13586 goto err_out;
13587
Johannes Berg55682962007-09-20 13:09:35 -040013588 return 0;
13589 err_out:
13590 genl_unregister_family(&nl80211_fam);
13591 return err;
13592}
13593
13594void nl80211_exit(void)
13595{
Jouni Malinen026331c2010-02-15 12:53:10 +020013596 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013597 genl_unregister_family(&nl80211_fam);
13598}