blob: 4f45a2913104e42e692bde95a8e4ecb621767b15 [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 Malinen36aedc92008-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 Malinendc6382ce2009-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 Bergee688b002008-01-24 19:38:39 +01001280 enum ieee80211_band band;
1281 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;
1413 band < IEEE80211_NUM_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 Berg3713b4e2013-02-14 16:19:38 +01001475 if (band < IEEE80211_NUM_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) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002432 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002433 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002434 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2435 rdev->devlist_generation ^
2436 (cfg80211_rdev_list_generation << 2)))
2437 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002438
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002439 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002440 int ret;
2441 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002442
Johannes Berg683b6d32012-11-08 21:25:48 +01002443 ret = rdev_get_channel(rdev, wdev, &chandef);
2444 if (ret == 0) {
2445 if (nl80211_send_chandef(msg, &chandef))
2446 goto nla_put_failure;
2447 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002448 }
2449
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002450 if (rdev->ops->get_tx_power) {
2451 int dbm, ret;
2452
2453 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2454 if (ret == 0 &&
2455 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2456 DBM_TO_MBM(dbm)))
2457 goto nla_put_failure;
2458 }
2459
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002460 if (wdev->ssid_len) {
2461 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2462 goto nla_put_failure;
2463 }
2464
Johannes Berg053c0952015-01-16 22:09:00 +01002465 genlmsg_end(msg, hdr);
2466 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002467
2468 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002469 genlmsg_cancel(msg, hdr);
2470 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002471}
2472
2473static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2474{
2475 int wp_idx = 0;
2476 int if_idx = 0;
2477 int wp_start = cb->args[0];
2478 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002479 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002480 struct wireless_dev *wdev;
2481
Johannes Berg5fe231e2013-05-08 21:45:15 +02002482 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002483 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2484 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002485 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002486 if (wp_idx < wp_start) {
2487 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002488 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002489 }
Johannes Berg55682962007-09-20 13:09:35 -04002490 if_idx = 0;
2491
Johannes Berg89a54e42012-06-15 14:33:17 +02002492 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002493 if (if_idx < if_start) {
2494 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002495 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002496 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002497 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002498 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002499 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002500 goto out;
2501 }
2502 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002503 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002504
2505 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002506 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002507 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002508 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002509
2510 cb->args[0] = wp_idx;
2511 cb->args[1] = if_idx;
2512
2513 return skb->len;
2514}
2515
2516static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2517{
2518 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002520 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002521
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002522 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002523 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002524 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002525
Eric W. Biederman15e47302012-09-07 20:12:54 +00002526 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002527 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002528 nlmsg_free(msg);
2529 return -ENOBUFS;
2530 }
Johannes Berg55682962007-09-20 13:09:35 -04002531
Johannes Berg134e6372009-07-10 09:51:34 +00002532 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002533}
2534
Michael Wu66f7ac52008-01-31 19:48:22 +01002535static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2536 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2537 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2538 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2539 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2540 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002541 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002542};
2543
2544static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2545{
2546 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2547 int flag;
2548
2549 *mntrflags = 0;
2550
2551 if (!nla)
2552 return -EINVAL;
2553
2554 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2555 nla, mntr_flags_policy))
2556 return -EINVAL;
2557
2558 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2559 if (flags[flag])
2560 *mntrflags |= (1<<flag);
2561
2562 return 0;
2563}
2564
Johannes Berg9bc383d2009-11-19 11:55:19 +01002565static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002566 struct net_device *netdev, u8 use_4addr,
2567 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002568{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002569 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002570 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002571 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002572 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002573 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002574
2575 switch (iftype) {
2576 case NL80211_IFTYPE_AP_VLAN:
2577 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2578 return 0;
2579 break;
2580 case NL80211_IFTYPE_STATION:
2581 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2582 return 0;
2583 break;
2584 default:
2585 break;
2586 }
2587
2588 return -EOPNOTSUPP;
2589}
2590
Johannes Berg55682962007-09-20 13:09:35 -04002591static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2592{
Johannes Berg4c476992010-10-04 21:36:35 +02002593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002594 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002595 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002596 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002597 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002598 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002599 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002600
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002601 memset(&params, 0, sizeof(params));
2602
Johannes Berg04a773a2009-04-19 21:24:32 +02002603 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002604
Johannes Berg723b0382008-09-16 20:22:09 +02002605 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002606 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002607 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002608 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002609 if (ntype > NL80211_IFTYPE_MAX)
2610 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002611 }
2612
Johannes Berg92ffe052008-09-16 20:39:36 +02002613 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002614 struct wireless_dev *wdev = dev->ieee80211_ptr;
2615
Johannes Berg4c476992010-10-04 21:36:35 +02002616 if (ntype != NL80211_IFTYPE_MESH_POINT)
2617 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002618 if (netif_running(dev))
2619 return -EBUSY;
2620
2621 wdev_lock(wdev);
2622 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2623 IEEE80211_MAX_MESH_ID_LEN);
2624 wdev->mesh_id_up_len =
2625 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2626 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2627 wdev->mesh_id_up_len);
2628 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002629 }
2630
Felix Fietkau8b787642009-11-10 18:53:10 +01002631 if (info->attrs[NL80211_ATTR_4ADDR]) {
2632 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2633 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002634 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002635 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002636 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002637 } else {
2638 params.use_4addr = -1;
2639 }
2640
Johannes Berg92ffe052008-09-16 20:39:36 +02002641 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002642 if (ntype != NL80211_IFTYPE_MONITOR)
2643 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002644 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2645 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002646 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002647 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002648
2649 flags = &_flags;
2650 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002651 }
Johannes Berg3b858752009-03-12 09:55:09 +01002652
Luciano Coelho18003292013-08-29 13:26:57 +03002653 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002654 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2655 return -EOPNOTSUPP;
2656
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002657 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002658 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002659 else
2660 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002661
Johannes Berg9bc383d2009-11-19 11:55:19 +01002662 if (!err && params.use_4addr != -1)
2663 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2664
Johannes Berg55682962007-09-20 13:09:35 -04002665 return err;
2666}
2667
2668static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2669{
Johannes Berg4c476992010-10-04 21:36:35 +02002670 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002671 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002672 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002673 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002674 int err;
2675 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002676 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002677
Johannes Berg78f22b62014-03-24 17:57:27 +01002678 /* to avoid failing a new interface creation due to pending removal */
2679 cfg80211_destroy_ifaces(rdev);
2680
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002681 memset(&params, 0, sizeof(params));
2682
Johannes Berg55682962007-09-20 13:09:35 -04002683 if (!info->attrs[NL80211_ATTR_IFNAME])
2684 return -EINVAL;
2685
2686 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2687 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2688 if (type > NL80211_IFTYPE_MAX)
2689 return -EINVAL;
2690 }
2691
Johannes Berg79c97e92009-07-07 03:56:12 +02002692 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002693 !(rdev->wiphy.interface_modes & (1 << type)))
2694 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002695
Ben Greeare8f479b2014-10-22 12:23:05 -07002696 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2697 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2698 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002699 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2700 ETH_ALEN);
2701 if (!is_valid_ether_addr(params.macaddr))
2702 return -EADDRNOTAVAIL;
2703 }
2704
Johannes Berg9bc383d2009-11-19 11:55:19 +01002705 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002706 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002707 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002708 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002709 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002710 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002711
Michael Wu66f7ac52008-01-31 19:48:22 +01002712 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2713 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2714 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002715
Luciano Coelho18003292013-08-29 13:26:57 +03002716 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002717 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2718 return -EOPNOTSUPP;
2719
Johannes Berga18c7192015-02-24 10:56:42 +01002720 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2721 if (!msg)
2722 return -ENOMEM;
2723
Hila Gonene35e4d22012-06-27 17:19:42 +03002724 wdev = rdev_add_virtual_intf(rdev,
2725 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002726 NET_NAME_USER, type, err ? NULL : &flags,
2727 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002728 if (WARN_ON(!wdev)) {
2729 nlmsg_free(msg);
2730 return -EPROTO;
2731 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002732 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002733 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002734 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002735
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002736 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002737 wdev->owner_nlportid = info->snd_portid;
2738
Johannes Berg98104fde2012-06-16 00:19:54 +02002739 switch (type) {
2740 case NL80211_IFTYPE_MESH_POINT:
2741 if (!info->attrs[NL80211_ATTR_MESH_ID])
2742 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002743 wdev_lock(wdev);
2744 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2745 IEEE80211_MAX_MESH_ID_LEN);
2746 wdev->mesh_id_up_len =
2747 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2748 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2749 wdev->mesh_id_up_len);
2750 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002751 break;
2752 case NL80211_IFTYPE_P2P_DEVICE:
2753 /*
2754 * P2P Device doesn't have a netdev, so doesn't go
2755 * through the netdev notifier and must be added here
2756 */
2757 mutex_init(&wdev->mtx);
2758 INIT_LIST_HEAD(&wdev->event_list);
2759 spin_lock_init(&wdev->event_lock);
2760 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2761 spin_lock_init(&wdev->mgmt_registrations_lock);
2762
Johannes Berg98104fde2012-06-16 00:19:54 +02002763 wdev->identifier = ++rdev->wdev_id;
2764 list_add_rcu(&wdev->list, &rdev->wdev_list);
2765 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002766 break;
2767 default:
2768 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002769 }
2770
Eric W. Biederman15e47302012-09-07 20:12:54 +00002771 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002772 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002773 nlmsg_free(msg);
2774 return -ENOBUFS;
2775 }
2776
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002777 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2778 if (event) {
2779 if (nl80211_send_iface(event, 0, 0, 0,
2780 rdev, wdev, false) < 0) {
2781 nlmsg_free(event);
2782 goto out;
2783 }
2784
2785 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2786 event, 0, NL80211_MCGRP_CONFIG,
2787 GFP_KERNEL);
2788 }
2789
2790out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002791 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002792}
2793
2794static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2795{
Johannes Berg4c476992010-10-04 21:36:35 +02002796 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002797 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002798 struct sk_buff *msg;
2799 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002800
Johannes Berg4c476992010-10-04 21:36:35 +02002801 if (!rdev->ops->del_virtual_intf)
2802 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002803
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002804 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2805 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2806 nlmsg_free(msg);
2807 msg = NULL;
2808 }
2809
Johannes Berg84efbb82012-06-16 00:00:26 +02002810 /*
2811 * If we remove a wireless device without a netdev then clear
2812 * user_ptr[1] so that nl80211_post_doit won't dereference it
2813 * to check if it needs to do dev_put(). Otherwise it crashes
2814 * since the wdev has been freed, unlike with a netdev where
2815 * we need the dev_put() for the netdev to really be freed.
2816 */
2817 if (!wdev->netdev)
2818 info->user_ptr[1] = NULL;
2819
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002820 status = rdev_del_virtual_intf(rdev, wdev);
2821 if (status >= 0 && msg)
2822 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2823 msg, 0, NL80211_MCGRP_CONFIG,
2824 GFP_KERNEL);
2825 else
2826 nlmsg_free(msg);
2827
2828 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002829}
2830
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002831static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2832{
2833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2834 struct net_device *dev = info->user_ptr[1];
2835 u16 noack_map;
2836
2837 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2838 return -EINVAL;
2839
2840 if (!rdev->ops->set_noack_map)
2841 return -EOPNOTSUPP;
2842
2843 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2844
Hila Gonene35e4d22012-06-27 17:19:42 +03002845 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002846}
2847
Johannes Berg41ade002007-12-19 02:03:29 +01002848struct get_key_cookie {
2849 struct sk_buff *msg;
2850 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002851 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002852};
2853
2854static void get_key_callback(void *c, struct key_params *params)
2855{
Johannes Bergb9454e82009-07-08 13:29:08 +02002856 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002857 struct get_key_cookie *cookie = c;
2858
David S. Miller9360ffd2012-03-29 04:41:26 -04002859 if ((params->key &&
2860 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2861 params->key_len, params->key)) ||
2862 (params->seq &&
2863 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2864 params->seq_len, params->seq)) ||
2865 (params->cipher &&
2866 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2867 params->cipher)))
2868 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002869
Johannes Bergb9454e82009-07-08 13:29:08 +02002870 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2871 if (!key)
2872 goto nla_put_failure;
2873
David S. Miller9360ffd2012-03-29 04:41:26 -04002874 if ((params->key &&
2875 nla_put(cookie->msg, NL80211_KEY_DATA,
2876 params->key_len, params->key)) ||
2877 (params->seq &&
2878 nla_put(cookie->msg, NL80211_KEY_SEQ,
2879 params->seq_len, params->seq)) ||
2880 (params->cipher &&
2881 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2882 params->cipher)))
2883 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002884
David S. Miller9360ffd2012-03-29 04:41:26 -04002885 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2886 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002887
2888 nla_nest_end(cookie->msg, key);
2889
Johannes Berg41ade002007-12-19 02:03:29 +01002890 return;
2891 nla_put_failure:
2892 cookie->error = 1;
2893}
2894
2895static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2896{
Johannes Berg4c476992010-10-04 21:36:35 +02002897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002898 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002899 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002900 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002901 const u8 *mac_addr = NULL;
2902 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002903 struct get_key_cookie cookie = {
2904 .error = 0,
2905 };
2906 void *hdr;
2907 struct sk_buff *msg;
2908
2909 if (info->attrs[NL80211_ATTR_KEY_IDX])
2910 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2911
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002912 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002913 return -EINVAL;
2914
2915 if (info->attrs[NL80211_ATTR_MAC])
2916 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2917
Johannes Berge31b8212010-10-05 19:39:30 +02002918 pairwise = !!mac_addr;
2919 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2920 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2921 if (kt >= NUM_NL80211_KEYTYPES)
2922 return -EINVAL;
2923 if (kt != NL80211_KEYTYPE_GROUP &&
2924 kt != NL80211_KEYTYPE_PAIRWISE)
2925 return -EINVAL;
2926 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2927 }
2928
Johannes Berg4c476992010-10-04 21:36:35 +02002929 if (!rdev->ops->get_key)
2930 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002931
Johannes Berg0fa7b392015-01-23 11:10:12 +01002932 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2933 return -ENOENT;
2934
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002935 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002936 if (!msg)
2937 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002938
Eric W. Biederman15e47302012-09-07 20:12:54 +00002939 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002940 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002941 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002942 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002943
2944 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002945 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002946
David S. Miller9360ffd2012-03-29 04:41:26 -04002947 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2948 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2949 goto nla_put_failure;
2950 if (mac_addr &&
2951 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2952 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002953
Hila Gonene35e4d22012-06-27 17:19:42 +03002954 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2955 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002956
2957 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002958 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002959
2960 if (cookie.error)
2961 goto nla_put_failure;
2962
2963 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002964 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002965
2966 nla_put_failure:
2967 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002968 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002969 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002970 return err;
2971}
2972
2973static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2974{
Johannes Berg4c476992010-10-04 21:36:35 +02002975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002976 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002977 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002978 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002979
Johannes Bergb9454e82009-07-08 13:29:08 +02002980 err = nl80211_parse_key(info, &key);
2981 if (err)
2982 return err;
2983
2984 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002985 return -EINVAL;
2986
Johannes Bergb9454e82009-07-08 13:29:08 +02002987 /* only support setting default key */
2988 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002989 return -EINVAL;
2990
Johannes Bergfffd0932009-07-08 14:22:54 +02002991 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002992
2993 if (key.def) {
2994 if (!rdev->ops->set_default_key) {
2995 err = -EOPNOTSUPP;
2996 goto out;
2997 }
2998
2999 err = nl80211_key_allowed(dev->ieee80211_ptr);
3000 if (err)
3001 goto out;
3002
Hila Gonene35e4d22012-06-27 17:19:42 +03003003 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003004 key.def_uni, key.def_multi);
3005
3006 if (err)
3007 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003008
Johannes Berg3d23e342009-09-29 23:27:28 +02003009#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003010 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003011#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003012 } else {
3013 if (key.def_uni || !key.def_multi) {
3014 err = -EINVAL;
3015 goto out;
3016 }
3017
3018 if (!rdev->ops->set_default_mgmt_key) {
3019 err = -EOPNOTSUPP;
3020 goto out;
3021 }
3022
3023 err = nl80211_key_allowed(dev->ieee80211_ptr);
3024 if (err)
3025 goto out;
3026
Hila Gonene35e4d22012-06-27 17:19:42 +03003027 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003028 if (err)
3029 goto out;
3030
3031#ifdef CONFIG_CFG80211_WEXT
3032 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3033#endif
3034 }
3035
3036 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003037 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003038
Johannes Berg41ade002007-12-19 02:03:29 +01003039 return err;
3040}
3041
3042static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3043{
Johannes Berg4c476992010-10-04 21:36:35 +02003044 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003045 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003046 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003047 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003048 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003049
Johannes Bergb9454e82009-07-08 13:29:08 +02003050 err = nl80211_parse_key(info, &key);
3051 if (err)
3052 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003053
Johannes Bergb9454e82009-07-08 13:29:08 +02003054 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003055 return -EINVAL;
3056
Johannes Berg41ade002007-12-19 02:03:29 +01003057 if (info->attrs[NL80211_ATTR_MAC])
3058 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3059
Johannes Berge31b8212010-10-05 19:39:30 +02003060 if (key.type == -1) {
3061 if (mac_addr)
3062 key.type = NL80211_KEYTYPE_PAIRWISE;
3063 else
3064 key.type = NL80211_KEYTYPE_GROUP;
3065 }
3066
3067 /* for now */
3068 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3069 key.type != NL80211_KEYTYPE_GROUP)
3070 return -EINVAL;
3071
Johannes Berg4c476992010-10-04 21:36:35 +02003072 if (!rdev->ops->add_key)
3073 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003074
Johannes Berge31b8212010-10-05 19:39:30 +02003075 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3076 key.type == NL80211_KEYTYPE_PAIRWISE,
3077 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003078 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003079
3080 wdev_lock(dev->ieee80211_ptr);
3081 err = nl80211_key_allowed(dev->ieee80211_ptr);
3082 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003083 err = rdev_add_key(rdev, dev, key.idx,
3084 key.type == NL80211_KEYTYPE_PAIRWISE,
3085 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003086 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003087
Johannes Berg41ade002007-12-19 02:03:29 +01003088 return err;
3089}
3090
3091static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3092{
Johannes Berg4c476992010-10-04 21:36:35 +02003093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003094 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003095 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003096 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003097 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003098
Johannes Bergb9454e82009-07-08 13:29:08 +02003099 err = nl80211_parse_key(info, &key);
3100 if (err)
3101 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003102
3103 if (info->attrs[NL80211_ATTR_MAC])
3104 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3105
Johannes Berge31b8212010-10-05 19:39:30 +02003106 if (key.type == -1) {
3107 if (mac_addr)
3108 key.type = NL80211_KEYTYPE_PAIRWISE;
3109 else
3110 key.type = NL80211_KEYTYPE_GROUP;
3111 }
3112
3113 /* for now */
3114 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3115 key.type != NL80211_KEYTYPE_GROUP)
3116 return -EINVAL;
3117
Johannes Berg4c476992010-10-04 21:36:35 +02003118 if (!rdev->ops->del_key)
3119 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003120
Johannes Bergfffd0932009-07-08 14:22:54 +02003121 wdev_lock(dev->ieee80211_ptr);
3122 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003123
Johannes Berg0fa7b392015-01-23 11:10:12 +01003124 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003125 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3126 err = -ENOENT;
3127
Johannes Bergfffd0932009-07-08 14:22:54 +02003128 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003129 err = rdev_del_key(rdev, dev, key.idx,
3130 key.type == NL80211_KEYTYPE_PAIRWISE,
3131 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003132
Johannes Berg3d23e342009-09-29 23:27:28 +02003133#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003134 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003135 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003136 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003137 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003138 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3139 }
3140#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003141 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003142
Johannes Berg41ade002007-12-19 02:03:29 +01003143 return err;
3144}
3145
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303146/* This function returns an error or the number of nested attributes */
3147static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3148{
3149 struct nlattr *attr;
3150 int n_entries = 0, tmp;
3151
3152 nla_for_each_nested(attr, nl_attr, tmp) {
3153 if (nla_len(attr) != ETH_ALEN)
3154 return -EINVAL;
3155
3156 n_entries++;
3157 }
3158
3159 return n_entries;
3160}
3161
3162/*
3163 * This function parses ACL information and allocates memory for ACL data.
3164 * On successful return, the calling function is responsible to free the
3165 * ACL buffer returned by this function.
3166 */
3167static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3168 struct genl_info *info)
3169{
3170 enum nl80211_acl_policy acl_policy;
3171 struct nlattr *attr;
3172 struct cfg80211_acl_data *acl;
3173 int i = 0, n_entries, tmp;
3174
3175 if (!wiphy->max_acl_mac_addrs)
3176 return ERR_PTR(-EOPNOTSUPP);
3177
3178 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3179 return ERR_PTR(-EINVAL);
3180
3181 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3182 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3183 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3184 return ERR_PTR(-EINVAL);
3185
3186 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3187 return ERR_PTR(-EINVAL);
3188
3189 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3190 if (n_entries < 0)
3191 return ERR_PTR(n_entries);
3192
3193 if (n_entries > wiphy->max_acl_mac_addrs)
3194 return ERR_PTR(-ENOTSUPP);
3195
3196 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3197 GFP_KERNEL);
3198 if (!acl)
3199 return ERR_PTR(-ENOMEM);
3200
3201 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3202 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3203 i++;
3204 }
3205
3206 acl->n_acl_entries = n_entries;
3207 acl->acl_policy = acl_policy;
3208
3209 return acl;
3210}
3211
3212static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3213{
3214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3215 struct net_device *dev = info->user_ptr[1];
3216 struct cfg80211_acl_data *acl;
3217 int err;
3218
3219 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3220 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3221 return -EOPNOTSUPP;
3222
3223 if (!dev->ieee80211_ptr->beacon_interval)
3224 return -EINVAL;
3225
3226 acl = parse_acl_data(&rdev->wiphy, info);
3227 if (IS_ERR(acl))
3228 return PTR_ERR(acl);
3229
3230 err = rdev_set_mac_acl(rdev, dev, acl);
3231
3232 kfree(acl);
3233
3234 return err;
3235}
3236
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003237static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003238 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003239{
Johannes Berg88600202012-02-13 15:17:18 +01003240 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003241
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003242 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3243 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3244 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3245 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003246 return -EINVAL;
3247
Johannes Berg88600202012-02-13 15:17:18 +01003248 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003249
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003250 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3251 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3252 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003253 if (!bcn->head_len)
3254 return -EINVAL;
3255 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003256 }
3257
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003258 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3259 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3260 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003261 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003262 }
3263
Johannes Berg4c476992010-10-04 21:36:35 +02003264 if (!haveinfo)
3265 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003266
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003267 if (attrs[NL80211_ATTR_IE]) {
3268 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3269 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003270 }
3271
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003272 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003273 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003274 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003275 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003276 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003277 }
3278
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003279 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003280 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003281 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003282 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003283 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003284 }
3285
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003286 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3287 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3288 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003289 }
3290
Johannes Berg88600202012-02-13 15:17:18 +01003291 return 0;
3292}
3293
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003294static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3295 struct cfg80211_ap_settings *params)
3296{
3297 struct wireless_dev *wdev;
3298 bool ret = false;
3299
Johannes Berg89a54e42012-06-15 14:33:17 +02003300 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003301 if (wdev->iftype != NL80211_IFTYPE_AP &&
3302 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3303 continue;
3304
Johannes Berg683b6d32012-11-08 21:25:48 +01003305 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003306 continue;
3307
Johannes Berg683b6d32012-11-08 21:25:48 +01003308 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003309 ret = true;
3310 break;
3311 }
3312
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003313 return ret;
3314}
3315
Jouni Malinene39e5b52012-09-30 19:29:39 +03003316static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3317 enum nl80211_auth_type auth_type,
3318 enum nl80211_commands cmd)
3319{
3320 if (auth_type > NL80211_AUTHTYPE_MAX)
3321 return false;
3322
3323 switch (cmd) {
3324 case NL80211_CMD_AUTHENTICATE:
3325 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3326 auth_type == NL80211_AUTHTYPE_SAE)
3327 return false;
3328 return true;
3329 case NL80211_CMD_CONNECT:
3330 case NL80211_CMD_START_AP:
3331 /* SAE not supported yet */
3332 if (auth_type == NL80211_AUTHTYPE_SAE)
3333 return false;
3334 return true;
3335 default:
3336 return false;
3337 }
3338}
3339
Johannes Berg88600202012-02-13 15:17:18 +01003340static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3341{
3342 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3343 struct net_device *dev = info->user_ptr[1];
3344 struct wireless_dev *wdev = dev->ieee80211_ptr;
3345 struct cfg80211_ap_settings params;
3346 int err;
3347
3348 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3349 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3350 return -EOPNOTSUPP;
3351
3352 if (!rdev->ops->start_ap)
3353 return -EOPNOTSUPP;
3354
3355 if (wdev->beacon_interval)
3356 return -EALREADY;
3357
3358 memset(&params, 0, sizeof(params));
3359
3360 /* these are required for START_AP */
3361 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3362 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3363 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3364 return -EINVAL;
3365
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003366 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003367 if (err)
3368 return err;
3369
3370 params.beacon_interval =
3371 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3372 params.dtim_period =
3373 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3374
3375 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3376 if (err)
3377 return err;
3378
3379 /*
3380 * In theory, some of these attributes should be required here
3381 * but since they were not used when the command was originally
3382 * added, keep them optional for old user space programs to let
3383 * them continue to work with drivers that do not need the
3384 * additional information -- drivers must check!
3385 */
3386 if (info->attrs[NL80211_ATTR_SSID]) {
3387 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3388 params.ssid_len =
3389 nla_len(info->attrs[NL80211_ATTR_SSID]);
3390 if (params.ssid_len == 0 ||
3391 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3392 return -EINVAL;
3393 }
3394
3395 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3396 params.hidden_ssid = nla_get_u32(
3397 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3398 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3399 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3400 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3401 return -EINVAL;
3402 }
3403
3404 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3405
3406 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3407 params.auth_type = nla_get_u32(
3408 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003409 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3410 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003411 return -EINVAL;
3412 } else
3413 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3414
3415 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3416 NL80211_MAX_NR_CIPHER_SUITES);
3417 if (err)
3418 return err;
3419
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303420 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3421 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3422 return -EOPNOTSUPP;
3423 params.inactivity_timeout = nla_get_u16(
3424 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3425 }
3426
Johannes Berg53cabad2012-11-14 15:17:28 +01003427 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3428 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3429 return -EINVAL;
3430 params.p2p_ctwindow =
3431 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3432 if (params.p2p_ctwindow > 127)
3433 return -EINVAL;
3434 if (params.p2p_ctwindow != 0 &&
3435 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3436 return -EINVAL;
3437 }
3438
3439 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3440 u8 tmp;
3441
3442 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3443 return -EINVAL;
3444 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3445 if (tmp > 1)
3446 return -EINVAL;
3447 params.p2p_opp_ps = tmp;
3448 if (params.p2p_opp_ps != 0 &&
3449 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3450 return -EINVAL;
3451 }
3452
Johannes Bergaa430da2012-05-16 23:50:18 +02003453 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003454 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3455 if (err)
3456 return err;
3457 } else if (wdev->preset_chandef.chan) {
3458 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003459 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003460 return -EINVAL;
3461
Arik Nemtsov923b3522015-07-08 15:41:44 +03003462 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3463 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003464 return -EINVAL;
3465
Eliad Peller18998c32014-09-10 14:07:34 +03003466 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3467 params.smps_mode =
3468 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3469 switch (params.smps_mode) {
3470 case NL80211_SMPS_OFF:
3471 break;
3472 case NL80211_SMPS_STATIC:
3473 if (!(rdev->wiphy.features &
3474 NL80211_FEATURE_STATIC_SMPS))
3475 return -EINVAL;
3476 break;
3477 case NL80211_SMPS_DYNAMIC:
3478 if (!(rdev->wiphy.features &
3479 NL80211_FEATURE_DYNAMIC_SMPS))
3480 return -EINVAL;
3481 break;
3482 default:
3483 return -EINVAL;
3484 }
3485 } else {
3486 params.smps_mode = NL80211_SMPS_OFF;
3487 }
3488
Ola Olsson4baf6be2015-10-29 07:04:58 +01003489 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3490 params.acl = parse_acl_data(&rdev->wiphy, info);
3491 if (IS_ERR(params.acl))
3492 return PTR_ERR(params.acl);
3493 }
3494
Lior David34d50512016-01-28 10:58:25 +02003495 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3496 if (params.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ])
3497 return -EOPNOTSUPP;
3498
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003499 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003500 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003501 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003502 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003503 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003504 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003505 wdev->ssid_len = params.ssid_len;
3506 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003507 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003508 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303509
3510 kfree(params.acl);
3511
Johannes Berg56d18932011-05-09 18:41:15 +02003512 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003513}
3514
Johannes Berg88600202012-02-13 15:17:18 +01003515static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3516{
3517 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3518 struct net_device *dev = info->user_ptr[1];
3519 struct wireless_dev *wdev = dev->ieee80211_ptr;
3520 struct cfg80211_beacon_data params;
3521 int err;
3522
3523 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3524 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3525 return -EOPNOTSUPP;
3526
3527 if (!rdev->ops->change_beacon)
3528 return -EOPNOTSUPP;
3529
3530 if (!wdev->beacon_interval)
3531 return -EINVAL;
3532
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003533 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003534 if (err)
3535 return err;
3536
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003537 wdev_lock(wdev);
3538 err = rdev_change_beacon(rdev, dev, &params);
3539 wdev_unlock(wdev);
3540
3541 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003542}
3543
3544static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003545{
Johannes Berg4c476992010-10-04 21:36:35 +02003546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3547 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003548
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003549 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003550}
3551
Johannes Berg5727ef12007-12-19 02:03:34 +01003552static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3553 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3554 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3555 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003556 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003557 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003558 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003559};
3560
Johannes Bergeccb8e82009-05-11 21:57:56 +03003561static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003562 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003563 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003564{
3565 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003566 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003567 int flag;
3568
Johannes Bergeccb8e82009-05-11 21:57:56 +03003569 /*
3570 * Try parsing the new attribute first so userspace
3571 * can specify both for older kernels.
3572 */
3573 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3574 if (nla) {
3575 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003576
Johannes Bergeccb8e82009-05-11 21:57:56 +03003577 sta_flags = nla_data(nla);
3578 params->sta_flags_mask = sta_flags->mask;
3579 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003580 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003581 if ((params->sta_flags_mask |
3582 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3583 return -EINVAL;
3584 return 0;
3585 }
3586
3587 /* if present, parse the old attribute */
3588
3589 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003590 if (!nla)
3591 return 0;
3592
3593 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3594 nla, sta_flags_policy))
3595 return -EINVAL;
3596
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003597 /*
3598 * Only allow certain flags for interface types so that
3599 * other attributes are silently ignored. Remember that
3600 * this is backward compatibility code with old userspace
3601 * and shouldn't be hit in other cases anyway.
3602 */
3603 switch (iftype) {
3604 case NL80211_IFTYPE_AP:
3605 case NL80211_IFTYPE_AP_VLAN:
3606 case NL80211_IFTYPE_P2P_GO:
3607 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3608 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3609 BIT(NL80211_STA_FLAG_WME) |
3610 BIT(NL80211_STA_FLAG_MFP);
3611 break;
3612 case NL80211_IFTYPE_P2P_CLIENT:
3613 case NL80211_IFTYPE_STATION:
3614 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3615 BIT(NL80211_STA_FLAG_TDLS_PEER);
3616 break;
3617 case NL80211_IFTYPE_MESH_POINT:
3618 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3619 BIT(NL80211_STA_FLAG_MFP) |
3620 BIT(NL80211_STA_FLAG_AUTHORIZED);
3621 default:
3622 return -EINVAL;
3623 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003624
Johannes Berg3383b5a2012-05-10 20:14:43 +02003625 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3626 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003627 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003628
Johannes Berg3383b5a2012-05-10 20:14:43 +02003629 /* no longer support new API additions in old API */
3630 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3631 return -EINVAL;
3632 }
3633 }
3634
Johannes Berg5727ef12007-12-19 02:03:34 +01003635 return 0;
3636}
3637
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003638static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3639 int attr)
3640{
3641 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003642 u32 bitrate;
3643 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003644 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003645
3646 rate = nla_nest_start(msg, attr);
3647 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003648 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003649
3650 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3651 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003652 /* report 16-bit bitrate only if we can */
3653 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003654 if (bitrate > 0 &&
3655 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3656 return false;
3657 if (bitrate_compat > 0 &&
3658 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3659 return false;
3660
Johannes Bergb51f3be2015-01-15 16:14:02 +01003661 switch (info->bw) {
3662 case RATE_INFO_BW_5:
3663 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3664 break;
3665 case RATE_INFO_BW_10:
3666 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3667 break;
3668 default:
3669 WARN_ON(1);
3670 /* fall through */
3671 case RATE_INFO_BW_20:
3672 rate_flg = 0;
3673 break;
3674 case RATE_INFO_BW_40:
3675 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3676 break;
3677 case RATE_INFO_BW_80:
3678 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3679 break;
3680 case RATE_INFO_BW_160:
3681 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3682 break;
3683 }
3684
3685 if (rate_flg && nla_put_flag(msg, rate_flg))
3686 return false;
3687
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003688 if (info->flags & RATE_INFO_FLAGS_MCS) {
3689 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3690 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003691 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3692 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3693 return false;
3694 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3695 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3696 return false;
3697 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3698 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003699 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3700 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3701 return false;
3702 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003703
3704 nla_nest_end(msg, rate);
3705 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003706}
3707
Felix Fietkau119363c2013-04-22 16:29:30 +02003708static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3709 int id)
3710{
3711 void *attr;
3712 int i = 0;
3713
3714 if (!mask)
3715 return true;
3716
3717 attr = nla_nest_start(msg, id);
3718 if (!attr)
3719 return false;
3720
3721 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3722 if (!(mask & BIT(i)))
3723 continue;
3724
3725 if (nla_put_u8(msg, i, signal[i]))
3726 return false;
3727 }
3728
3729 nla_nest_end(msg, attr);
3730
3731 return true;
3732}
3733
Johannes Bergcf5ead82014-11-14 17:14:00 +01003734static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3735 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003736 struct cfg80211_registered_device *rdev,
3737 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003738 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003739{
3740 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003741 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003742
Johannes Bergcf5ead82014-11-14 17:14:00 +01003743 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003744 if (!hdr)
3745 return -1;
3746
David S. Miller9360ffd2012-03-29 04:41:26 -04003747 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3748 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3749 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3750 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003751
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003752 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3753 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003754 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003755
3756#define PUT_SINFO(attr, memb, type) do { \
3757 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3758 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3759 sinfo->memb)) \
3760 goto nla_put_failure; \
3761 } while (0)
3762
3763 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3764 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3765
3766 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3767 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003768 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003769 (u32)sinfo->rx_bytes))
3770 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003771
3772 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3773 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003774 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3775 (u32)sinfo->tx_bytes))
3776 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003777
3778 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3779 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3780 PUT_SINFO(LLID, llid, u16);
3781 PUT_SINFO(PLID, plid, u16);
3782 PUT_SINFO(PLINK_STATE, plink_state, u8);
3783
John W. Linville66266b32012-03-15 13:25:41 -04003784 switch (rdev->wiphy.signal_type) {
3785 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003786 PUT_SINFO(SIGNAL, signal, u8);
3787 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003788 break;
3789 default:
3790 break;
3791 }
Johannes Berg319090b2014-11-17 14:08:11 +01003792 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003793 if (!nl80211_put_signal(msg, sinfo->chains,
3794 sinfo->chain_signal,
3795 NL80211_STA_INFO_CHAIN_SIGNAL))
3796 goto nla_put_failure;
3797 }
Johannes Berg319090b2014-11-17 14:08:11 +01003798 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003799 if (!nl80211_put_signal(msg, sinfo->chains,
3800 sinfo->chain_signal_avg,
3801 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3802 goto nla_put_failure;
3803 }
Johannes Berg319090b2014-11-17 14:08:11 +01003804 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003805 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3806 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003807 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003808 }
Johannes Berg319090b2014-11-17 14:08:11 +01003809 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003810 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3811 NL80211_STA_INFO_RX_BITRATE))
3812 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003813 }
Johannes Berg319090b2014-11-17 14:08:11 +01003814
3815 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3816 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3817 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3818 PUT_SINFO(TX_FAILED, tx_failed, u32);
3819 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3820 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3821 PUT_SINFO(LOCAL_PM, local_pm, u32);
3822 PUT_SINFO(PEER_PM, peer_pm, u32);
3823 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3824
3825 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003826 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3827 if (!bss_param)
3828 goto nla_put_failure;
3829
David S. Miller9360ffd2012-03-29 04:41:26 -04003830 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3831 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3832 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3833 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3834 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3835 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3836 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3837 sinfo->bss_param.dtim_period) ||
3838 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3839 sinfo->bss_param.beacon_interval))
3840 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003841
3842 nla_nest_end(msg, bss_param);
3843 }
Johannes Berg319090b2014-11-17 14:08:11 +01003844 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003845 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3846 sizeof(struct nl80211_sta_flag_update),
3847 &sinfo->sta_flags))
3848 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003849
3850 PUT_SINFO(T_OFFSET, t_offset, u64);
3851 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003852 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3853 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003854
3855#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003856
3857 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3858 struct nlattr *tidsattr;
3859 int tid;
3860
3861 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3862 if (!tidsattr)
3863 goto nla_put_failure;
3864
3865 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3866 struct cfg80211_tid_stats *tidstats;
3867 struct nlattr *tidattr;
3868
3869 tidstats = &sinfo->pertid[tid];
3870
3871 if (!tidstats->filled)
3872 continue;
3873
3874 tidattr = nla_nest_start(msg, tid + 1);
3875 if (!tidattr)
3876 goto nla_put_failure;
3877
3878#define PUT_TIDVAL(attr, memb, type) do { \
3879 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3880 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3881 tidstats->memb)) \
3882 goto nla_put_failure; \
3883 } while (0)
3884
3885 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3886 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3887 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3888 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3889
3890#undef PUT_TIDVAL
3891 nla_nest_end(msg, tidattr);
3892 }
3893
3894 nla_nest_end(msg, tidsattr);
3895 }
3896
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003897 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003898
Johannes Berg319090b2014-11-17 14:08:11 +01003899 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003900 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3901 sinfo->assoc_req_ies))
3902 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003903
Johannes Berg053c0952015-01-16 22:09:00 +01003904 genlmsg_end(msg, hdr);
3905 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003906
3907 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003908 genlmsg_cancel(msg, hdr);
3909 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003910}
3911
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003912static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003913 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003914{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003915 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003916 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003917 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003918 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003919 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003920 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003921
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003922 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003923 if (err)
3924 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003925
Johannes Berg97990a02013-04-19 01:02:55 +02003926 if (!wdev->netdev) {
3927 err = -EINVAL;
3928 goto out_err;
3929 }
3930
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003931 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003932 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003933 goto out_err;
3934 }
3935
Johannes Bergbba95fe2008-07-29 13:22:51 +02003936 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003937 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003938 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003939 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003940 if (err == -ENOENT)
3941 break;
3942 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003943 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003944
Johannes Bergcf5ead82014-11-14 17:14:00 +01003945 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003946 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003947 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003948 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003949 &sinfo) < 0)
3950 goto out;
3951
3952 sta_idx++;
3953 }
3954
3955
3956 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003957 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003958 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003959 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003960 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003961
3962 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003963}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003964
Johannes Berg5727ef12007-12-19 02:03:34 +01003965static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3966{
Johannes Berg4c476992010-10-04 21:36:35 +02003967 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3968 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003969 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003970 struct sk_buff *msg;
3971 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003972 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003973
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003974 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003975
3976 if (!info->attrs[NL80211_ATTR_MAC])
3977 return -EINVAL;
3978
3979 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3980
Johannes Berg4c476992010-10-04 21:36:35 +02003981 if (!rdev->ops->get_station)
3982 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003983
Hila Gonene35e4d22012-06-27 17:19:42 +03003984 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003985 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003986 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003987
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003989 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003990 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003991
Johannes Bergcf5ead82014-11-14 17:14:00 +01003992 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3993 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003994 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003995 nlmsg_free(msg);
3996 return -ENOBUFS;
3997 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003998
Johannes Berg4c476992010-10-04 21:36:35 +02003999 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004000}
4001
Johannes Berg77ee7c82013-02-15 00:48:33 +01004002int cfg80211_check_station_change(struct wiphy *wiphy,
4003 struct station_parameters *params,
4004 enum cfg80211_station_type statype)
4005{
Ayala Bekere4208422015-10-23 11:20:06 +03004006 if (params->listen_interval != -1 &&
4007 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004008 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004009
Ayala Beker17b94242016-03-17 15:41:38 +02004010 if (params->support_p2p_ps != -1 &&
4011 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4012 return -EINVAL;
4013
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004014 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004015 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4016 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004017 return -EINVAL;
4018
4019 /* When you run into this, adjust the code below for the new flag */
4020 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4021
4022 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004023 case CFG80211_STA_MESH_PEER_KERNEL:
4024 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004025 /*
4026 * No ignoring the TDLS flag here -- the userspace mesh
4027 * code doesn't have the bug of including TDLS in the
4028 * mask everywhere.
4029 */
4030 if (params->sta_flags_mask &
4031 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4032 BIT(NL80211_STA_FLAG_MFP) |
4033 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4034 return -EINVAL;
4035 break;
4036 case CFG80211_STA_TDLS_PEER_SETUP:
4037 case CFG80211_STA_TDLS_PEER_ACTIVE:
4038 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4039 return -EINVAL;
4040 /* ignore since it can't change */
4041 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4042 break;
4043 default:
4044 /* disallow mesh-specific things */
4045 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4046 return -EINVAL;
4047 if (params->local_pm)
4048 return -EINVAL;
4049 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4050 return -EINVAL;
4051 }
4052
4053 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4054 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4055 /* TDLS can't be set, ... */
4056 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4057 return -EINVAL;
4058 /*
4059 * ... but don't bother the driver with it. This works around
4060 * a hostapd/wpa_supplicant issue -- it always includes the
4061 * TLDS_PEER flag in the mask even for AP mode.
4062 */
4063 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4064 }
4065
Ayala Beker47edb112015-09-21 15:49:53 +03004066 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4067 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004068 /* reject other things that can't change */
4069 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4070 return -EINVAL;
4071 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4072 return -EINVAL;
4073 if (params->supported_rates)
4074 return -EINVAL;
4075 if (params->ext_capab || params->ht_capa || params->vht_capa)
4076 return -EINVAL;
4077 }
4078
Ayala Beker47edb112015-09-21 15:49:53 +03004079 if (statype != CFG80211_STA_AP_CLIENT &&
4080 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004081 if (params->vlan)
4082 return -EINVAL;
4083 }
4084
4085 switch (statype) {
4086 case CFG80211_STA_AP_MLME_CLIENT:
4087 /* Use this only for authorizing/unauthorizing a station */
4088 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4089 return -EOPNOTSUPP;
4090 break;
4091 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004092 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004093 /* accept only the listed bits */
4094 if (params->sta_flags_mask &
4095 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4096 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4097 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4098 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4099 BIT(NL80211_STA_FLAG_WME) |
4100 BIT(NL80211_STA_FLAG_MFP)))
4101 return -EINVAL;
4102
4103 /* but authenticated/associated only if driver handles it */
4104 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4105 params->sta_flags_mask &
4106 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4107 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4108 return -EINVAL;
4109 break;
4110 case CFG80211_STA_IBSS:
4111 case CFG80211_STA_AP_STA:
4112 /* reject any changes other than AUTHORIZED */
4113 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4114 return -EINVAL;
4115 break;
4116 case CFG80211_STA_TDLS_PEER_SETUP:
4117 /* reject any changes other than AUTHORIZED or WME */
4118 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4119 BIT(NL80211_STA_FLAG_WME)))
4120 return -EINVAL;
4121 /* force (at least) rates when authorizing */
4122 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4123 !params->supported_rates)
4124 return -EINVAL;
4125 break;
4126 case CFG80211_STA_TDLS_PEER_ACTIVE:
4127 /* reject any changes */
4128 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004129 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004130 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4131 return -EINVAL;
4132 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004133 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004134 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4135 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004136 return -EINVAL;
4137 break;
4138 }
4139
4140 return 0;
4141}
4142EXPORT_SYMBOL(cfg80211_check_station_change);
4143
Johannes Berg5727ef12007-12-19 02:03:34 +01004144/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004145 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004146 */
Johannes Berg80b99892011-11-18 16:23:01 +01004147static struct net_device *get_vlan(struct genl_info *info,
4148 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004149{
Johannes Berg463d0182009-07-14 00:33:35 +02004150 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004151 struct net_device *v;
4152 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004153
Johannes Berg80b99892011-11-18 16:23:01 +01004154 if (!vlanattr)
4155 return NULL;
4156
4157 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4158 if (!v)
4159 return ERR_PTR(-ENODEV);
4160
4161 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4162 ret = -EINVAL;
4163 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004164 }
Johannes Berg80b99892011-11-18 16:23:01 +01004165
Johannes Berg77ee7c82013-02-15 00:48:33 +01004166 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4167 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4168 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4169 ret = -EINVAL;
4170 goto error;
4171 }
4172
Johannes Berg80b99892011-11-18 16:23:01 +01004173 if (!netif_running(v)) {
4174 ret = -ENETDOWN;
4175 goto error;
4176 }
4177
4178 return v;
4179 error:
4180 dev_put(v);
4181 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004182}
4183
Johannes Berg94e860f2014-01-20 23:58:15 +01004184static const struct nla_policy
4185nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004186 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4187 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4188};
4189
Johannes Bergff276692013-02-15 00:09:01 +01004190static int nl80211_parse_sta_wme(struct genl_info *info,
4191 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004192{
Jouni Malinendf881292013-02-14 21:10:54 +02004193 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4194 struct nlattr *nla;
4195 int err;
4196
Jouni Malinendf881292013-02-14 21:10:54 +02004197 /* parse WME attributes if present */
4198 if (!info->attrs[NL80211_ATTR_STA_WME])
4199 return 0;
4200
4201 nla = info->attrs[NL80211_ATTR_STA_WME];
4202 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4203 nl80211_sta_wme_policy);
4204 if (err)
4205 return err;
4206
4207 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4208 params->uapsd_queues = nla_get_u8(
4209 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4210 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4211 return -EINVAL;
4212
4213 if (tb[NL80211_STA_WME_MAX_SP])
4214 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4215
4216 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4217 return -EINVAL;
4218
4219 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4220
4221 return 0;
4222}
4223
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304224static int nl80211_parse_sta_channel_info(struct genl_info *info,
4225 struct station_parameters *params)
4226{
4227 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4228 params->supported_channels =
4229 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4230 params->supported_channels_len =
4231 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4232 /*
4233 * Need to include at least one (first channel, number of
4234 * channels) tuple for each subband, and must have proper
4235 * tuples for the rest of the data as well.
4236 */
4237 if (params->supported_channels_len < 2)
4238 return -EINVAL;
4239 if (params->supported_channels_len % 2)
4240 return -EINVAL;
4241 }
4242
4243 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4244 params->supported_oper_classes =
4245 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4246 params->supported_oper_classes_len =
4247 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4248 /*
4249 * The value of the Length field of the Supported Operating
4250 * Classes element is between 2 and 253.
4251 */
4252 if (params->supported_oper_classes_len < 2 ||
4253 params->supported_oper_classes_len > 253)
4254 return -EINVAL;
4255 }
4256 return 0;
4257}
4258
Johannes Bergff276692013-02-15 00:09:01 +01004259static int nl80211_set_station_tdls(struct genl_info *info,
4260 struct station_parameters *params)
4261{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304262 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004263 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004264 if (info->attrs[NL80211_ATTR_PEER_AID])
4265 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004266 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4267 params->ht_capa =
4268 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4269 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4270 params->vht_capa =
4271 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4272
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304273 err = nl80211_parse_sta_channel_info(info, params);
4274 if (err)
4275 return err;
4276
Johannes Bergff276692013-02-15 00:09:01 +01004277 return nl80211_parse_sta_wme(info, params);
4278}
4279
Johannes Berg5727ef12007-12-19 02:03:34 +01004280static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4281{
Johannes Berg4c476992010-10-04 21:36:35 +02004282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004283 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004284 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004285 u8 *mac_addr;
4286 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004287
4288 memset(&params, 0, sizeof(params));
4289
Johannes Berg77ee7c82013-02-15 00:48:33 +01004290 if (!rdev->ops->change_station)
4291 return -EOPNOTSUPP;
4292
Ayala Bekere4208422015-10-23 11:20:06 +03004293 /*
4294 * AID and listen_interval properties can be set only for unassociated
4295 * station. Include these parameters here and will check them in
4296 * cfg80211_check_station_change().
4297 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004298 if (info->attrs[NL80211_ATTR_STA_AID])
4299 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004300
4301 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4302 params.listen_interval =
4303 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4304 else
4305 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004306
Ayala Beker17b94242016-03-17 15:41:38 +02004307 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4308 u8 tmp;
4309
4310 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4311 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4312 return -EINVAL;
4313
4314 params.support_p2p_ps = tmp;
4315 } else {
4316 params.support_p2p_ps = -1;
4317 }
4318
Johannes Berg5727ef12007-12-19 02:03:34 +01004319 if (!info->attrs[NL80211_ATTR_MAC])
4320 return -EINVAL;
4321
4322 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4323
4324 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4325 params.supported_rates =
4326 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4327 params.supported_rates_len =
4328 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4329 }
4330
Jouni Malinen9d62a982013-02-14 21:10:13 +02004331 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4332 params.capability =
4333 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4334 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4335 }
4336
4337 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4338 params.ext_capab =
4339 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4340 params.ext_capab_len =
4341 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4342 }
4343
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004344 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004345 return -EINVAL;
4346
Johannes Bergf8bacc22013-02-14 23:27:01 +01004347 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004348 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004349 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4350 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4351 return -EINVAL;
4352 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004353
Johannes Bergf8bacc22013-02-14 23:27:01 +01004354 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004355 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004356 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4357 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4358 return -EINVAL;
4359 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4360 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004361
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004362 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4363 enum nl80211_mesh_power_mode pm = nla_get_u32(
4364 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4365
4366 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4367 pm > NL80211_MESH_POWER_MAX)
4368 return -EINVAL;
4369
4370 params.local_pm = pm;
4371 }
4372
Johannes Berg77ee7c82013-02-15 00:48:33 +01004373 /* Include parameters for TDLS peer (will check later) */
4374 err = nl80211_set_station_tdls(info, &params);
4375 if (err)
4376 return err;
4377
4378 params.vlan = get_vlan(info, rdev);
4379 if (IS_ERR(params.vlan))
4380 return PTR_ERR(params.vlan);
4381
Johannes Berga97f4422009-06-18 17:23:43 +02004382 switch (dev->ieee80211_ptr->iftype) {
4383 case NL80211_IFTYPE_AP:
4384 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004385 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004386 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004387 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004388 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004389 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004390 break;
4391 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004392 err = -EOPNOTSUPP;
4393 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004394 }
4395
Johannes Berg77ee7c82013-02-15 00:48:33 +01004396 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004397 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004398
Johannes Berg77ee7c82013-02-15 00:48:33 +01004399 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004400 if (params.vlan)
4401 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004402
Johannes Berg5727ef12007-12-19 02:03:34 +01004403 return err;
4404}
4405
4406static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4407{
Johannes Berg4c476992010-10-04 21:36:35 +02004408 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004409 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004410 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004411 struct station_parameters params;
4412 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004413 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4414 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004415
4416 memset(&params, 0, sizeof(params));
4417
Johannes Berg984c3112013-02-14 23:43:25 +01004418 if (!rdev->ops->add_station)
4419 return -EOPNOTSUPP;
4420
Johannes Berg5727ef12007-12-19 02:03:34 +01004421 if (!info->attrs[NL80211_ATTR_MAC])
4422 return -EINVAL;
4423
Johannes Berg5727ef12007-12-19 02:03:34 +01004424 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4425 return -EINVAL;
4426
4427 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4428 return -EINVAL;
4429
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004430 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4431 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004432 return -EINVAL;
4433
Johannes Berg5727ef12007-12-19 02:03:34 +01004434 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4435 params.supported_rates =
4436 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4437 params.supported_rates_len =
4438 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4439 params.listen_interval =
4440 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004441
Ayala Beker17b94242016-03-17 15:41:38 +02004442 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4443 u8 tmp;
4444
4445 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4446 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4447 return -EINVAL;
4448
4449 params.support_p2p_ps = tmp;
4450 } else {
4451 /*
4452 * if not specified, assume it's supported for P2P GO interface,
4453 * and is NOT supported for AP interface
4454 */
4455 params.support_p2p_ps =
4456 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4457 }
4458
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004459 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004460 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004461 else
4462 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004463 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4464 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004465
Jouni Malinen9d62a982013-02-14 21:10:13 +02004466 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4467 params.capability =
4468 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4469 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4470 }
4471
4472 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4473 params.ext_capab =
4474 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4475 params.ext_capab_len =
4476 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4477 }
4478
Jouni Malinen36aedc92008-08-25 11:58:58 +03004479 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4480 params.ht_capa =
4481 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004482
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004483 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4484 params.vht_capa =
4485 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4486
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004487 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4488 params.opmode_notif_used = true;
4489 params.opmode_notif =
4490 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4491 }
4492
Johannes Bergf8bacc22013-02-14 23:27:01 +01004493 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004494 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004495 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4496 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4497 return -EINVAL;
4498 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004499
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304500 err = nl80211_parse_sta_channel_info(info, &params);
4501 if (err)
4502 return err;
4503
Johannes Bergff276692013-02-15 00:09:01 +01004504 err = nl80211_parse_sta_wme(info, &params);
4505 if (err)
4506 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004507
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004508 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004509 return -EINVAL;
4510
Johannes Berg496fcc22015-03-12 08:53:27 +02004511 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4512 * as userspace might just pass through the capabilities from the IEs
4513 * directly, rather than enforcing this restriction and returning an
4514 * error in this case.
4515 */
4516 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4517 params.ht_capa = NULL;
4518 params.vht_capa = NULL;
4519 }
4520
Johannes Berg77ee7c82013-02-15 00:48:33 +01004521 /* When you run into this, adjust the code below for the new flag */
4522 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4523
Johannes Bergbdd90d52011-12-14 12:20:27 +01004524 switch (dev->ieee80211_ptr->iftype) {
4525 case NL80211_IFTYPE_AP:
4526 case NL80211_IFTYPE_AP_VLAN:
4527 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004528 /* ignore WME attributes if iface/sta is not capable */
4529 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4530 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4531 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004532
Johannes Bergbdd90d52011-12-14 12:20:27 +01004533 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004534 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4535 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004536 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004537 /* but don't bother the driver with it */
4538 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004539
Johannes Bergd582cff2012-10-26 17:53:44 +02004540 /* allow authenticated/associated only if driver handles it */
4541 if (!(rdev->wiphy.features &
4542 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004543 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004544 return -EINVAL;
4545
Johannes Bergbda95eb2015-11-26 16:26:13 +01004546 /* Older userspace, or userspace wanting to be compatible with
4547 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4548 * and assoc flags in the mask, but assumes the station will be
4549 * added as associated anyway since this was the required driver
4550 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4551 * introduced.
4552 * In order to not bother drivers with this quirk in the API
4553 * set the flags in both the mask and set for new stations in
4554 * this case.
4555 */
4556 if (!(params.sta_flags_mask & auth_assoc)) {
4557 params.sta_flags_mask |= auth_assoc;
4558 params.sta_flags_set |= auth_assoc;
4559 }
4560
Johannes Bergbdd90d52011-12-14 12:20:27 +01004561 /* must be last in here for error handling */
4562 params.vlan = get_vlan(info, rdev);
4563 if (IS_ERR(params.vlan))
4564 return PTR_ERR(params.vlan);
4565 break;
4566 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004567 /* ignore uAPSD data */
4568 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4569
Johannes Bergd582cff2012-10-26 17:53:44 +02004570 /* associated is disallowed */
4571 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4572 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004573 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004574 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4575 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004576 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004577 break;
4578 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004579 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004580 /* ignore uAPSD data */
4581 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4582
Johannes Berg77ee7c82013-02-15 00:48:33 +01004583 /* these are disallowed */
4584 if (params.sta_flags_mask &
4585 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4586 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004587 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004588 /* Only TDLS peers can be added */
4589 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4590 return -EINVAL;
4591 /* Can only add if TDLS ... */
4592 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4593 return -EOPNOTSUPP;
4594 /* ... with external setup is supported */
4595 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4596 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004597 /*
4598 * Older wpa_supplicant versions always mark the TDLS peer
4599 * as authorized, but it shouldn't yet be.
4600 */
4601 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004602 break;
4603 default:
4604 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004605 }
4606
Johannes Bergbdd90d52011-12-14 12:20:27 +01004607 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004608
Hila Gonene35e4d22012-06-27 17:19:42 +03004609 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004610
Johannes Berg5727ef12007-12-19 02:03:34 +01004611 if (params.vlan)
4612 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004613 return err;
4614}
4615
4616static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4617{
Johannes Berg4c476992010-10-04 21:36:35 +02004618 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4619 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004620 struct station_del_parameters params;
4621
4622 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004623
4624 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004625 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004626
Johannes Berge80cf852009-05-11 14:43:13 +02004627 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004628 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004629 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004630 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4631 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004632
Johannes Berg4c476992010-10-04 21:36:35 +02004633 if (!rdev->ops->del_station)
4634 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004635
Jouni Malinen98856862014-10-20 13:20:45 +03004636 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4637 params.subtype =
4638 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4639 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4640 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4641 return -EINVAL;
4642 } else {
4643 /* Default to Deauthentication frame */
4644 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4645 }
4646
4647 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4648 params.reason_code =
4649 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4650 if (params.reason_code == 0)
4651 return -EINVAL; /* 0 is reserved */
4652 } else {
4653 /* Default to reason code 2 */
4654 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4655 }
4656
Jouni Malinen89c771e2014-10-10 20:52:40 +03004657 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004658}
4659
Eric W. Biederman15e47302012-09-07 20:12:54 +00004660static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004661 int flags, struct net_device *dev,
4662 u8 *dst, u8 *next_hop,
4663 struct mpath_info *pinfo)
4664{
4665 void *hdr;
4666 struct nlattr *pinfoattr;
4667
Henning Rogge1ef4c852014-11-04 16:14:58 +01004668 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004669 if (!hdr)
4670 return -1;
4671
David S. Miller9360ffd2012-03-29 04:41:26 -04004672 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4673 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4674 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4675 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4676 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004677
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004678 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4679 if (!pinfoattr)
4680 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004681 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4682 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4683 pinfo->frame_qlen))
4684 goto nla_put_failure;
4685 if (((pinfo->filled & MPATH_INFO_SN) &&
4686 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4687 ((pinfo->filled & MPATH_INFO_METRIC) &&
4688 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4689 pinfo->metric)) ||
4690 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4691 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4692 pinfo->exptime)) ||
4693 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4694 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4695 pinfo->flags)) ||
4696 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4697 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4698 pinfo->discovery_timeout)) ||
4699 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4700 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4701 pinfo->discovery_retries)))
4702 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004703
4704 nla_nest_end(msg, pinfoattr);
4705
Johannes Berg053c0952015-01-16 22:09:00 +01004706 genlmsg_end(msg, hdr);
4707 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004708
4709 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004710 genlmsg_cancel(msg, hdr);
4711 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004712}
4713
4714static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004715 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004716{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004717 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004718 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004719 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004720 u8 dst[ETH_ALEN];
4721 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004722 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004723 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004724
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004725 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004726 if (err)
4727 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004728
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004729 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004730 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004731 goto out_err;
4732 }
4733
Johannes Berg97990a02013-04-19 01:02:55 +02004734 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004735 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004736 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004737 }
4738
Johannes Bergbba95fe2008-07-29 13:22:51 +02004739 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004740 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004741 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004742 if (err == -ENOENT)
4743 break;
4744 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004745 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004746
Eric W. Biederman15e47302012-09-07 20:12:54 +00004747 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004748 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004749 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004750 &pinfo) < 0)
4751 goto out;
4752
4753 path_idx++;
4754 }
4755
4756
4757 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004758 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004759 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004760 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004761 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004762 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004763}
4764
4765static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4766{
Johannes Berg4c476992010-10-04 21:36:35 +02004767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004768 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004769 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004770 struct mpath_info pinfo;
4771 struct sk_buff *msg;
4772 u8 *dst = NULL;
4773 u8 next_hop[ETH_ALEN];
4774
4775 memset(&pinfo, 0, sizeof(pinfo));
4776
4777 if (!info->attrs[NL80211_ATTR_MAC])
4778 return -EINVAL;
4779
4780 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4781
Johannes Berg4c476992010-10-04 21:36:35 +02004782 if (!rdev->ops->get_mpath)
4783 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004784
Johannes Berg4c476992010-10-04 21:36:35 +02004785 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4786 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004787
Hila Gonene35e4d22012-06-27 17:19:42 +03004788 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004789 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004790 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004791
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004792 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004793 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004794 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004795
Eric W. Biederman15e47302012-09-07 20:12:54 +00004796 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004797 dev, dst, next_hop, &pinfo) < 0) {
4798 nlmsg_free(msg);
4799 return -ENOBUFS;
4800 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004801
Johannes Berg4c476992010-10-04 21:36:35 +02004802 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004803}
4804
4805static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4806{
Johannes Berg4c476992010-10-04 21:36:35 +02004807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4808 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004809 u8 *dst = NULL;
4810 u8 *next_hop = NULL;
4811
4812 if (!info->attrs[NL80211_ATTR_MAC])
4813 return -EINVAL;
4814
4815 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4816 return -EINVAL;
4817
4818 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4819 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4820
Johannes Berg4c476992010-10-04 21:36:35 +02004821 if (!rdev->ops->change_mpath)
4822 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004823
Johannes Berg4c476992010-10-04 21:36:35 +02004824 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4825 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004826
Hila Gonene35e4d22012-06-27 17:19:42 +03004827 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004828}
Johannes Berg4c476992010-10-04 21:36:35 +02004829
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004830static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4831{
Johannes Berg4c476992010-10-04 21:36:35 +02004832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4833 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004834 u8 *dst = NULL;
4835 u8 *next_hop = NULL;
4836
4837 if (!info->attrs[NL80211_ATTR_MAC])
4838 return -EINVAL;
4839
4840 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4841 return -EINVAL;
4842
4843 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4844 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4845
Johannes Berg4c476992010-10-04 21:36:35 +02004846 if (!rdev->ops->add_mpath)
4847 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004848
Johannes Berg4c476992010-10-04 21:36:35 +02004849 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4850 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004851
Hila Gonene35e4d22012-06-27 17:19:42 +03004852 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004853}
4854
4855static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4856{
Johannes Berg4c476992010-10-04 21:36:35 +02004857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4858 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004859 u8 *dst = NULL;
4860
4861 if (info->attrs[NL80211_ATTR_MAC])
4862 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4863
Johannes Berg4c476992010-10-04 21:36:35 +02004864 if (!rdev->ops->del_mpath)
4865 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004866
Hila Gonene35e4d22012-06-27 17:19:42 +03004867 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004868}
4869
Henning Rogge66be7d22014-09-12 08:58:49 +02004870static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4871{
4872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4873 int err;
4874 struct net_device *dev = info->user_ptr[1];
4875 struct mpath_info pinfo;
4876 struct sk_buff *msg;
4877 u8 *dst = NULL;
4878 u8 mpp[ETH_ALEN];
4879
4880 memset(&pinfo, 0, sizeof(pinfo));
4881
4882 if (!info->attrs[NL80211_ATTR_MAC])
4883 return -EINVAL;
4884
4885 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4886
4887 if (!rdev->ops->get_mpp)
4888 return -EOPNOTSUPP;
4889
4890 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4891 return -EOPNOTSUPP;
4892
4893 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4894 if (err)
4895 return err;
4896
4897 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4898 if (!msg)
4899 return -ENOMEM;
4900
4901 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4902 dev, dst, mpp, &pinfo) < 0) {
4903 nlmsg_free(msg);
4904 return -ENOBUFS;
4905 }
4906
4907 return genlmsg_reply(msg, info);
4908}
4909
4910static int nl80211_dump_mpp(struct sk_buff *skb,
4911 struct netlink_callback *cb)
4912{
4913 struct mpath_info pinfo;
4914 struct cfg80211_registered_device *rdev;
4915 struct wireless_dev *wdev;
4916 u8 dst[ETH_ALEN];
4917 u8 mpp[ETH_ALEN];
4918 int path_idx = cb->args[2];
4919 int err;
4920
4921 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4922 if (err)
4923 return err;
4924
4925 if (!rdev->ops->dump_mpp) {
4926 err = -EOPNOTSUPP;
4927 goto out_err;
4928 }
4929
4930 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4931 err = -EOPNOTSUPP;
4932 goto out_err;
4933 }
4934
4935 while (1) {
4936 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4937 mpp, &pinfo);
4938 if (err == -ENOENT)
4939 break;
4940 if (err)
4941 goto out_err;
4942
4943 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4944 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4945 wdev->netdev, dst, mpp,
4946 &pinfo) < 0)
4947 goto out;
4948
4949 path_idx++;
4950 }
4951
4952 out:
4953 cb->args[2] = path_idx;
4954 err = skb->len;
4955 out_err:
4956 nl80211_finish_wdev_dump(rdev);
4957 return err;
4958}
4959
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004960static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4961{
Johannes Berg4c476992010-10-04 21:36:35 +02004962 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4963 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004964 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004965 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004966 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004967
4968 memset(&params, 0, sizeof(params));
4969 /* default to not changing parameters */
4970 params.use_cts_prot = -1;
4971 params.use_short_preamble = -1;
4972 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004973 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004974 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004975 params.p2p_ctwindow = -1;
4976 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004977
4978 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4979 params.use_cts_prot =
4980 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4981 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4982 params.use_short_preamble =
4983 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4984 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4985 params.use_short_slot_time =
4986 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004987 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4988 params.basic_rates =
4989 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4990 params.basic_rates_len =
4991 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4992 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004993 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4994 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004995 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4996 params.ht_opmode =
4997 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004998
Johannes Berg53cabad2012-11-14 15:17:28 +01004999 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5000 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5001 return -EINVAL;
5002 params.p2p_ctwindow =
5003 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5004 if (params.p2p_ctwindow < 0)
5005 return -EINVAL;
5006 if (params.p2p_ctwindow != 0 &&
5007 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5008 return -EINVAL;
5009 }
5010
5011 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5012 u8 tmp;
5013
5014 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5015 return -EINVAL;
5016 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5017 if (tmp > 1)
5018 return -EINVAL;
5019 params.p2p_opp_ps = tmp;
5020 if (params.p2p_opp_ps &&
5021 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5022 return -EINVAL;
5023 }
5024
Johannes Berg4c476992010-10-04 21:36:35 +02005025 if (!rdev->ops->change_bss)
5026 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005027
Johannes Berg074ac8d2010-09-16 14:58:22 +02005028 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005029 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5030 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005031
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005032 wdev_lock(wdev);
5033 err = rdev_change_bss(rdev, dev, &params);
5034 wdev_unlock(wdev);
5035
5036 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005037}
5038
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005039static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5040{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005041 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005042 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005043 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005044 u32 owner_nlportid;
5045
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005046
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005047 /*
5048 * You should only get this when cfg80211 hasn't yet initialized
5049 * completely when built-in to the kernel right between the time
5050 * window between nl80211_init() and regulatory_init(), if that is
5051 * even possible.
5052 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005053 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005054 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005055
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005056 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5057 user_reg_hint_type =
5058 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5059 else
5060 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5061
5062 switch (user_reg_hint_type) {
5063 case NL80211_USER_REG_HINT_USER:
5064 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005065 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5066 return -EINVAL;
5067
5068 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5069 return regulatory_hint_user(data, user_reg_hint_type);
5070 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005071 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5072 owner_nlportid = info->snd_portid;
5073 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5074 } else {
5075 owner_nlportid = 0;
5076 is_indoor = true;
5077 }
5078
5079 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005080 default:
5081 return -EINVAL;
5082 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005083}
5084
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005085static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005086 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005087{
Johannes Berg4c476992010-10-04 21:36:35 +02005088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005089 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005090 struct wireless_dev *wdev = dev->ieee80211_ptr;
5091 struct mesh_config cur_params;
5092 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005093 void *hdr;
5094 struct nlattr *pinfoattr;
5095 struct sk_buff *msg;
5096
Johannes Berg29cbe682010-12-03 09:20:44 +01005097 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5098 return -EOPNOTSUPP;
5099
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005100 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005101 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005102
Johannes Berg29cbe682010-12-03 09:20:44 +01005103 wdev_lock(wdev);
5104 /* If not connected, get default parameters */
5105 if (!wdev->mesh_id_len)
5106 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5107 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005108 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005109 wdev_unlock(wdev);
5110
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005111 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005112 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005113
5114 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005116 if (!msg)
5117 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005118 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005119 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005120 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005121 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005122 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005123 if (!pinfoattr)
5124 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005125 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5126 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5127 cur_params.dot11MeshRetryTimeout) ||
5128 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5129 cur_params.dot11MeshConfirmTimeout) ||
5130 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5131 cur_params.dot11MeshHoldingTimeout) ||
5132 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5133 cur_params.dot11MeshMaxPeerLinks) ||
5134 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5135 cur_params.dot11MeshMaxRetries) ||
5136 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5137 cur_params.dot11MeshTTL) ||
5138 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5139 cur_params.element_ttl) ||
5140 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5141 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005142 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5143 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005144 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5145 cur_params.dot11MeshHWMPmaxPREQretries) ||
5146 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5147 cur_params.path_refresh_time) ||
5148 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5149 cur_params.min_discovery_timeout) ||
5150 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5151 cur_params.dot11MeshHWMPactivePathTimeout) ||
5152 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5153 cur_params.dot11MeshHWMPpreqMinInterval) ||
5154 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5155 cur_params.dot11MeshHWMPperrMinInterval) ||
5156 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5157 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5158 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5159 cur_params.dot11MeshHWMPRootMode) ||
5160 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5161 cur_params.dot11MeshHWMPRannInterval) ||
5162 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5163 cur_params.dot11MeshGateAnnouncementProtocol) ||
5164 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5165 cur_params.dot11MeshForwarding) ||
5166 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005167 cur_params.rssi_threshold) ||
5168 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005169 cur_params.ht_opmode) ||
5170 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5171 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5172 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005173 cur_params.dot11MeshHWMProotInterval) ||
5174 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005175 cur_params.dot11MeshHWMPconfirmationInterval) ||
5176 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5177 cur_params.power_mode) ||
5178 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005179 cur_params.dot11MeshAwakeWindowDuration) ||
5180 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5181 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005182 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005183 nla_nest_end(msg, pinfoattr);
5184 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005185 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005186
Johannes Berg3b858752009-03-12 09:55:09 +01005187 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005188 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005189 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005190 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005191 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005192}
5193
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005194static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005195 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5196 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5197 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5198 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5199 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5200 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005201 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005202 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005203 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005204 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5205 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5206 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5207 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5208 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005209 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005210 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005211 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005212 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005213 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005214 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005215 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5216 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005217 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5218 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005219 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005220 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5221 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005222 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005223};
5224
Javier Cardonac80d5452010-12-16 17:37:49 -08005225static const struct nla_policy
5226 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005227 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005228 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5229 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005230 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005231 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005232 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005233 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005234 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005235 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005236};
5237
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005238static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005239 struct mesh_config *cfg,
5240 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005241{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005242 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005243 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005244
Marco Porschea54fba2013-01-07 16:04:48 +01005245#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5246do { \
5247 if (tb[attr]) { \
5248 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5249 return -EINVAL; \
5250 cfg->param = fn(tb[attr]); \
5251 mask |= (1 << (attr - 1)); \
5252 } \
5253} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005254
5255
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005256 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005257 return -EINVAL;
5258 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005259 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005260 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005261 return -EINVAL;
5262
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005263 /* This makes sure that there aren't more than 32 mesh config
5264 * parameters (otherwise our bitfield scheme would not work.) */
5265 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5266
5267 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005268 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005269 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5270 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005271 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005272 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5273 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005274 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005275 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5276 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005277 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005278 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5279 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005280 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005281 mask, NL80211_MESHCONF_MAX_RETRIES,
5282 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005283 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005284 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005285 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005286 mask, NL80211_MESHCONF_ELEMENT_TTL,
5287 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005288 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005289 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5290 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005291 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5292 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005293 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5294 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005295 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005296 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5297 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005298 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005299 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5300 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005301 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005302 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5303 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005304 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5305 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005306 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5307 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005308 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005309 1, 65535, mask,
5310 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005311 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005312 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005313 1, 65535, mask,
5314 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005315 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005316 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005317 dot11MeshHWMPnetDiameterTraversalTime,
5318 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005319 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5320 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005321 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5322 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5323 nla_get_u8);
5324 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5325 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005326 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005327 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005328 dot11MeshGateAnnouncementProtocol, 0, 1,
5329 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005330 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005331 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005332 mask, NL80211_MESHCONF_FORWARDING,
5333 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005334 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005335 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005336 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005337 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005338 mask, NL80211_MESHCONF_HT_OPMODE,
5339 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005340 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005341 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005342 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5343 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005344 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005345 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5346 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005347 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005348 dot11MeshHWMPconfirmationInterval,
5349 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005350 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5351 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005352 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5353 NL80211_MESH_POWER_ACTIVE,
5354 NL80211_MESH_POWER_MAX,
5355 mask, NL80211_MESHCONF_POWER_MODE,
5356 nla_get_u32);
5357 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5358 0, 65535, mask,
5359 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005360 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005361 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5362 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005363 if (mask_out)
5364 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005365
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005366 return 0;
5367
5368#undef FILL_IN_MESH_PARAM_IF_SET
5369}
5370
Javier Cardonac80d5452010-12-16 17:37:49 -08005371static int nl80211_parse_mesh_setup(struct genl_info *info,
5372 struct mesh_setup *setup)
5373{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005375 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5376
5377 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5378 return -EINVAL;
5379 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5380 info->attrs[NL80211_ATTR_MESH_SETUP],
5381 nl80211_mesh_setup_params_policy))
5382 return -EINVAL;
5383
Javier Cardonad299a1f2012-03-31 11:31:33 -07005384 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5385 setup->sync_method =
5386 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5387 IEEE80211_SYNC_METHOD_VENDOR :
5388 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5389
Javier Cardonac80d5452010-12-16 17:37:49 -08005390 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5391 setup->path_sel_proto =
5392 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5393 IEEE80211_PATH_PROTOCOL_VENDOR :
5394 IEEE80211_PATH_PROTOCOL_HWMP;
5395
5396 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5397 setup->path_metric =
5398 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5399 IEEE80211_PATH_METRIC_VENDOR :
5400 IEEE80211_PATH_METRIC_AIRTIME;
5401
Javier Cardona581a8b02011-04-07 15:08:27 -07005402
5403 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005404 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005405 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005406 if (!is_valid_ie_attr(ieattr))
5407 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005408 setup->ie = nla_data(ieattr);
5409 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005410 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005411 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5412 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5413 return -EINVAL;
5414 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005415 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5416 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005417 if (setup->is_secure)
5418 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005419
Colleen Twitty6e16d902013-05-08 11:45:59 -07005420 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5421 if (!setup->user_mpm)
5422 return -EINVAL;
5423 setup->auth_id =
5424 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5425 }
5426
Javier Cardonac80d5452010-12-16 17:37:49 -08005427 return 0;
5428}
5429
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005430static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005431 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005432{
5433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5434 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005435 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005436 struct mesh_config cfg;
5437 u32 mask;
5438 int err;
5439
Johannes Berg29cbe682010-12-03 09:20:44 +01005440 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5441 return -EOPNOTSUPP;
5442
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005443 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005444 return -EOPNOTSUPP;
5445
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005446 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005447 if (err)
5448 return err;
5449
Johannes Berg29cbe682010-12-03 09:20:44 +01005450 wdev_lock(wdev);
5451 if (!wdev->mesh_id_len)
5452 err = -ENOLINK;
5453
5454 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005455 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005456
5457 wdev_unlock(wdev);
5458
5459 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005460}
5461
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005462static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5463 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005464{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005465 struct nlattr *nl_reg_rules;
5466 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005467
Johannes Berg458f4f92012-12-06 15:47:38 +01005468 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5469 (regdom->dfs_region &&
5470 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005471 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005472
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005473 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5474 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005475 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005476
Johannes Berg458f4f92012-12-06 15:47:38 +01005477 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005478 struct nlattr *nl_reg_rule;
5479 const struct ieee80211_reg_rule *reg_rule;
5480 const struct ieee80211_freq_range *freq_range;
5481 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005482 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005483
Johannes Berg458f4f92012-12-06 15:47:38 +01005484 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005485 freq_range = &reg_rule->freq_range;
5486 power_rule = &reg_rule->power_rule;
5487
5488 nl_reg_rule = nla_nest_start(msg, i);
5489 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005490 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005491
Janusz Dziedzic97524822014-01-30 09:52:20 +01005492 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5493 if (!max_bandwidth_khz)
5494 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5495 reg_rule);
5496
David S. Miller9360ffd2012-03-29 04:41:26 -04005497 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5498 reg_rule->flags) ||
5499 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5500 freq_range->start_freq_khz) ||
5501 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5502 freq_range->end_freq_khz) ||
5503 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005504 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005505 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5506 power_rule->max_antenna_gain) ||
5507 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005508 power_rule->max_eirp) ||
5509 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5510 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005511 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005512
5513 nla_nest_end(msg, nl_reg_rule);
5514 }
5515
5516 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005517 return 0;
5518
5519nla_put_failure:
5520 return -EMSGSIZE;
5521}
5522
5523static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5524{
5525 const struct ieee80211_regdomain *regdom = NULL;
5526 struct cfg80211_registered_device *rdev;
5527 struct wiphy *wiphy = NULL;
5528 struct sk_buff *msg;
5529 void *hdr;
5530
5531 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5532 if (!msg)
5533 return -ENOBUFS;
5534
5535 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5536 NL80211_CMD_GET_REG);
5537 if (!hdr)
5538 goto put_failure;
5539
5540 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005541 bool self_managed;
5542
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005543 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5544 if (IS_ERR(rdev)) {
5545 nlmsg_free(msg);
5546 return PTR_ERR(rdev);
5547 }
5548
5549 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005550 self_managed = wiphy->regulatory_flags &
5551 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005552 regdom = get_wiphy_regdom(wiphy);
5553
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005554 /* a self-managed-reg device must have a private regdom */
5555 if (WARN_ON(!regdom && self_managed)) {
5556 nlmsg_free(msg);
5557 return -EINVAL;
5558 }
5559
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005560 if (regdom &&
5561 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5562 goto nla_put_failure;
5563 }
5564
5565 if (!wiphy && reg_last_request_cell_base() &&
5566 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5567 NL80211_USER_REG_HINT_CELL_BASE))
5568 goto nla_put_failure;
5569
5570 rcu_read_lock();
5571
5572 if (!regdom)
5573 regdom = rcu_dereference(cfg80211_regdomain);
5574
5575 if (nl80211_put_regdom(regdom, msg))
5576 goto nla_put_failure_rcu;
5577
5578 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005579
5580 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005581 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005582
Johannes Berg458f4f92012-12-06 15:47:38 +01005583nla_put_failure_rcu:
5584 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005585nla_put_failure:
5586 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005587put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005588 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005589 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005590}
5591
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005592static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5593 u32 seq, int flags, struct wiphy *wiphy,
5594 const struct ieee80211_regdomain *regdom)
5595{
5596 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5597 NL80211_CMD_GET_REG);
5598
5599 if (!hdr)
5600 return -1;
5601
5602 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5603
5604 if (nl80211_put_regdom(regdom, msg))
5605 goto nla_put_failure;
5606
5607 if (!wiphy && reg_last_request_cell_base() &&
5608 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5609 NL80211_USER_REG_HINT_CELL_BASE))
5610 goto nla_put_failure;
5611
5612 if (wiphy &&
5613 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5614 goto nla_put_failure;
5615
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005616 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5617 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5618 goto nla_put_failure;
5619
Johannes Berg053c0952015-01-16 22:09:00 +01005620 genlmsg_end(msg, hdr);
5621 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005622
5623nla_put_failure:
5624 genlmsg_cancel(msg, hdr);
5625 return -EMSGSIZE;
5626}
5627
5628static int nl80211_get_reg_dump(struct sk_buff *skb,
5629 struct netlink_callback *cb)
5630{
5631 const struct ieee80211_regdomain *regdom = NULL;
5632 struct cfg80211_registered_device *rdev;
5633 int err, reg_idx, start = cb->args[2];
5634
5635 rtnl_lock();
5636
5637 if (cfg80211_regdomain && start == 0) {
5638 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5639 NLM_F_MULTI, NULL,
5640 rtnl_dereference(cfg80211_regdomain));
5641 if (err < 0)
5642 goto out_err;
5643 }
5644
5645 /* the global regdom is idx 0 */
5646 reg_idx = 1;
5647 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5648 regdom = get_wiphy_regdom(&rdev->wiphy);
5649 if (!regdom)
5650 continue;
5651
5652 if (++reg_idx <= start)
5653 continue;
5654
5655 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5656 NLM_F_MULTI, &rdev->wiphy, regdom);
5657 if (err < 0) {
5658 reg_idx--;
5659 break;
5660 }
5661 }
5662
5663 cb->args[2] = reg_idx;
5664 err = skb->len;
5665out_err:
5666 rtnl_unlock();
5667 return err;
5668}
5669
Johannes Bergb6863032015-10-15 09:25:18 +02005670#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5671static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5672 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5673 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5674 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5675 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5676 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5677 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5678 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5679};
5680
5681static int parse_reg_rule(struct nlattr *tb[],
5682 struct ieee80211_reg_rule *reg_rule)
5683{
5684 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5685 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5686
5687 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5688 return -EINVAL;
5689 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5690 return -EINVAL;
5691 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5692 return -EINVAL;
5693 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5694 return -EINVAL;
5695 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5696 return -EINVAL;
5697
5698 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5699
5700 freq_range->start_freq_khz =
5701 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5702 freq_range->end_freq_khz =
5703 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5704 freq_range->max_bandwidth_khz =
5705 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5706
5707 power_rule->max_eirp =
5708 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5709
5710 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5711 power_rule->max_antenna_gain =
5712 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5713
5714 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5715 reg_rule->dfs_cac_ms =
5716 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5717
5718 return 0;
5719}
5720
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005721static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5722{
5723 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5724 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005725 char *alpha2;
5726 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005727 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005728 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005729 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005730
5731 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5732 return -EINVAL;
5733
5734 if (!info->attrs[NL80211_ATTR_REG_RULES])
5735 return -EINVAL;
5736
5737 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5738
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005739 if (info->attrs[NL80211_ATTR_DFS_REGION])
5740 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5741
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005742 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005743 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005744 num_rules++;
5745 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005746 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005747 }
5748
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005749 if (!reg_is_valid_request(alpha2))
5750 return -EINVAL;
5751
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005752 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005753 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005754
5755 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005756 if (!rd)
5757 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005758
5759 rd->n_reg_rules = num_rules;
5760 rd->alpha2[0] = alpha2[0];
5761 rd->alpha2[1] = alpha2[1];
5762
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005763 /*
5764 * Disable DFS master mode if the DFS region was
5765 * not supported or known on this kernel.
5766 */
5767 if (reg_supported_dfs_region(dfs_region))
5768 rd->dfs_region = dfs_region;
5769
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005770 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005771 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005772 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5773 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5774 reg_rule_policy);
5775 if (r)
5776 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005777 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5778 if (r)
5779 goto bad_reg;
5780
5781 rule_idx++;
5782
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005783 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5784 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005785 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005786 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005787 }
5788
Ilan peerc37722b2015-03-30 15:15:49 +03005789 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005790 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005791 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005792
Johannes Bergd2372b32008-10-24 20:32:20 +02005793 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005794 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005795 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005796}
Johannes Bergb6863032015-10-15 09:25:18 +02005797#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005798
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005799static int validate_scan_freqs(struct nlattr *freqs)
5800{
5801 struct nlattr *attr1, *attr2;
5802 int n_channels = 0, tmp1, tmp2;
5803
5804 nla_for_each_nested(attr1, freqs, tmp1) {
5805 n_channels++;
5806 /*
5807 * Some hardware has a limited channel list for
5808 * scanning, and it is pretty much nonsensical
5809 * to scan for a channel twice, so disallow that
5810 * and don't require drivers to check that the
5811 * channel list they get isn't longer than what
5812 * they can scan, as long as they can scan all
5813 * the channels they registered at once.
5814 */
5815 nla_for_each_nested(attr2, freqs, tmp2)
5816 if (attr1 != attr2 &&
5817 nla_get_u32(attr1) == nla_get_u32(attr2))
5818 return 0;
5819 }
5820
5821 return n_channels;
5822}
5823
Arend van Spriel38de03d2016-03-02 20:37:18 +01005824static bool is_band_valid(struct wiphy *wiphy, enum ieee80211_band b)
5825{
5826 return b < IEEE80211_NUM_BANDS && wiphy->bands[b];
5827}
5828
5829static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5830 struct cfg80211_bss_selection *bss_select)
5831{
5832 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5833 struct nlattr *nest;
5834 int err;
5835 bool found = false;
5836 int i;
5837
5838 /* only process one nested attribute */
5839 nest = nla_data(nla);
5840 if (!nla_ok(nest, nla_len(nest)))
5841 return -EINVAL;
5842
5843 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5844 nla_len(nest), nl80211_bss_select_policy);
5845 if (err)
5846 return err;
5847
5848 /* only one attribute may be given */
5849 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
5850 if (attr[i]) {
5851 if (found)
5852 return -EINVAL;
5853 found = true;
5854 }
5855 }
5856
5857 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
5858
5859 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
5860 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
5861
5862 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
5863 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
5864 bss_select->param.band_pref =
5865 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
5866 if (!is_band_valid(wiphy, bss_select->param.band_pref))
5867 return -EINVAL;
5868 }
5869
5870 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
5871 struct nl80211_bss_select_rssi_adjust *adj_param;
5872
5873 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
5874 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
5875 bss_select->param.adjust.band = adj_param->band;
5876 bss_select->param.adjust.delta = adj_param->delta;
5877 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
5878 return -EINVAL;
5879 }
5880
5881 /* user-space did not provide behaviour attribute */
5882 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
5883 return -EINVAL;
5884
5885 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
5886 return -EINVAL;
5887
5888 return 0;
5889}
5890
Johannes Bergad2b26a2014-06-12 21:39:05 +02005891static int nl80211_parse_random_mac(struct nlattr **attrs,
5892 u8 *mac_addr, u8 *mac_addr_mask)
5893{
5894 int i;
5895
5896 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005897 eth_zero_addr(mac_addr);
5898 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005899 mac_addr[0] = 0x2;
5900 mac_addr_mask[0] = 0x3;
5901
5902 return 0;
5903 }
5904
5905 /* need both or none */
5906 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5907 return -EINVAL;
5908
5909 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5910 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5911
5912 /* don't allow or configure an mcast address */
5913 if (!is_multicast_ether_addr(mac_addr_mask) ||
5914 is_multicast_ether_addr(mac_addr))
5915 return -EINVAL;
5916
5917 /*
5918 * allow users to pass a MAC address that has bits set outside
5919 * of the mask, but don't bother drivers with having to deal
5920 * with such bits
5921 */
5922 for (i = 0; i < ETH_ALEN; i++)
5923 mac_addr[i] &= mac_addr_mask[i];
5924
5925 return 0;
5926}
5927
Johannes Berg2a519312009-02-10 21:25:55 +01005928static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5929{
Johannes Berg4c476992010-10-04 21:36:35 +02005930 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005931 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005932 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005933 struct nlattr *attr;
5934 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005935 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005936 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005937
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005938 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5939 return -EINVAL;
5940
Johannes Berg79c97e92009-07-07 03:56:12 +02005941 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005942
Johannes Berg4c476992010-10-04 21:36:35 +02005943 if (!rdev->ops->scan)
5944 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005945
Johannes Bergf9d15d12014-01-22 11:14:19 +02005946 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005947 err = -EBUSY;
5948 goto unlock;
5949 }
Johannes Berg2a519312009-02-10 21:25:55 +01005950
5951 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005952 n_channels = validate_scan_freqs(
5953 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005954 if (!n_channels) {
5955 err = -EINVAL;
5956 goto unlock;
5957 }
Johannes Berg2a519312009-02-10 21:25:55 +01005958 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005959 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005960 }
5961
5962 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5963 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5964 n_ssids++;
5965
Johannes Bergf9f47522013-03-19 15:04:07 +01005966 if (n_ssids > wiphy->max_scan_ssids) {
5967 err = -EINVAL;
5968 goto unlock;
5969 }
Johannes Berg2a519312009-02-10 21:25:55 +01005970
Jouni Malinen70692ad2009-02-16 19:39:13 +02005971 if (info->attrs[NL80211_ATTR_IE])
5972 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5973 else
5974 ie_len = 0;
5975
Johannes Bergf9f47522013-03-19 15:04:07 +01005976 if (ie_len > wiphy->max_scan_ie_len) {
5977 err = -EINVAL;
5978 goto unlock;
5979 }
Johannes Berg18a83652009-03-31 12:12:05 +02005980
Johannes Berg2a519312009-02-10 21:25:55 +01005981 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005982 + sizeof(*request->ssids) * n_ssids
5983 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005984 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005985 if (!request) {
5986 err = -ENOMEM;
5987 goto unlock;
5988 }
Johannes Berg2a519312009-02-10 21:25:55 +01005989
Johannes Berg2a519312009-02-10 21:25:55 +01005990 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005991 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005992 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005993 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005994 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005995 request->ie = (void *)(request->ssids + n_ssids);
5996 else
5997 request->ie = (void *)(request->channels + n_channels);
5998 }
Johannes Berg2a519312009-02-10 21:25:55 +01005999
Johannes Berg584991d2009-11-02 13:32:03 +01006000 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006001 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6002 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006003 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006004 struct ieee80211_channel *chan;
6005
6006 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6007
6008 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006009 err = -EINVAL;
6010 goto out_free;
6011 }
Johannes Berg584991d2009-11-02 13:32:03 +01006012
6013 /* ignore disabled channels */
6014 if (chan->flags & IEEE80211_CHAN_DISABLED)
6015 continue;
6016
6017 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006018 i++;
6019 }
6020 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02006021 enum ieee80211_band band;
6022
Johannes Berg2a519312009-02-10 21:25:55 +01006023 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01006024 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6025 int j;
6026 if (!wiphy->bands[band])
6027 continue;
6028 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006029 struct ieee80211_channel *chan;
6030
6031 chan = &wiphy->bands[band]->channels[j];
6032
6033 if (chan->flags & IEEE80211_CHAN_DISABLED)
6034 continue;
6035
6036 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006037 i++;
6038 }
6039 }
6040 }
6041
Johannes Berg584991d2009-11-02 13:32:03 +01006042 if (!i) {
6043 err = -EINVAL;
6044 goto out_free;
6045 }
6046
6047 request->n_channels = i;
6048
Johannes Berg2a519312009-02-10 21:25:55 +01006049 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006050 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006051 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006052 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006053 err = -EINVAL;
6054 goto out_free;
6055 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006056 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006057 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006058 i++;
6059 }
6060 }
6061
Jouni Malinen70692ad2009-02-16 19:39:13 +02006062 if (info->attrs[NL80211_ATTR_IE]) {
6063 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006064 memcpy((void *)request->ie,
6065 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006066 request->ie_len);
6067 }
6068
Johannes Berg34850ab2011-07-18 18:08:35 +02006069 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006070 if (wiphy->bands[i])
6071 request->rates[i] =
6072 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006073
6074 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6075 nla_for_each_nested(attr,
6076 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6077 tmp) {
6078 enum ieee80211_band band = nla_type(attr);
6079
Dan Carpenter84404622011-07-29 11:52:18 +03006080 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006081 err = -EINVAL;
6082 goto out_free;
6083 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006084
6085 if (!wiphy->bands[band])
6086 continue;
6087
Johannes Berg34850ab2011-07-18 18:08:35 +02006088 err = ieee80211_get_ratemask(wiphy->bands[band],
6089 nla_data(attr),
6090 nla_len(attr),
6091 &request->rates[band]);
6092 if (err)
6093 goto out_free;
6094 }
6095 }
6096
Sam Leffler46856bb2012-10-11 21:03:32 -07006097 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006098 request->flags = nla_get_u32(
6099 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006100 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6101 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006102 err = -EOPNOTSUPP;
6103 goto out_free;
6104 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006105
6106 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6107 if (!(wiphy->features &
6108 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6109 err = -EOPNOTSUPP;
6110 goto out_free;
6111 }
6112
6113 if (wdev->current_bss) {
6114 err = -EOPNOTSUPP;
6115 goto out_free;
6116 }
6117
6118 err = nl80211_parse_random_mac(info->attrs,
6119 request->mac_addr,
6120 request->mac_addr_mask);
6121 if (err)
6122 goto out_free;
6123 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006124 }
Sam Lefflered4737712012-10-11 21:03:31 -07006125
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306126 request->no_cck =
6127 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6128
Jouni Malinen818965d2016-02-26 22:12:47 +02006129 if (info->attrs[NL80211_ATTR_MAC])
6130 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6131 ETH_ALEN);
6132 else
6133 eth_broadcast_addr(request->bssid);
6134
Johannes Bergfd014282012-06-18 19:17:03 +02006135 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006136 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006137 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006138
Johannes Berg79c97e92009-07-07 03:56:12 +02006139 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006140 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006141
Johannes Berg463d0182009-07-14 00:33:35 +02006142 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006143 nl80211_send_scan_start(rdev, wdev);
6144 if (wdev->netdev)
6145 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006146 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006147 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006148 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006149 kfree(request);
6150 }
Johannes Berg3b858752009-03-12 09:55:09 +01006151
Johannes Bergf9f47522013-03-19 15:04:07 +01006152 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006153 return err;
6154}
6155
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306156static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6157{
6158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6159 struct wireless_dev *wdev = info->user_ptr[1];
6160
6161 if (!rdev->ops->abort_scan)
6162 return -EOPNOTSUPP;
6163
6164 if (rdev->scan_msg)
6165 return 0;
6166
6167 if (!rdev->scan_req)
6168 return -ENOENT;
6169
6170 rdev_abort_scan(rdev, wdev);
6171 return 0;
6172}
6173
Avraham Stern3b06d272015-10-12 09:51:34 +03006174static int
6175nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6176 struct cfg80211_sched_scan_request *request,
6177 struct nlattr **attrs)
6178{
6179 int tmp, err, i = 0;
6180 struct nlattr *attr;
6181
6182 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6183 u32 interval;
6184
6185 /*
6186 * If scan plans are not specified,
6187 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6188 * case one scan plan will be set with the specified scan
6189 * interval and infinite number of iterations.
6190 */
6191 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6192 return -EINVAL;
6193
6194 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6195 if (!interval)
6196 return -EINVAL;
6197
6198 request->scan_plans[0].interval =
6199 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6200 if (!request->scan_plans[0].interval)
6201 return -EINVAL;
6202
6203 if (request->scan_plans[0].interval >
6204 wiphy->max_sched_scan_plan_interval)
6205 request->scan_plans[0].interval =
6206 wiphy->max_sched_scan_plan_interval;
6207
6208 return 0;
6209 }
6210
6211 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6212 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6213
6214 if (WARN_ON(i >= n_plans))
6215 return -EINVAL;
6216
6217 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6218 nla_data(attr), nla_len(attr),
6219 nl80211_plan_policy);
6220 if (err)
6221 return err;
6222
6223 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6224 return -EINVAL;
6225
6226 request->scan_plans[i].interval =
6227 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6228 if (!request->scan_plans[i].interval ||
6229 request->scan_plans[i].interval >
6230 wiphy->max_sched_scan_plan_interval)
6231 return -EINVAL;
6232
6233 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6234 request->scan_plans[i].iterations =
6235 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6236 if (!request->scan_plans[i].iterations ||
6237 (request->scan_plans[i].iterations >
6238 wiphy->max_sched_scan_plan_iterations))
6239 return -EINVAL;
6240 } else if (i < n_plans - 1) {
6241 /*
6242 * All scan plans but the last one must specify
6243 * a finite number of iterations
6244 */
6245 return -EINVAL;
6246 }
6247
6248 i++;
6249 }
6250
6251 /*
6252 * The last scan plan must not specify the number of
6253 * iterations, it is supposed to run infinitely
6254 */
6255 if (request->scan_plans[n_plans - 1].iterations)
6256 return -EINVAL;
6257
6258 return 0;
6259}
6260
Luciano Coelho256da022014-11-10 16:13:46 +02006261static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006262nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006263 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006264{
6265 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006266 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006267 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006268 enum ieee80211_band band;
6269 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006270 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006271 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006272
Luciano Coelho256da022014-11-10 16:13:46 +02006273 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6274 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006275
Luciano Coelho256da022014-11-10 16:13:46 +02006276 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006277 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006278 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006279 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006280 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006281 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006282 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006283 }
6284
Luciano Coelho256da022014-11-10 16:13:46 +02006285 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6286 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006287 tmp)
6288 n_ssids++;
6289
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006290 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006291 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006292
Johannes Bergea73cbc2014-01-24 10:53:53 +01006293 /*
6294 * First, count the number of 'real' matchsets. Due to an issue with
6295 * the old implementation, matchsets containing only the RSSI attribute
6296 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6297 * RSSI for all matchsets, rather than their own matchset for reporting
6298 * all APs with a strong RSSI. This is needed to be compatible with
6299 * older userspace that treated a matchset with only the RSSI as the
6300 * global RSSI for all other matchsets - if there are other matchsets.
6301 */
Luciano Coelho256da022014-11-10 16:13:46 +02006302 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006303 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006304 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006305 tmp) {
6306 struct nlattr *rssi;
6307
6308 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6309 nla_data(attr), nla_len(attr),
6310 nl80211_match_policy);
6311 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006312 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006313 /* add other standalone attributes here */
6314 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6315 n_match_sets++;
6316 continue;
6317 }
6318 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6319 if (rssi)
6320 default_match_rssi = nla_get_s32(rssi);
6321 }
6322 }
6323
6324 /* However, if there's no other matchset, add the RSSI one */
6325 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6326 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006327
6328 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006329 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006330
Luciano Coelho256da022014-11-10 16:13:46 +02006331 if (attrs[NL80211_ATTR_IE])
6332 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006333 else
6334 ie_len = 0;
6335
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006336 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006337 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006338
Avraham Stern3b06d272015-10-12 09:51:34 +03006339 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6340 /*
6341 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6342 * each scan plan already specifies its own interval
6343 */
6344 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6345 return ERR_PTR(-EINVAL);
6346
6347 nla_for_each_nested(attr,
6348 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6349 n_plans++;
6350 } else {
6351 /*
6352 * The scan interval attribute is kept for backward
6353 * compatibility. If no scan plans are specified and sched scan
6354 * interval is specified, one scan plan will be set with this
6355 * scan interval and infinite number of iterations.
6356 */
6357 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6358 return ERR_PTR(-EINVAL);
6359
6360 n_plans = 1;
6361 }
6362
6363 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6364 return ERR_PTR(-EINVAL);
6365
Luciano Coelho807f8a82011-05-11 17:09:35 +03006366 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006367 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006368 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006369 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006370 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006371 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006372 if (!request)
6373 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006374
6375 if (n_ssids)
6376 request->ssids = (void *)&request->channels[n_channels];
6377 request->n_ssids = n_ssids;
6378 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006379 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006380 request->ie = (void *)(request->ssids + n_ssids);
6381 else
6382 request->ie = (void *)(request->channels + n_channels);
6383 }
6384
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006385 if (n_match_sets) {
6386 if (request->ie)
6387 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006388 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006389 request->match_sets =
6390 (void *)(request->ssids + n_ssids);
6391 else
6392 request->match_sets =
6393 (void *)(request->channels + n_channels);
6394 }
6395 request->n_match_sets = n_match_sets;
6396
Avraham Stern3b06d272015-10-12 09:51:34 +03006397 if (n_match_sets)
6398 request->scan_plans = (void *)(request->match_sets +
6399 n_match_sets);
6400 else if (request->ie)
6401 request->scan_plans = (void *)(request->ie + ie_len);
6402 else if (n_ssids)
6403 request->scan_plans = (void *)(request->ssids + n_ssids);
6404 else
6405 request->scan_plans = (void *)(request->channels + n_channels);
6406
6407 request->n_scan_plans = n_plans;
6408
Luciano Coelho807f8a82011-05-11 17:09:35 +03006409 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006410 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006411 /* user specified, bail out if channel not found */
6412 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006413 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006414 tmp) {
6415 struct ieee80211_channel *chan;
6416
6417 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6418
6419 if (!chan) {
6420 err = -EINVAL;
6421 goto out_free;
6422 }
6423
6424 /* ignore disabled channels */
6425 if (chan->flags & IEEE80211_CHAN_DISABLED)
6426 continue;
6427
6428 request->channels[i] = chan;
6429 i++;
6430 }
6431 } else {
6432 /* all channels */
6433 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6434 int j;
6435 if (!wiphy->bands[band])
6436 continue;
6437 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6438 struct ieee80211_channel *chan;
6439
6440 chan = &wiphy->bands[band]->channels[j];
6441
6442 if (chan->flags & IEEE80211_CHAN_DISABLED)
6443 continue;
6444
6445 request->channels[i] = chan;
6446 i++;
6447 }
6448 }
6449 }
6450
6451 if (!i) {
6452 err = -EINVAL;
6453 goto out_free;
6454 }
6455
6456 request->n_channels = i;
6457
6458 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006459 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006460 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006461 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006462 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006463 err = -EINVAL;
6464 goto out_free;
6465 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006466 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006467 memcpy(request->ssids[i].ssid, nla_data(attr),
6468 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006469 i++;
6470 }
6471 }
6472
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006473 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006474 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006475 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006476 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006477 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006478 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006479
Johannes Bergae811e22014-01-24 10:17:47 +01006480 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6481 nla_data(attr), nla_len(attr),
6482 nl80211_match_policy);
6483 if (err)
6484 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006485 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006486 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006487 if (WARN_ON(i >= n_match_sets)) {
6488 /* this indicates a programming error,
6489 * the loop above should have verified
6490 * things properly
6491 */
6492 err = -EINVAL;
6493 goto out_free;
6494 }
6495
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006496 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6497 err = -EINVAL;
6498 goto out_free;
6499 }
6500 memcpy(request->match_sets[i].ssid.ssid,
6501 nla_data(ssid), nla_len(ssid));
6502 request->match_sets[i].ssid.ssid_len =
6503 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006504 /* special attribute - old implemenation w/a */
6505 request->match_sets[i].rssi_thold =
6506 default_match_rssi;
6507 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6508 if (rssi)
6509 request->match_sets[i].rssi_thold =
6510 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006511 }
6512 i++;
6513 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006514
6515 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006516 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006517 request->match_sets[0].rssi_thold = default_match_rssi;
6518
6519 request->min_rssi_thold = INT_MAX;
6520 for (i = 0; i < n_match_sets; i++)
6521 request->min_rssi_thold =
6522 min(request->match_sets[i].rssi_thold,
6523 request->min_rssi_thold);
6524 } else {
6525 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006526 }
6527
Johannes Berg9900e482014-02-04 21:01:25 +01006528 if (ie_len) {
6529 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006530 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006531 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006532 request->ie_len);
6533 }
6534
Luciano Coelho256da022014-11-10 16:13:46 +02006535 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006536 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006537 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006538 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6539 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006540 err = -EOPNOTSUPP;
6541 goto out_free;
6542 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006543
6544 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6545 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6546
6547 if (!wdev) /* must be net-detect */
6548 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6549
6550 if (!(wiphy->features & flg)) {
6551 err = -EOPNOTSUPP;
6552 goto out_free;
6553 }
6554
6555 if (wdev && wdev->current_bss) {
6556 err = -EOPNOTSUPP;
6557 goto out_free;
6558 }
6559
6560 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6561 request->mac_addr_mask);
6562 if (err)
6563 goto out_free;
6564 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006565 }
Sam Lefflered4737712012-10-11 21:03:31 -07006566
Luciano Coelho9c748932015-01-16 16:04:09 +02006567 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6568 request->delay =
6569 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6570
Avraham Stern3b06d272015-10-12 09:51:34 +03006571 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6572 if (err)
6573 goto out_free;
6574
Sam Leffler15d60302012-10-11 21:03:34 -07006575 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006576
Luciano Coelho256da022014-11-10 16:13:46 +02006577 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006578
6579out_free:
6580 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006581 return ERR_PTR(err);
6582}
6583
6584static int nl80211_start_sched_scan(struct sk_buff *skb,
6585 struct genl_info *info)
6586{
6587 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6588 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006589 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006590 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006591 int err;
6592
6593 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6594 !rdev->ops->sched_scan_start)
6595 return -EOPNOTSUPP;
6596
6597 if (rdev->sched_scan_req)
6598 return -EINPROGRESS;
6599
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006600 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6601 info->attrs);
6602
6603 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006604 if (err)
6605 goto out_err;
6606
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006607 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006608 if (err)
6609 goto out_free;
6610
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006611 sched_scan_req->dev = dev;
6612 sched_scan_req->wiphy = &rdev->wiphy;
6613
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006614 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6615 sched_scan_req->owner_nlportid = info->snd_portid;
6616
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006617 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006618
6619 nl80211_send_sched_scan(rdev, dev,
6620 NL80211_CMD_START_SCHED_SCAN);
6621 return 0;
6622
6623out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006624 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006625out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006626 return err;
6627}
6628
6629static int nl80211_stop_sched_scan(struct sk_buff *skb,
6630 struct genl_info *info)
6631{
6632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6633
6634 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6635 !rdev->ops->sched_scan_stop)
6636 return -EOPNOTSUPP;
6637
Johannes Berg5fe231e2013-05-08 21:45:15 +02006638 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006639}
6640
Simon Wunderlich04f39042013-02-08 18:16:19 +01006641static int nl80211_start_radar_detection(struct sk_buff *skb,
6642 struct genl_info *info)
6643{
6644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6645 struct net_device *dev = info->user_ptr[1];
6646 struct wireless_dev *wdev = dev->ieee80211_ptr;
6647 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006648 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006649 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006650 int err;
6651
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006652 dfs_region = reg_get_dfs_region(wdev->wiphy);
6653 if (dfs_region == NL80211_DFS_UNSET)
6654 return -EINVAL;
6655
Simon Wunderlich04f39042013-02-08 18:16:19 +01006656 err = nl80211_parse_chandef(rdev, info, &chandef);
6657 if (err)
6658 return err;
6659
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006660 if (netif_carrier_ok(dev))
6661 return -EBUSY;
6662
Simon Wunderlich04f39042013-02-08 18:16:19 +01006663 if (wdev->cac_started)
6664 return -EBUSY;
6665
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006666 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006667 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006668 if (err < 0)
6669 return err;
6670
6671 if (err == 0)
6672 return -EINVAL;
6673
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006674 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006675 return -EINVAL;
6676
6677 if (!rdev->ops->start_radar_detection)
6678 return -EOPNOTSUPP;
6679
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006680 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6681 if (WARN_ON(!cac_time_ms))
6682 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6683
Ilan Peera1056b12015-10-22 22:27:46 +03006684 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006685 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006686 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006687 wdev->cac_started = true;
6688 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006689 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006690 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006691 return err;
6692}
6693
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006694static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6695{
6696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6697 struct net_device *dev = info->user_ptr[1];
6698 struct wireless_dev *wdev = dev->ieee80211_ptr;
6699 struct cfg80211_csa_settings params;
6700 /* csa_attrs is defined static to avoid waste of stack size - this
6701 * function is called under RTNL lock, so this should not be a problem.
6702 */
6703 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006704 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006705 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006706 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006707 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006708
6709 if (!rdev->ops->channel_switch ||
6710 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6711 return -EOPNOTSUPP;
6712
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006713 switch (dev->ieee80211_ptr->iftype) {
6714 case NL80211_IFTYPE_AP:
6715 case NL80211_IFTYPE_P2P_GO:
6716 need_new_beacon = true;
6717
6718 /* useless if AP is not running */
6719 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006720 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006721 break;
6722 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006723 if (!wdev->ssid_len)
6724 return -ENOTCONN;
6725 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006726 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006727 if (!wdev->mesh_id_len)
6728 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006729 break;
6730 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006731 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006732 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006733
6734 memset(&params, 0, sizeof(params));
6735
6736 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6737 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6738 return -EINVAL;
6739
6740 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006741 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006742 return -EINVAL;
6743
Luciano Coelho252e07c2014-10-08 09:48:34 +03006744 /* Even though the attribute is u32, the specification says
6745 * u8, so let's make sure we don't overflow.
6746 */
6747 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6748 if (cs_count > 255)
6749 return -EINVAL;
6750
6751 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006752
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006753 if (!need_new_beacon)
6754 goto skip_beacons;
6755
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006756 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6757 if (err)
6758 return err;
6759
6760 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6761 info->attrs[NL80211_ATTR_CSA_IES],
6762 nl80211_policy);
6763 if (err)
6764 return err;
6765
6766 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6767 if (err)
6768 return err;
6769
6770 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6771 return -EINVAL;
6772
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006773 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6774 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006775 return -EINVAL;
6776
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006777 params.n_counter_offsets_beacon = len / sizeof(u16);
6778 if (rdev->wiphy.max_num_csa_counters &&
6779 (params.n_counter_offsets_beacon >
6780 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006781 return -EINVAL;
6782
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006783 params.counter_offsets_beacon =
6784 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6785
6786 /* sanity checks - counters should fit and be the same */
6787 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6788 u16 offset = params.counter_offsets_beacon[i];
6789
6790 if (offset >= params.beacon_csa.tail_len)
6791 return -EINVAL;
6792
6793 if (params.beacon_csa.tail[offset] != params.count)
6794 return -EINVAL;
6795 }
6796
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006797 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006798 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6799 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006800 return -EINVAL;
6801
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006802 params.n_counter_offsets_presp = len / sizeof(u16);
6803 if (rdev->wiphy.max_num_csa_counters &&
6804 (params.n_counter_offsets_beacon >
6805 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006806 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006807
6808 params.counter_offsets_presp =
6809 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6810
6811 /* sanity checks - counters should fit and be the same */
6812 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6813 u16 offset = params.counter_offsets_presp[i];
6814
6815 if (offset >= params.beacon_csa.probe_resp_len)
6816 return -EINVAL;
6817
6818 if (params.beacon_csa.probe_resp[offset] !=
6819 params.count)
6820 return -EINVAL;
6821 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006822 }
6823
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006824skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006825 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6826 if (err)
6827 return err;
6828
Arik Nemtsov923b3522015-07-08 15:41:44 +03006829 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6830 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006831 return -EINVAL;
6832
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006833 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6834 &params.chandef,
6835 wdev->iftype);
6836 if (err < 0)
6837 return err;
6838
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006839 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006840 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006841
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006842 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6843 params.block_tx = true;
6844
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006845 wdev_lock(wdev);
6846 err = rdev_channel_switch(rdev, dev, &params);
6847 wdev_unlock(wdev);
6848
6849 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006850}
6851
Johannes Berg9720bb32011-06-21 09:45:33 +02006852static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6853 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006854 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006855 struct wireless_dev *wdev,
6856 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006857{
Johannes Berg48ab9052009-07-10 18:42:31 +02006858 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006859 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006860 void *hdr;
6861 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006862
6863 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006864
Eric W. Biederman15e47302012-09-07 20:12:54 +00006865 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006866 NL80211_CMD_NEW_SCAN_RESULTS);
6867 if (!hdr)
6868 return -1;
6869
Johannes Berg9720bb32011-06-21 09:45:33 +02006870 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6871
Johannes Berg97990a02013-04-19 01:02:55 +02006872 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6873 goto nla_put_failure;
6874 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006875 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6876 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006877 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6878 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006879
6880 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6881 if (!bss)
6882 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006883 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006884 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006885 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006886
6887 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006888 /* indicate whether we have probe response data or not */
6889 if (rcu_access_pointer(res->proberesp_ies) &&
6890 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6891 goto fail_unlock_rcu;
6892
6893 /* this pointer prefers to be pointed to probe response data
6894 * but is always valid
6895 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006896 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006897 if (ies) {
6898 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6899 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006900 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6901 ies->len, ies->data))
6902 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006903 }
Johannes Berg0e227082014-08-12 20:34:30 +02006904
6905 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006906 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006907 if (ies && ies->from_beacon) {
6908 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006909 goto fail_unlock_rcu;
6910 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6911 ies->len, ies->data))
6912 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006913 }
6914 rcu_read_unlock();
6915
David S. Miller9360ffd2012-03-29 04:41:26 -04006916 if (res->beacon_interval &&
6917 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6918 goto nla_put_failure;
6919 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6920 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006921 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006922 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6923 jiffies_to_msecs(jiffies - intbss->ts)))
6924 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006925
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006926 if (intbss->ts_boottime &&
6927 nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6928 intbss->ts_boottime))
6929 goto nla_put_failure;
6930
Johannes Berg77965c92009-02-18 18:45:06 +01006931 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006932 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006933 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6934 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006935 break;
6936 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006937 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6938 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006939 break;
6940 default:
6941 break;
6942 }
6943
Johannes Berg48ab9052009-07-10 18:42:31 +02006944 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006945 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006946 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006947 if (intbss == wdev->current_bss &&
6948 nla_put_u32(msg, NL80211_BSS_STATUS,
6949 NL80211_BSS_STATUS_ASSOCIATED))
6950 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006951 break;
6952 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006953 if (intbss == wdev->current_bss &&
6954 nla_put_u32(msg, NL80211_BSS_STATUS,
6955 NL80211_BSS_STATUS_IBSS_JOINED))
6956 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006957 break;
6958 default:
6959 break;
6960 }
6961
Johannes Berg2a519312009-02-10 21:25:55 +01006962 nla_nest_end(msg, bss);
6963
Johannes Berg053c0952015-01-16 22:09:00 +01006964 genlmsg_end(msg, hdr);
6965 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006966
Johannes Berg8cef2c92013-02-05 16:54:31 +01006967 fail_unlock_rcu:
6968 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006969 nla_put_failure:
6970 genlmsg_cancel(msg, hdr);
6971 return -EMSGSIZE;
6972}
6973
Johannes Berg97990a02013-04-19 01:02:55 +02006974static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006975{
Johannes Berg48ab9052009-07-10 18:42:31 +02006976 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006977 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006978 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006979 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006980 int err;
6981
Johannes Berg97990a02013-04-19 01:02:55 +02006982 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006983 if (err)
6984 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006985
Johannes Berg48ab9052009-07-10 18:42:31 +02006986 wdev_lock(wdev);
6987 spin_lock_bh(&rdev->bss_lock);
6988 cfg80211_bss_expire(rdev);
6989
Johannes Berg9720bb32011-06-21 09:45:33 +02006990 cb->seq = rdev->bss_generation;
6991
Johannes Berg48ab9052009-07-10 18:42:31 +02006992 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006993 if (++idx <= start)
6994 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006995 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006996 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006997 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006998 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006999 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007000 }
7001 }
7002
Johannes Berg48ab9052009-07-10 18:42:31 +02007003 spin_unlock_bh(&rdev->bss_lock);
7004 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007005
Johannes Berg97990a02013-04-19 01:02:55 +02007006 cb->args[2] = idx;
7007 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007008
Johannes Berg67748892010-10-04 21:14:06 +02007009 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007010}
7011
Eric W. Biederman15e47302012-09-07 20:12:54 +00007012static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007013 int flags, struct net_device *dev,
7014 bool allow_radio_stats,
7015 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007016{
7017 void *hdr;
7018 struct nlattr *infoattr;
7019
Johannes Berg11f78ac2014-11-14 16:43:50 +01007020 /* skip radio stats if userspace didn't request them */
7021 if (!survey->channel && !allow_radio_stats)
7022 return 0;
7023
Eric W. Biederman15e47302012-09-07 20:12:54 +00007024 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007025 NL80211_CMD_NEW_SURVEY_RESULTS);
7026 if (!hdr)
7027 return -ENOMEM;
7028
David S. Miller9360ffd2012-03-29 04:41:26 -04007029 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7030 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007031
7032 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7033 if (!infoattr)
7034 goto nla_put_failure;
7035
Johannes Berg11f78ac2014-11-14 16:43:50 +01007036 if (survey->channel &&
7037 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007038 survey->channel->center_freq))
7039 goto nla_put_failure;
7040
7041 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7042 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7043 goto nla_put_failure;
7044 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7045 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7046 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007047 if ((survey->filled & SURVEY_INFO_TIME) &&
7048 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
7049 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04007050 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007051 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
7052 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7053 survey->time_busy))
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_EXT_BUSY) &&
7056 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7057 survey->time_ext_busy))
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_RX) &&
7060 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
7061 survey->time_rx))
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_TX) &&
7064 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
7065 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04007066 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007067 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
7068 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7069 survey->time_scan))
7070 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007071
7072 nla_nest_end(msg, infoattr);
7073
Johannes Berg053c0952015-01-16 22:09:00 +01007074 genlmsg_end(msg, hdr);
7075 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007076
7077 nla_put_failure:
7078 genlmsg_cancel(msg, hdr);
7079 return -EMSGSIZE;
7080}
7081
Johannes Berg11f78ac2014-11-14 16:43:50 +01007082static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007083{
7084 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007085 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007086 struct wireless_dev *wdev;
7087 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007088 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007089 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007090
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007091 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007092 if (res)
7093 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007094
Johannes Berg11f78ac2014-11-14 16:43:50 +01007095 /* prepare_wdev_dump parsed the attributes */
7096 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7097
Johannes Berg97990a02013-04-19 01:02:55 +02007098 if (!wdev->netdev) {
7099 res = -EINVAL;
7100 goto out_err;
7101 }
7102
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007103 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007104 res = -EOPNOTSUPP;
7105 goto out_err;
7106 }
7107
7108 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007109 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007110 if (res == -ENOENT)
7111 break;
7112 if (res)
7113 goto out_err;
7114
Johannes Berg11f78ac2014-11-14 16:43:50 +01007115 /* don't send disabled channels, but do send non-channel data */
7116 if (survey.channel &&
7117 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007118 survey_idx++;
7119 continue;
7120 }
7121
Holger Schurig61fa7132009-11-11 12:25:40 +01007122 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007123 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007124 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007125 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007126 goto out;
7127 survey_idx++;
7128 }
7129
7130 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007131 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007132 res = skb->len;
7133 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007134 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007135 return res;
7136}
7137
Samuel Ortizb23aa672009-07-01 21:26:54 +02007138static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7139{
7140 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7141 NL80211_WPA_VERSION_2));
7142}
7143
Jouni Malinen636a5d32009-03-19 13:39:22 +02007144static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7145{
Johannes Berg4c476992010-10-04 21:36:35 +02007146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7147 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007148 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007149 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7150 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007151 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007152 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007153 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007154
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007155 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7156 return -EINVAL;
7157
7158 if (!info->attrs[NL80211_ATTR_MAC])
7159 return -EINVAL;
7160
Jouni Malinen17780922009-03-27 20:52:47 +02007161 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7162 return -EINVAL;
7163
Johannes Berg19957bb2009-07-02 17:20:43 +02007164 if (!info->attrs[NL80211_ATTR_SSID])
7165 return -EINVAL;
7166
7167 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7168 return -EINVAL;
7169
Johannes Bergfffd0932009-07-08 14:22:54 +02007170 err = nl80211_parse_key(info, &key);
7171 if (err)
7172 return err;
7173
7174 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007175 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7176 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007177 if (!key.p.key || !key.p.key_len)
7178 return -EINVAL;
7179 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7180 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7181 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7182 key.p.key_len != WLAN_KEY_LEN_WEP104))
7183 return -EINVAL;
7184 if (key.idx > 4)
7185 return -EINVAL;
7186 } else {
7187 key.p.key_len = 0;
7188 key.p.key = NULL;
7189 }
7190
Johannes Bergafea0b72010-08-10 09:46:42 +02007191 if (key.idx >= 0) {
7192 int i;
7193 bool ok = false;
7194 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7195 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7196 ok = true;
7197 break;
7198 }
7199 }
Johannes Berg4c476992010-10-04 21:36:35 +02007200 if (!ok)
7201 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007202 }
7203
Johannes Berg4c476992010-10-04 21:36:35 +02007204 if (!rdev->ops->auth)
7205 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007206
Johannes Berg074ac8d2010-09-16 14:58:22 +02007207 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007208 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7209 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007210
Johannes Berg19957bb2009-07-02 17:20:43 +02007211 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007212 chan = nl80211_get_valid_chan(&rdev->wiphy,
7213 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7214 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007215 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007216
Johannes Berg19957bb2009-07-02 17:20:43 +02007217 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7218 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7219
7220 if (info->attrs[NL80211_ATTR_IE]) {
7221 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7222 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7223 }
7224
7225 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007226 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007227 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007228
Jouni Malinene39e5b52012-09-30 19:29:39 +03007229 if (auth_type == NL80211_AUTHTYPE_SAE &&
7230 !info->attrs[NL80211_ATTR_SAE_DATA])
7231 return -EINVAL;
7232
7233 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7234 if (auth_type != NL80211_AUTHTYPE_SAE)
7235 return -EINVAL;
7236 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7237 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7238 /* need to include at least Auth Transaction and Status Code */
7239 if (sae_data_len < 4)
7240 return -EINVAL;
7241 }
7242
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007243 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7244
Johannes Berg95de8172012-01-20 13:55:25 +01007245 /*
7246 * Since we no longer track auth state, ignore
7247 * requests to only change local state.
7248 */
7249 if (local_state_change)
7250 return 0;
7251
Johannes Berg91bf9b22013-05-15 17:44:01 +02007252 wdev_lock(dev->ieee80211_ptr);
7253 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7254 ssid, ssid_len, ie, ie_len,
7255 key.p.key, key.p.key_len, key.idx,
7256 sae_data, sae_data_len);
7257 wdev_unlock(dev->ieee80211_ptr);
7258 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007259}
7260
Johannes Bergc0692b82010-08-27 14:26:53 +03007261static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7262 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007263 struct cfg80211_crypto_settings *settings,
7264 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007265{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007266 memset(settings, 0, sizeof(*settings));
7267
Samuel Ortizb23aa672009-07-01 21:26:54 +02007268 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7269
Johannes Bergc0692b82010-08-27 14:26:53 +03007270 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7271 u16 proto;
7272 proto = nla_get_u16(
7273 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7274 settings->control_port_ethertype = cpu_to_be16(proto);
7275 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7276 proto != ETH_P_PAE)
7277 return -EINVAL;
7278 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7279 settings->control_port_no_encrypt = true;
7280 } else
7281 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7282
Samuel Ortizb23aa672009-07-01 21:26:54 +02007283 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7284 void *data;
7285 int len, i;
7286
7287 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7288 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7289 settings->n_ciphers_pairwise = len / sizeof(u32);
7290
7291 if (len % sizeof(u32))
7292 return -EINVAL;
7293
Johannes Berg3dc27d22009-07-02 21:36:37 +02007294 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007295 return -EINVAL;
7296
7297 memcpy(settings->ciphers_pairwise, data, len);
7298
7299 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007300 if (!cfg80211_supported_cipher_suite(
7301 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007302 settings->ciphers_pairwise[i]))
7303 return -EINVAL;
7304 }
7305
7306 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7307 settings->cipher_group =
7308 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007309 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7310 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007311 return -EINVAL;
7312 }
7313
7314 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7315 settings->wpa_versions =
7316 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7317 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7318 return -EINVAL;
7319 }
7320
7321 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7322 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007323 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007324
7325 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7326 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7327 settings->n_akm_suites = len / sizeof(u32);
7328
7329 if (len % sizeof(u32))
7330 return -EINVAL;
7331
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007332 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7333 return -EINVAL;
7334
Samuel Ortizb23aa672009-07-01 21:26:54 +02007335 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007336 }
7337
7338 return 0;
7339}
7340
Jouni Malinen636a5d32009-03-19 13:39:22 +02007341static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7342{
Johannes Berg4c476992010-10-04 21:36:35 +02007343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7344 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007345 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007346 struct cfg80211_assoc_request req = {};
7347 const u8 *bssid, *ssid;
7348 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007349
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007350 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7351 return -EINVAL;
7352
7353 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007354 !info->attrs[NL80211_ATTR_SSID] ||
7355 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007356 return -EINVAL;
7357
Johannes Berg4c476992010-10-04 21:36:35 +02007358 if (!rdev->ops->assoc)
7359 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007360
Johannes Berg074ac8d2010-09-16 14:58:22 +02007361 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007362 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7363 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007364
Johannes Berg19957bb2009-07-02 17:20:43 +02007365 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007366
Jouni Malinen664834d2014-01-15 00:01:44 +02007367 chan = nl80211_get_valid_chan(&rdev->wiphy,
7368 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7369 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007370 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007371
Johannes Berg19957bb2009-07-02 17:20:43 +02007372 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7373 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007374
7375 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007376 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7377 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007378 }
7379
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007380 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007381 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007382 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007383 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007384 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007385 else if (mfp != NL80211_MFP_NO)
7386 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007387 }
7388
Johannes Berg3e5d7642009-07-07 14:37:26 +02007389 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007390 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007391
Ben Greear7e7c8922011-11-18 11:31:59 -08007392 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007393 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007394
7395 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007396 memcpy(&req.ht_capa_mask,
7397 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7398 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007399
7400 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007401 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007402 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007403 memcpy(&req.ht_capa,
7404 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7405 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007406 }
7407
Johannes Bergee2aca32013-02-21 17:36:01 +01007408 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007409 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007410
7411 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007412 memcpy(&req.vht_capa_mask,
7413 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7414 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007415
7416 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007417 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007418 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007419 memcpy(&req.vht_capa,
7420 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7421 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007422 }
7423
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007424 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007425 if (!((rdev->wiphy.features &
7426 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7427 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7428 !wiphy_ext_feature_isset(&rdev->wiphy,
7429 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007430 return -EINVAL;
7431 req.flags |= ASSOC_REQ_USE_RRM;
7432 }
7433
Johannes Bergf62fab72013-02-21 20:09:09 +01007434 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007435 if (!err) {
7436 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007437 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7438 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007439 wdev_unlock(dev->ieee80211_ptr);
7440 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007441
Jouni Malinen636a5d32009-03-19 13:39:22 +02007442 return err;
7443}
7444
7445static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7446{
Johannes Berg4c476992010-10-04 21:36:35 +02007447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7448 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007449 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007450 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007451 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007452 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007453
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007454 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7455 return -EINVAL;
7456
7457 if (!info->attrs[NL80211_ATTR_MAC])
7458 return -EINVAL;
7459
7460 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7461 return -EINVAL;
7462
Johannes Berg4c476992010-10-04 21:36:35 +02007463 if (!rdev->ops->deauth)
7464 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007465
Johannes Berg074ac8d2010-09-16 14:58:22 +02007466 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007467 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7468 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007469
Johannes Berg19957bb2009-07-02 17:20:43 +02007470 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007471
Johannes Berg19957bb2009-07-02 17:20:43 +02007472 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7473 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007474 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007475 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007476 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007477
7478 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007479 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7480 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007481 }
7482
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007483 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7484
Johannes Berg91bf9b22013-05-15 17:44:01 +02007485 wdev_lock(dev->ieee80211_ptr);
7486 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7487 local_state_change);
7488 wdev_unlock(dev->ieee80211_ptr);
7489 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007490}
7491
7492static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7493{
Johannes Berg4c476992010-10-04 21:36:35 +02007494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7495 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007496 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007497 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007498 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007499 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007500
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007501 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7502 return -EINVAL;
7503
7504 if (!info->attrs[NL80211_ATTR_MAC])
7505 return -EINVAL;
7506
7507 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7508 return -EINVAL;
7509
Johannes Berg4c476992010-10-04 21:36:35 +02007510 if (!rdev->ops->disassoc)
7511 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007512
Johannes Berg074ac8d2010-09-16 14:58:22 +02007513 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007514 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7515 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007516
Johannes Berg19957bb2009-07-02 17:20:43 +02007517 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007518
Johannes Berg19957bb2009-07-02 17:20:43 +02007519 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7520 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007521 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007522 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007523 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007524
7525 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007526 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7527 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007528 }
7529
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007530 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7531
Johannes Berg91bf9b22013-05-15 17:44:01 +02007532 wdev_lock(dev->ieee80211_ptr);
7533 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7534 local_state_change);
7535 wdev_unlock(dev->ieee80211_ptr);
7536 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007537}
7538
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007539static bool
7540nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7541 int mcast_rate[IEEE80211_NUM_BANDS],
7542 int rateval)
7543{
7544 struct wiphy *wiphy = &rdev->wiphy;
7545 bool found = false;
7546 int band, i;
7547
7548 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7549 struct ieee80211_supported_band *sband;
7550
7551 sband = wiphy->bands[band];
7552 if (!sband)
7553 continue;
7554
7555 for (i = 0; i < sband->n_bitrates; i++) {
7556 if (sband->bitrates[i].bitrate == rateval) {
7557 mcast_rate[band] = i + 1;
7558 found = true;
7559 break;
7560 }
7561 }
7562 }
7563
7564 return found;
7565}
7566
Johannes Berg04a773a2009-04-19 21:24:32 +02007567static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7568{
Johannes Berg4c476992010-10-04 21:36:35 +02007569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7570 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007571 struct cfg80211_ibss_params ibss;
7572 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007573 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007574 int err;
7575
Johannes Berg8e30bc52009-04-22 17:45:38 +02007576 memset(&ibss, 0, sizeof(ibss));
7577
Johannes Berg04a773a2009-04-19 21:24:32 +02007578 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7579 return -EINVAL;
7580
Johannes Berg683b6d32012-11-08 21:25:48 +01007581 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007582 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7583 return -EINVAL;
7584
Johannes Berg8e30bc52009-04-22 17:45:38 +02007585 ibss.beacon_interval = 100;
7586
7587 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7588 ibss.beacon_interval =
7589 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7590 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7591 return -EINVAL;
7592 }
7593
Johannes Berg4c476992010-10-04 21:36:35 +02007594 if (!rdev->ops->join_ibss)
7595 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007596
Johannes Berg4c476992010-10-04 21:36:35 +02007597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7598 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007599
Johannes Berg79c97e92009-07-07 03:56:12 +02007600 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007601
Johannes Berg39193492011-09-16 13:45:25 +02007602 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007603 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007604
7605 if (!is_valid_ether_addr(ibss.bssid))
7606 return -EINVAL;
7607 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007608 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7609 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7610
7611 if (info->attrs[NL80211_ATTR_IE]) {
7612 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7613 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7614 }
7615
Johannes Berg683b6d32012-11-08 21:25:48 +01007616 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7617 if (err)
7618 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007619
Ilan Peer174e0cd2014-02-23 09:13:01 +02007620 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7621 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007622 return -EINVAL;
7623
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007624 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007625 case NL80211_CHAN_WIDTH_5:
7626 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007627 case NL80211_CHAN_WIDTH_20_NOHT:
7628 break;
7629 case NL80211_CHAN_WIDTH_20:
7630 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007631 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7632 return -EINVAL;
7633 break;
7634 case NL80211_CHAN_WIDTH_80:
7635 case NL80211_CHAN_WIDTH_80P80:
7636 case NL80211_CHAN_WIDTH_160:
7637 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7638 return -EINVAL;
7639 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7640 NL80211_EXT_FEATURE_VHT_IBSS))
7641 return -EINVAL;
7642 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007643 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007644 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007645 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007646
Johannes Berg04a773a2009-04-19 21:24:32 +02007647 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007648 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007649
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007650 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7651 u8 *rates =
7652 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7653 int n_rates =
7654 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7655 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007656 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007657
Johannes Berg34850ab2011-07-18 18:08:35 +02007658 err = ieee80211_get_ratemask(sband, rates, n_rates,
7659 &ibss.basic_rates);
7660 if (err)
7661 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007662 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007663
Simon Wunderlich803768f2013-06-28 10:39:58 +02007664 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7665 memcpy(&ibss.ht_capa_mask,
7666 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7667 sizeof(ibss.ht_capa_mask));
7668
7669 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7670 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7671 return -EINVAL;
7672 memcpy(&ibss.ht_capa,
7673 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7674 sizeof(ibss.ht_capa));
7675 }
7676
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007677 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7678 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7679 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7680 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007681
Johannes Berg4c476992010-10-04 21:36:35 +02007682 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307683 bool no_ht = false;
7684
Johannes Berg4c476992010-10-04 21:36:35 +02007685 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307686 info->attrs[NL80211_ATTR_KEYS],
7687 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007688 if (IS_ERR(connkeys))
7689 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307690
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007691 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7692 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007693 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307694 return -EINVAL;
7695 }
Johannes Berg4c476992010-10-04 21:36:35 +02007696 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007697
Antonio Quartulli267335d2012-01-31 20:25:47 +01007698 ibss.control_port =
7699 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7700
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007701 ibss.userspace_handles_dfs =
7702 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7703
Johannes Berg4c476992010-10-04 21:36:35 +02007704 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007705 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007706 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007707 return err;
7708}
7709
7710static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7711{
Johannes Berg4c476992010-10-04 21:36:35 +02007712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7713 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007714
Johannes Berg4c476992010-10-04 21:36:35 +02007715 if (!rdev->ops->leave_ibss)
7716 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007717
Johannes Berg4c476992010-10-04 21:36:35 +02007718 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7719 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007720
Johannes Berg4c476992010-10-04 21:36:35 +02007721 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007722}
7723
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007724static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7725{
7726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7727 struct net_device *dev = info->user_ptr[1];
7728 int mcast_rate[IEEE80211_NUM_BANDS];
7729 u32 nla_rate;
7730 int err;
7731
7732 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007733 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7734 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007735 return -EOPNOTSUPP;
7736
7737 if (!rdev->ops->set_mcast_rate)
7738 return -EOPNOTSUPP;
7739
7740 memset(mcast_rate, 0, sizeof(mcast_rate));
7741
7742 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7743 return -EINVAL;
7744
7745 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7746 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7747 return -EINVAL;
7748
Ilan Peera1056b12015-10-22 22:27:46 +03007749 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007750
7751 return err;
7752}
7753
Johannes Bergad7e7182013-11-13 13:37:47 +01007754static struct sk_buff *
7755__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007756 struct wireless_dev *wdev, int approxlen,
7757 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007758 enum nl80211_attrs attr,
7759 const struct nl80211_vendor_cmd_info *info,
7760 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007761{
7762 struct sk_buff *skb;
7763 void *hdr;
7764 struct nlattr *data;
7765
7766 skb = nlmsg_new(approxlen + 100, gfp);
7767 if (!skb)
7768 return NULL;
7769
7770 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7771 if (!hdr) {
7772 kfree_skb(skb);
7773 return NULL;
7774 }
7775
7776 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7777 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007778
7779 if (info) {
7780 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7781 info->vendor_id))
7782 goto nla_put_failure;
7783 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7784 info->subcmd))
7785 goto nla_put_failure;
7786 }
7787
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007788 if (wdev) {
7789 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7790 wdev_id(wdev)))
7791 goto nla_put_failure;
7792 if (wdev->netdev &&
7793 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7794 wdev->netdev->ifindex))
7795 goto nla_put_failure;
7796 }
7797
Johannes Bergad7e7182013-11-13 13:37:47 +01007798 data = nla_nest_start(skb, attr);
7799
7800 ((void **)skb->cb)[0] = rdev;
7801 ((void **)skb->cb)[1] = hdr;
7802 ((void **)skb->cb)[2] = data;
7803
7804 return skb;
7805
7806 nla_put_failure:
7807 kfree_skb(skb);
7808 return NULL;
7809}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007810
Johannes Berge03ad6e2014-01-01 17:22:30 +01007811struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007812 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007813 enum nl80211_commands cmd,
7814 enum nl80211_attrs attr,
7815 int vendor_event_idx,
7816 int approxlen, gfp_t gfp)
7817{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007818 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007819 const struct nl80211_vendor_cmd_info *info;
7820
7821 switch (cmd) {
7822 case NL80211_CMD_TESTMODE:
7823 if (WARN_ON(vendor_event_idx != -1))
7824 return NULL;
7825 info = NULL;
7826 break;
7827 case NL80211_CMD_VENDOR:
7828 if (WARN_ON(vendor_event_idx < 0 ||
7829 vendor_event_idx >= wiphy->n_vendor_events))
7830 return NULL;
7831 info = &wiphy->vendor_events[vendor_event_idx];
7832 break;
7833 default:
7834 WARN_ON(1);
7835 return NULL;
7836 }
7837
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007838 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007839 cmd, attr, info, gfp);
7840}
7841EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7842
7843void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7844{
7845 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7846 void *hdr = ((void **)skb->cb)[1];
7847 struct nlattr *data = ((void **)skb->cb)[2];
7848 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7849
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007850 /* clear CB data for netlink core to own from now on */
7851 memset(skb->cb, 0, sizeof(skb->cb));
7852
Johannes Berge03ad6e2014-01-01 17:22:30 +01007853 nla_nest_end(skb, data);
7854 genlmsg_end(skb, hdr);
7855
7856 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7857 mcgrp = NL80211_MCGRP_VENDOR;
7858
7859 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7860 mcgrp, gfp);
7861}
7862EXPORT_SYMBOL(__cfg80211_send_event_skb);
7863
Johannes Bergaff89a92009-07-01 21:26:51 +02007864#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007865static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7866{
Johannes Berg4c476992010-10-04 21:36:35 +02007867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007868 struct wireless_dev *wdev =
7869 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007870 int err;
7871
David Spinadelfc73f112013-07-31 18:04:15 +03007872 if (!rdev->ops->testmode_cmd)
7873 return -EOPNOTSUPP;
7874
7875 if (IS_ERR(wdev)) {
7876 err = PTR_ERR(wdev);
7877 if (err != -EINVAL)
7878 return err;
7879 wdev = NULL;
7880 } else if (wdev->wiphy != &rdev->wiphy) {
7881 return -EINVAL;
7882 }
7883
Johannes Bergaff89a92009-07-01 21:26:51 +02007884 if (!info->attrs[NL80211_ATTR_TESTDATA])
7885 return -EINVAL;
7886
Johannes Bergad7e7182013-11-13 13:37:47 +01007887 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007888 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007889 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7890 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007891 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007892
Johannes Bergaff89a92009-07-01 21:26:51 +02007893 return err;
7894}
7895
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007896static int nl80211_testmode_dump(struct sk_buff *skb,
7897 struct netlink_callback *cb)
7898{
Johannes Berg00918d32011-12-13 17:22:05 +01007899 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007900 int err;
7901 long phy_idx;
7902 void *data = NULL;
7903 int data_len = 0;
7904
Johannes Berg5fe231e2013-05-08 21:45:15 +02007905 rtnl_lock();
7906
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007907 if (cb->args[0]) {
7908 /*
7909 * 0 is a valid index, but not valid for args[0],
7910 * so we need to offset by 1.
7911 */
7912 phy_idx = cb->args[0] - 1;
7913 } else {
7914 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7915 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7916 nl80211_policy);
7917 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007918 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007919
Johannes Berg2bd7e352012-06-15 14:23:16 +02007920 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7921 nl80211_fam.attrbuf);
7922 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007923 err = PTR_ERR(rdev);
7924 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007925 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007926 phy_idx = rdev->wiphy_idx;
7927 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007928
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007929 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7930 cb->args[1] =
7931 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7932 }
7933
7934 if (cb->args[1]) {
7935 data = nla_data((void *)cb->args[1]);
7936 data_len = nla_len((void *)cb->args[1]);
7937 }
7938
Johannes Berg00918d32011-12-13 17:22:05 +01007939 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7940 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007941 err = -ENOENT;
7942 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007943 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007944
Johannes Berg00918d32011-12-13 17:22:05 +01007945 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007946 err = -EOPNOTSUPP;
7947 goto out_err;
7948 }
7949
7950 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007951 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007952 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7953 NL80211_CMD_TESTMODE);
7954 struct nlattr *tmdata;
7955
Dan Carpentercb35fba2013-08-14 14:50:01 +03007956 if (!hdr)
7957 break;
7958
David S. Miller9360ffd2012-03-29 04:41:26 -04007959 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007960 genlmsg_cancel(skb, hdr);
7961 break;
7962 }
7963
7964 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7965 if (!tmdata) {
7966 genlmsg_cancel(skb, hdr);
7967 break;
7968 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007969 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007970 nla_nest_end(skb, tmdata);
7971
7972 if (err == -ENOBUFS || err == -ENOENT) {
7973 genlmsg_cancel(skb, hdr);
7974 break;
7975 } else if (err) {
7976 genlmsg_cancel(skb, hdr);
7977 goto out_err;
7978 }
7979
7980 genlmsg_end(skb, hdr);
7981 }
7982
7983 err = skb->len;
7984 /* see above */
7985 cb->args[0] = phy_idx + 1;
7986 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007987 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007988 return err;
7989}
Johannes Bergaff89a92009-07-01 21:26:51 +02007990#endif
7991
Samuel Ortizb23aa672009-07-01 21:26:54 +02007992static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7993{
Johannes Berg4c476992010-10-04 21:36:35 +02007994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7995 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007996 struct cfg80211_connect_params connect;
7997 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007998 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007999 int err;
8000
8001 memset(&connect, 0, sizeof(connect));
8002
8003 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8004 return -EINVAL;
8005
8006 if (!info->attrs[NL80211_ATTR_SSID] ||
8007 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8008 return -EINVAL;
8009
8010 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8011 connect.auth_type =
8012 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008013 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8014 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008015 return -EINVAL;
8016 } else
8017 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8018
8019 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8020
Johannes Bergc0692b82010-08-27 14:26:53 +03008021 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008022 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008023 if (err)
8024 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008025
Johannes Berg074ac8d2010-09-16 14:58:22 +02008026 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008027 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8028 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008029
Johannes Berg79c97e92009-07-07 03:56:12 +02008030 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008031
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308032 connect.bg_scan_period = -1;
8033 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8034 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8035 connect.bg_scan_period =
8036 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8037 }
8038
Samuel Ortizb23aa672009-07-01 21:26:54 +02008039 if (info->attrs[NL80211_ATTR_MAC])
8040 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008041 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8042 connect.bssid_hint =
8043 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008044 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8045 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8046
8047 if (info->attrs[NL80211_ATTR_IE]) {
8048 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8049 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8050 }
8051
Jouni Malinencee00a92013-01-15 17:15:57 +02008052 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8053 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8054 if (connect.mfp != NL80211_MFP_REQUIRED &&
8055 connect.mfp != NL80211_MFP_NO)
8056 return -EINVAL;
8057 } else {
8058 connect.mfp = NL80211_MFP_NO;
8059 }
8060
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008061 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8062 connect.prev_bssid =
8063 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8064
Samuel Ortizb23aa672009-07-01 21:26:54 +02008065 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008066 connect.channel = nl80211_get_valid_chan(
8067 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8068 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008069 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008070 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008071 connect.channel_hint = nl80211_get_valid_chan(
8072 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8073 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008074 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008075 }
8076
Johannes Bergfffd0932009-07-08 14:22:54 +02008077 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8078 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308079 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008080 if (IS_ERR(connkeys))
8081 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008082 }
8083
Ben Greear7e7c8922011-11-18 11:31:59 -08008084 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8085 connect.flags |= ASSOC_REQ_DISABLE_HT;
8086
8087 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8088 memcpy(&connect.ht_capa_mask,
8089 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8090 sizeof(connect.ht_capa_mask));
8091
8092 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008093 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008094 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008095 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008096 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008097 memcpy(&connect.ht_capa,
8098 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8099 sizeof(connect.ht_capa));
8100 }
8101
Johannes Bergee2aca32013-02-21 17:36:01 +01008102 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8103 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8104
8105 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8106 memcpy(&connect.vht_capa_mask,
8107 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8108 sizeof(connect.vht_capa_mask));
8109
8110 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8111 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008112 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008113 return -EINVAL;
8114 }
8115 memcpy(&connect.vht_capa,
8116 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8117 sizeof(connect.vht_capa));
8118 }
8119
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008120 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008121 if (!((rdev->wiphy.features &
8122 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8123 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8124 !wiphy_ext_feature_isset(&rdev->wiphy,
8125 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008126 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008127 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008128 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008129 connect.flags |= ASSOC_REQ_USE_RRM;
8130 }
8131
Lior David34d50512016-01-28 10:58:25 +02008132 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
8133 if (connect.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ]) {
8134 kzfree(connkeys);
8135 return -EOPNOTSUPP;
8136 }
8137
Arend van Spriel38de03d2016-03-02 20:37:18 +01008138 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8139 /* bss selection makes no sense if bssid is set */
8140 if (connect.bssid) {
8141 kzfree(connkeys);
8142 return -EINVAL;
8143 }
8144
8145 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8146 wiphy, &connect.bss_select);
8147 if (err) {
8148 kzfree(connkeys);
8149 return err;
8150 }
8151 }
8152
Johannes Berg83739b02013-05-15 17:44:01 +02008153 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008154 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8155 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008156 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008157 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008158 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008159 return err;
8160}
8161
8162static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8163{
Johannes Berg4c476992010-10-04 21:36:35 +02008164 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8165 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008166 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008167 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008168
8169 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8170 reason = WLAN_REASON_DEAUTH_LEAVING;
8171 else
8172 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8173
8174 if (reason == 0)
8175 return -EINVAL;
8176
Johannes Berg074ac8d2010-09-16 14:58:22 +02008177 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008178 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8179 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008180
Johannes Berg83739b02013-05-15 17:44:01 +02008181 wdev_lock(dev->ieee80211_ptr);
8182 ret = cfg80211_disconnect(rdev, dev, reason, true);
8183 wdev_unlock(dev->ieee80211_ptr);
8184 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008185}
8186
Johannes Berg463d0182009-07-14 00:33:35 +02008187static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8188{
Johannes Berg4c476992010-10-04 21:36:35 +02008189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008190 struct net *net;
8191 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008192
Vadim Kochan4b681c82015-01-12 16:34:05 +02008193 if (info->attrs[NL80211_ATTR_PID]) {
8194 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8195
8196 net = get_net_ns_by_pid(pid);
8197 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8198 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8199
8200 net = get_net_ns_by_fd(fd);
8201 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008202 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008203 }
Johannes Berg463d0182009-07-14 00:33:35 +02008204
Johannes Berg4c476992010-10-04 21:36:35 +02008205 if (IS_ERR(net))
8206 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008207
8208 err = 0;
8209
8210 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008211 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8212 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008213
Johannes Berg463d0182009-07-14 00:33:35 +02008214 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008215 return err;
8216}
8217
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008218static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8219{
Johannes Berg4c476992010-10-04 21:36:35 +02008220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008221 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8222 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008223 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008224 struct cfg80211_pmksa pmksa;
8225
8226 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8227
8228 if (!info->attrs[NL80211_ATTR_MAC])
8229 return -EINVAL;
8230
8231 if (!info->attrs[NL80211_ATTR_PMKID])
8232 return -EINVAL;
8233
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008234 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8235 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8236
Johannes Berg074ac8d2010-09-16 14:58:22 +02008237 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008238 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8239 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008240
8241 switch (info->genlhdr->cmd) {
8242 case NL80211_CMD_SET_PMKSA:
8243 rdev_ops = rdev->ops->set_pmksa;
8244 break;
8245 case NL80211_CMD_DEL_PMKSA:
8246 rdev_ops = rdev->ops->del_pmksa;
8247 break;
8248 default:
8249 WARN_ON(1);
8250 break;
8251 }
8252
Johannes Berg4c476992010-10-04 21:36:35 +02008253 if (!rdev_ops)
8254 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008255
Johannes Berg4c476992010-10-04 21:36:35 +02008256 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008257}
8258
8259static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8260{
Johannes Berg4c476992010-10-04 21:36:35 +02008261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8262 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008263
Johannes Berg074ac8d2010-09-16 14:58:22 +02008264 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008265 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8266 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008267
Johannes Berg4c476992010-10-04 21:36:35 +02008268 if (!rdev->ops->flush_pmksa)
8269 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008270
Hila Gonene35e4d22012-06-27 17:19:42 +03008271 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008272}
8273
Arik Nemtsov109086c2011-09-28 14:12:50 +03008274static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8275{
8276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8277 struct net_device *dev = info->user_ptr[1];
8278 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308279 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008280 u16 status_code;
8281 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008282 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008283
8284 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8285 !rdev->ops->tdls_mgmt)
8286 return -EOPNOTSUPP;
8287
8288 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8289 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8290 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8291 !info->attrs[NL80211_ATTR_IE] ||
8292 !info->attrs[NL80211_ATTR_MAC])
8293 return -EINVAL;
8294
8295 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8296 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8297 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8298 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008299 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308300 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8301 peer_capability =
8302 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008303
Hila Gonene35e4d22012-06-27 17:19:42 +03008304 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308305 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008306 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008307 nla_data(info->attrs[NL80211_ATTR_IE]),
8308 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008309}
8310
8311static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8312{
8313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8314 struct net_device *dev = info->user_ptr[1];
8315 enum nl80211_tdls_operation operation;
8316 u8 *peer;
8317
8318 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8319 !rdev->ops->tdls_oper)
8320 return -EOPNOTSUPP;
8321
8322 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8323 !info->attrs[NL80211_ATTR_MAC])
8324 return -EINVAL;
8325
8326 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8327 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8328
Hila Gonene35e4d22012-06-27 17:19:42 +03008329 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008330}
8331
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008332static int nl80211_remain_on_channel(struct sk_buff *skb,
8333 struct genl_info *info)
8334{
Johannes Berg4c476992010-10-04 21:36:35 +02008335 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008336 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008337 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008338 struct sk_buff *msg;
8339 void *hdr;
8340 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008341 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008342 int err;
8343
8344 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8345 !info->attrs[NL80211_ATTR_DURATION])
8346 return -EINVAL;
8347
8348 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8349
Johannes Berg7c4ef712011-11-18 15:33:48 +01008350 if (!rdev->ops->remain_on_channel ||
8351 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008352 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008353
Johannes Bergebf348f2012-06-01 12:50:54 +02008354 /*
8355 * We should be on that channel for at least a minimum amount of
8356 * time (10ms) but no longer than the driver supports.
8357 */
8358 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8359 duration > rdev->wiphy.max_remain_on_channel_duration)
8360 return -EINVAL;
8361
Johannes Berg683b6d32012-11-08 21:25:48 +01008362 err = nl80211_parse_chandef(rdev, info, &chandef);
8363 if (err)
8364 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008365
8366 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008367 if (!msg)
8368 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008369
Eric W. Biederman15e47302012-09-07 20:12:54 +00008370 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008371 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008372 if (!hdr) {
8373 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008374 goto free_msg;
8375 }
8376
Johannes Berg683b6d32012-11-08 21:25:48 +01008377 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8378 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008379
8380 if (err)
8381 goto free_msg;
8382
David S. Miller9360ffd2012-03-29 04:41:26 -04008383 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8384 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008385
8386 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008387
8388 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008389
8390 nla_put_failure:
8391 err = -ENOBUFS;
8392 free_msg:
8393 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008394 return err;
8395}
8396
8397static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8398 struct genl_info *info)
8399{
Johannes Berg4c476992010-10-04 21:36:35 +02008400 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008401 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008402 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008403
8404 if (!info->attrs[NL80211_ATTR_COOKIE])
8405 return -EINVAL;
8406
Johannes Berg4c476992010-10-04 21:36:35 +02008407 if (!rdev->ops->cancel_remain_on_channel)
8408 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008409
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008410 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8411
Hila Gonene35e4d22012-06-27 17:19:42 +03008412 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008413}
8414
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008415static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8416 u8 *rates, u8 rates_len)
8417{
8418 u8 i;
8419 u32 mask = 0;
8420
8421 for (i = 0; i < rates_len; i++) {
8422 int rate = (rates[i] & 0x7f) * 5;
8423 int ridx;
8424 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8425 struct ieee80211_rate *srate =
8426 &sband->bitrates[ridx];
8427 if (rate == srate->bitrate) {
8428 mask |= 1 << ridx;
8429 break;
8430 }
8431 }
8432 if (ridx == sband->n_bitrates)
8433 return 0; /* rate not found */
8434 }
8435
8436 return mask;
8437}
8438
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008439static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8440 u8 *rates, u8 rates_len,
8441 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8442{
8443 u8 i;
8444
8445 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8446
8447 for (i = 0; i < rates_len; i++) {
8448 int ridx, rbit;
8449
8450 ridx = rates[i] / 8;
8451 rbit = BIT(rates[i] % 8);
8452
8453 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008454 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008455 return false;
8456
8457 /* check availability */
8458 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8459 mcs[ridx] |= rbit;
8460 else
8461 return false;
8462 }
8463
8464 return true;
8465}
8466
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008467static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8468{
8469 u16 mcs_mask = 0;
8470
8471 switch (vht_mcs_map) {
8472 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8473 break;
8474 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8475 mcs_mask = 0x00FF;
8476 break;
8477 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8478 mcs_mask = 0x01FF;
8479 break;
8480 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8481 mcs_mask = 0x03FF;
8482 break;
8483 default:
8484 break;
8485 }
8486
8487 return mcs_mask;
8488}
8489
8490static void vht_build_mcs_mask(u16 vht_mcs_map,
8491 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8492{
8493 u8 nss;
8494
8495 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8496 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8497 vht_mcs_map >>= 2;
8498 }
8499}
8500
8501static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8502 struct nl80211_txrate_vht *txrate,
8503 u16 mcs[NL80211_VHT_NSS_MAX])
8504{
8505 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8506 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8507 u8 i;
8508
8509 if (!sband->vht_cap.vht_supported)
8510 return false;
8511
8512 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8513
8514 /* Build vht_mcs_mask from VHT capabilities */
8515 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8516
8517 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8518 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8519 mcs[i] = txrate->mcs[i];
8520 else
8521 return false;
8522 }
8523
8524 return true;
8525}
8526
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008527static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008528 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8529 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008530 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8531 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008532 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008533 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008534};
8535
8536static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8537 struct genl_info *info)
8538{
8539 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008541 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008542 int rem, i;
8543 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008544 struct nlattr *tx_rates;
8545 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008546 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008547
Johannes Berg4c476992010-10-04 21:36:35 +02008548 if (!rdev->ops->set_bitrate_mask)
8549 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008550
8551 memset(&mask, 0, sizeof(mask));
8552 /* Default to all rates enabled */
8553 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8554 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008555
8556 if (!sband)
8557 continue;
8558
8559 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008560 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008561 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008562 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008563
8564 if (!sband->vht_cap.vht_supported)
8565 continue;
8566
8567 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8568 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008569 }
8570
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008571 /* if no rates are given set it back to the defaults */
8572 if (!info->attrs[NL80211_ATTR_TX_RATES])
8573 goto out;
8574
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008575 /*
8576 * The nested attribute uses enum nl80211_band as the index. This maps
8577 * directly to the enum ieee80211_band values used in cfg80211.
8578 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008579 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008580 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008581 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008582 int err;
8583
Johannes Berg4c476992010-10-04 21:36:35 +02008584 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8585 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008586 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008587 if (sband == NULL)
8588 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008589 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8590 nla_len(tx_rates), nl80211_txattr_policy);
8591 if (err)
8592 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008593 if (tb[NL80211_TXRATE_LEGACY]) {
8594 mask.control[band].legacy = rateset_to_mask(
8595 sband,
8596 nla_data(tb[NL80211_TXRATE_LEGACY]),
8597 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308598 if ((mask.control[band].legacy == 0) &&
8599 nla_len(tb[NL80211_TXRATE_LEGACY]))
8600 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008601 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008602 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008603 if (!ht_rateset_to_mask(
8604 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008605 nla_data(tb[NL80211_TXRATE_HT]),
8606 nla_len(tb[NL80211_TXRATE_HT]),
8607 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008608 return -EINVAL;
8609 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008610 if (tb[NL80211_TXRATE_VHT]) {
8611 if (!vht_set_mcs_mask(
8612 sband,
8613 nla_data(tb[NL80211_TXRATE_VHT]),
8614 mask.control[band].vht_mcs))
8615 return -EINVAL;
8616 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008617 if (tb[NL80211_TXRATE_GI]) {
8618 mask.control[band].gi =
8619 nla_get_u8(tb[NL80211_TXRATE_GI]);
8620 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8621 return -EINVAL;
8622 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008623
8624 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008625 /* don't allow empty legacy rates if HT or VHT
8626 * are not even supported.
8627 */
8628 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8629 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008630 return -EINVAL;
8631
8632 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008633 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008634 goto out;
8635
8636 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8637 if (mask.control[band].vht_mcs[i])
8638 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008639
8640 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008641 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008642 }
8643 }
8644
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008645out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008646 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008647}
8648
Johannes Berg2e161f72010-08-12 15:38:38 +02008649static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008650{
Johannes Berg4c476992010-10-04 21:36:35 +02008651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008652 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008653 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008654
8655 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8656 return -EINVAL;
8657
Johannes Berg2e161f72010-08-12 15:38:38 +02008658 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8659 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008660
Johannes Berg71bbc992012-06-15 15:30:18 +02008661 switch (wdev->iftype) {
8662 case NL80211_IFTYPE_STATION:
8663 case NL80211_IFTYPE_ADHOC:
8664 case NL80211_IFTYPE_P2P_CLIENT:
8665 case NL80211_IFTYPE_AP:
8666 case NL80211_IFTYPE_AP_VLAN:
8667 case NL80211_IFTYPE_MESH_POINT:
8668 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008669 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008670 break;
8671 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008672 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008673 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008674
8675 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008676 if (!rdev->ops->mgmt_tx)
8677 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008678
Eric W. Biederman15e47302012-09-07 20:12:54 +00008679 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008680 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8681 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008682}
8683
Johannes Berg2e161f72010-08-12 15:38:38 +02008684static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008685{
Johannes Berg4c476992010-10-04 21:36:35 +02008686 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008687 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008688 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008689 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008690 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008691 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008692 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008693 struct cfg80211_mgmt_tx_params params = {
8694 .dont_wait_for_ack =
8695 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8696 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008697
Johannes Berg683b6d32012-11-08 21:25:48 +01008698 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008699 return -EINVAL;
8700
Johannes Berg4c476992010-10-04 21:36:35 +02008701 if (!rdev->ops->mgmt_tx)
8702 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008703
Johannes Berg71bbc992012-06-15 15:30:18 +02008704 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008705 case NL80211_IFTYPE_P2P_DEVICE:
8706 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8707 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008708 case NL80211_IFTYPE_STATION:
8709 case NL80211_IFTYPE_ADHOC:
8710 case NL80211_IFTYPE_P2P_CLIENT:
8711 case NL80211_IFTYPE_AP:
8712 case NL80211_IFTYPE_AP_VLAN:
8713 case NL80211_IFTYPE_MESH_POINT:
8714 case NL80211_IFTYPE_P2P_GO:
8715 break;
8716 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008717 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008718 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008719
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008720 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008721 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008722 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008723 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008724
8725 /*
8726 * We should wait on the channel for at least a minimum amount
8727 * of time (10ms) but no longer than the driver supports.
8728 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008729 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8730 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008731 return -EINVAL;
8732
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008733 }
8734
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008735 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008736
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008737 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008738 return -EINVAL;
8739
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008740 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308741
Antonio Quartulliea141b752013-06-11 14:20:03 +02008742 /* get the channel if any has been specified, otherwise pass NULL to
8743 * the driver. The latter will use the current one
8744 */
8745 chandef.chan = NULL;
8746 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8747 err = nl80211_parse_chandef(rdev, info, &chandef);
8748 if (err)
8749 return err;
8750 }
8751
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008752 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008753 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008754
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008755 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8756 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8757
8758 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8759 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8760 int i;
8761
8762 if (len % sizeof(u16))
8763 return -EINVAL;
8764
8765 params.n_csa_offsets = len / sizeof(u16);
8766 params.csa_offsets =
8767 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8768
8769 /* check that all the offsets fit the frame */
8770 for (i = 0; i < params.n_csa_offsets; i++) {
8771 if (params.csa_offsets[i] >= params.len)
8772 return -EINVAL;
8773 }
8774 }
8775
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008776 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008777 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8778 if (!msg)
8779 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008780
Eric W. Biederman15e47302012-09-07 20:12:54 +00008781 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008782 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008783 if (!hdr) {
8784 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008785 goto free_msg;
8786 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008787 }
Johannes Berge247bd902011-11-04 11:18:21 +01008788
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008789 params.chan = chandef.chan;
8790 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008791 if (err)
8792 goto free_msg;
8793
Johannes Berge247bd902011-11-04 11:18:21 +01008794 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008795 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8796 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008797
Johannes Berge247bd902011-11-04 11:18:21 +01008798 genlmsg_end(msg, hdr);
8799 return genlmsg_reply(msg, info);
8800 }
8801
8802 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008803
8804 nla_put_failure:
8805 err = -ENOBUFS;
8806 free_msg:
8807 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008808 return err;
8809}
8810
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008811static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8812{
8813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008814 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008815 u64 cookie;
8816
8817 if (!info->attrs[NL80211_ATTR_COOKIE])
8818 return -EINVAL;
8819
8820 if (!rdev->ops->mgmt_tx_cancel_wait)
8821 return -EOPNOTSUPP;
8822
Johannes Berg71bbc992012-06-15 15:30:18 +02008823 switch (wdev->iftype) {
8824 case NL80211_IFTYPE_STATION:
8825 case NL80211_IFTYPE_ADHOC:
8826 case NL80211_IFTYPE_P2P_CLIENT:
8827 case NL80211_IFTYPE_AP:
8828 case NL80211_IFTYPE_AP_VLAN:
8829 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008830 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008831 break;
8832 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008833 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008834 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008835
8836 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8837
Hila Gonene35e4d22012-06-27 17:19:42 +03008838 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008839}
8840
Kalle Valoffb9eb32010-02-17 17:58:10 +02008841static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8842{
Johannes Berg4c476992010-10-04 21:36:35 +02008843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008844 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008845 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008846 u8 ps_state;
8847 bool state;
8848 int err;
8849
Johannes Berg4c476992010-10-04 21:36:35 +02008850 if (!info->attrs[NL80211_ATTR_PS_STATE])
8851 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008852
8853 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8854
Johannes Berg4c476992010-10-04 21:36:35 +02008855 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8856 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008857
8858 wdev = dev->ieee80211_ptr;
8859
Johannes Berg4c476992010-10-04 21:36:35 +02008860 if (!rdev->ops->set_power_mgmt)
8861 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008862
8863 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8864
8865 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008866 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008867
Hila Gonene35e4d22012-06-27 17:19:42 +03008868 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008869 if (!err)
8870 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008871 return err;
8872}
8873
8874static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8875{
Johannes Berg4c476992010-10-04 21:36:35 +02008876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008877 enum nl80211_ps_state ps_state;
8878 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008879 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008880 struct sk_buff *msg;
8881 void *hdr;
8882 int err;
8883
Kalle Valoffb9eb32010-02-17 17:58:10 +02008884 wdev = dev->ieee80211_ptr;
8885
Johannes Berg4c476992010-10-04 21:36:35 +02008886 if (!rdev->ops->set_power_mgmt)
8887 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008888
8889 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008890 if (!msg)
8891 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008892
Eric W. Biederman15e47302012-09-07 20:12:54 +00008893 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008894 NL80211_CMD_GET_POWER_SAVE);
8895 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008896 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008897 goto free_msg;
8898 }
8899
8900 if (wdev->ps)
8901 ps_state = NL80211_PS_ENABLED;
8902 else
8903 ps_state = NL80211_PS_DISABLED;
8904
David S. Miller9360ffd2012-03-29 04:41:26 -04008905 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8906 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008907
8908 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008909 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008910
Johannes Berg4c476992010-10-04 21:36:35 +02008911 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008912 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008913 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008914 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008915 return err;
8916}
8917
Johannes Berg94e860f2014-01-20 23:58:15 +01008918static const struct nla_policy
8919nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008920 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8921 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8922 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008923 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8924 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8925 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008926};
8927
Thomas Pedersen84f10702012-07-12 16:17:33 -07008928static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008929 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008930{
8931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008932 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008933 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008934
Johannes Bergd9d8b012012-11-26 12:51:52 +01008935 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008936 return -EINVAL;
8937
Thomas Pedersen84f10702012-07-12 16:17:33 -07008938 if (!rdev->ops->set_cqm_txe_config)
8939 return -EOPNOTSUPP;
8940
8941 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8942 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8943 return -EOPNOTSUPP;
8944
Hila Gonene35e4d22012-06-27 17:19:42 +03008945 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008946}
8947
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008948static int nl80211_set_cqm_rssi(struct genl_info *info,
8949 s32 threshold, u32 hysteresis)
8950{
Johannes Berg4c476992010-10-04 21:36:35 +02008951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008952 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008953 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008954
8955 if (threshold > 0)
8956 return -EINVAL;
8957
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008958 /* disabling - hysteresis should also be zero then */
8959 if (threshold == 0)
8960 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008961
Johannes Berg4c476992010-10-04 21:36:35 +02008962 if (!rdev->ops->set_cqm_rssi_config)
8963 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008964
Johannes Berg074ac8d2010-09-16 14:58:22 +02008965 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008966 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8967 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008968
Hila Gonene35e4d22012-06-27 17:19:42 +03008969 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008970}
8971
8972static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8973{
8974 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8975 struct nlattr *cqm;
8976 int err;
8977
8978 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008979 if (!cqm)
8980 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008981
8982 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8983 nl80211_attr_cqm_policy);
8984 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008985 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008986
8987 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8988 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008989 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8990 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008991
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008992 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8993 }
8994
8995 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8996 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8997 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8998 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8999 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9000 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9001
9002 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9003 }
9004
9005 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009006}
9007
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009008static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9009{
9010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9011 struct net_device *dev = info->user_ptr[1];
9012 struct ocb_setup setup = {};
9013 int err;
9014
9015 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9016 if (err)
9017 return err;
9018
9019 return cfg80211_join_ocb(rdev, dev, &setup);
9020}
9021
9022static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9023{
9024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9025 struct net_device *dev = info->user_ptr[1];
9026
9027 return cfg80211_leave_ocb(rdev, dev);
9028}
9029
Johannes Berg29cbe682010-12-03 09:20:44 +01009030static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9031{
9032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9033 struct net_device *dev = info->user_ptr[1];
9034 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009035 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009036 int err;
9037
9038 /* start with default */
9039 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009040 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009041
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009042 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009043 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009044 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009045 if (err)
9046 return err;
9047 }
9048
9049 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9050 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9051 return -EINVAL;
9052
Javier Cardonac80d5452010-12-16 17:37:49 -08009053 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9054 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9055
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009056 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9057 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9058 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9059 return -EINVAL;
9060
Marco Porsch9bdbf042013-01-07 16:04:51 +01009061 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9062 setup.beacon_interval =
9063 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9064 if (setup.beacon_interval < 10 ||
9065 setup.beacon_interval > 10000)
9066 return -EINVAL;
9067 }
9068
9069 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9070 setup.dtim_period =
9071 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9072 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9073 return -EINVAL;
9074 }
9075
Javier Cardonac80d5452010-12-16 17:37:49 -08009076 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9077 /* parse additional setup parameters if given */
9078 err = nl80211_parse_mesh_setup(info, &setup);
9079 if (err)
9080 return err;
9081 }
9082
Thomas Pedersend37bb182013-03-04 13:06:13 -08009083 if (setup.user_mpm)
9084 cfg.auto_open_plinks = false;
9085
Johannes Bergcc1d2802012-05-16 23:50:20 +02009086 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009087 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9088 if (err)
9089 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009090 } else {
9091 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009092 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009093 }
9094
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009095 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9096 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9097 int n_rates =
9098 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9099 struct ieee80211_supported_band *sband;
9100
9101 if (!setup.chandef.chan)
9102 return -EINVAL;
9103
9104 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9105
9106 err = ieee80211_get_ratemask(sband, rates, n_rates,
9107 &setup.basic_rates);
9108 if (err)
9109 return err;
9110 }
9111
Javier Cardonac80d5452010-12-16 17:37:49 -08009112 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009113}
9114
9115static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9116{
9117 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9118 struct net_device *dev = info->user_ptr[1];
9119
9120 return cfg80211_leave_mesh(rdev, dev);
9121}
9122
Johannes Bergdfb89c52012-06-27 09:23:48 +02009123#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009124static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9125 struct cfg80211_registered_device *rdev)
9126{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009127 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009128 struct nlattr *nl_pats, *nl_pat;
9129 int i, pat_len;
9130
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009131 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009132 return 0;
9133
9134 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9135 if (!nl_pats)
9136 return -ENOBUFS;
9137
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009138 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009139 nl_pat = nla_nest_start(msg, i + 1);
9140 if (!nl_pat)
9141 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009142 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009143 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009144 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009145 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9146 wowlan->patterns[i].pattern) ||
9147 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009148 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009149 return -ENOBUFS;
9150 nla_nest_end(msg, nl_pat);
9151 }
9152 nla_nest_end(msg, nl_pats);
9153
9154 return 0;
9155}
9156
Johannes Berg2a0e0472013-01-23 22:57:40 +01009157static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9158 struct cfg80211_wowlan_tcp *tcp)
9159{
9160 struct nlattr *nl_tcp;
9161
9162 if (!tcp)
9163 return 0;
9164
9165 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9166 if (!nl_tcp)
9167 return -ENOBUFS;
9168
Jiri Benc930345e2015-03-29 16:59:25 +02009169 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9170 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009171 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9172 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9173 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9174 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9175 tcp->payload_len, tcp->payload) ||
9176 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9177 tcp->data_interval) ||
9178 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9179 tcp->wake_len, tcp->wake_data) ||
9180 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9181 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9182 return -ENOBUFS;
9183
9184 if (tcp->payload_seq.len &&
9185 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9186 sizeof(tcp->payload_seq), &tcp->payload_seq))
9187 return -ENOBUFS;
9188
9189 if (tcp->payload_tok.len &&
9190 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9191 sizeof(tcp->payload_tok) + tcp->tokens_size,
9192 &tcp->payload_tok))
9193 return -ENOBUFS;
9194
Johannes Berge248ad32013-05-16 10:24:28 +02009195 nla_nest_end(msg, nl_tcp);
9196
Johannes Berg2a0e0472013-01-23 22:57:40 +01009197 return 0;
9198}
9199
Luciano Coelho75453cc2015-01-09 14:06:37 +02009200static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9201 struct cfg80211_sched_scan_request *req)
9202{
Avraham Stern3b06d272015-10-12 09:51:34 +03009203 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009204 int i;
9205
9206 if (!req)
9207 return 0;
9208
9209 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9210 if (!nd)
9211 return -ENOBUFS;
9212
Avraham Stern3b06d272015-10-12 09:51:34 +03009213 if (req->n_scan_plans == 1 &&
9214 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9215 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009216 return -ENOBUFS;
9217
Luciano Coelho21fea562015-03-17 16:36:01 +02009218 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9219 return -ENOBUFS;
9220
Luciano Coelho75453cc2015-01-09 14:06:37 +02009221 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9222 if (!freqs)
9223 return -ENOBUFS;
9224
9225 for (i = 0; i < req->n_channels; i++)
9226 nla_put_u32(msg, i, req->channels[i]->center_freq);
9227
9228 nla_nest_end(msg, freqs);
9229
9230 if (req->n_match_sets) {
9231 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9232 for (i = 0; i < req->n_match_sets; i++) {
9233 match = nla_nest_start(msg, i);
9234 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9235 req->match_sets[i].ssid.ssid_len,
9236 req->match_sets[i].ssid.ssid);
9237 nla_nest_end(msg, match);
9238 }
9239 nla_nest_end(msg, matches);
9240 }
9241
Avraham Stern3b06d272015-10-12 09:51:34 +03009242 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9243 if (!scan_plans)
9244 return -ENOBUFS;
9245
9246 for (i = 0; i < req->n_scan_plans; i++) {
9247 scan_plan = nla_nest_start(msg, i + 1);
9248 if (!scan_plan ||
9249 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9250 req->scan_plans[i].interval) ||
9251 (req->scan_plans[i].iterations &&
9252 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9253 req->scan_plans[i].iterations)))
9254 return -ENOBUFS;
9255 nla_nest_end(msg, scan_plan);
9256 }
9257 nla_nest_end(msg, scan_plans);
9258
Luciano Coelho75453cc2015-01-09 14:06:37 +02009259 nla_nest_end(msg, nd);
9260
9261 return 0;
9262}
9263
Johannes Bergff1b6e62011-05-04 15:37:28 +02009264static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9265{
9266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9267 struct sk_buff *msg;
9268 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009269 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009270
Johannes Berg964dc9e2013-06-03 17:25:34 +02009271 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009272 return -EOPNOTSUPP;
9273
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009274 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009275 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009276 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9277 rdev->wiphy.wowlan_config->tcp->payload_len +
9278 rdev->wiphy.wowlan_config->tcp->wake_len +
9279 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009280 }
9281
9282 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009283 if (!msg)
9284 return -ENOMEM;
9285
Eric W. Biederman15e47302012-09-07 20:12:54 +00009286 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009287 NL80211_CMD_GET_WOWLAN);
9288 if (!hdr)
9289 goto nla_put_failure;
9290
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009291 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009292 struct nlattr *nl_wowlan;
9293
9294 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9295 if (!nl_wowlan)
9296 goto nla_put_failure;
9297
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009298 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009299 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009300 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009301 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009302 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009303 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009304 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009305 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009306 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009307 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009308 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009309 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009310 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009311 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9312 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009313
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009314 if (nl80211_send_wowlan_patterns(msg, rdev))
9315 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009316
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009317 if (nl80211_send_wowlan_tcp(msg,
9318 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009319 goto nla_put_failure;
9320
Luciano Coelho75453cc2015-01-09 14:06:37 +02009321 if (nl80211_send_wowlan_nd(
9322 msg,
9323 rdev->wiphy.wowlan_config->nd_config))
9324 goto nla_put_failure;
9325
Johannes Bergff1b6e62011-05-04 15:37:28 +02009326 nla_nest_end(msg, nl_wowlan);
9327 }
9328
9329 genlmsg_end(msg, hdr);
9330 return genlmsg_reply(msg, info);
9331
9332nla_put_failure:
9333 nlmsg_free(msg);
9334 return -ENOBUFS;
9335}
9336
Johannes Berg2a0e0472013-01-23 22:57:40 +01009337static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9338 struct nlattr *attr,
9339 struct cfg80211_wowlan *trig)
9340{
9341 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9342 struct cfg80211_wowlan_tcp *cfg;
9343 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9344 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9345 u32 size;
9346 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9347 int err, port;
9348
Johannes Berg964dc9e2013-06-03 17:25:34 +02009349 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009350 return -EINVAL;
9351
9352 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9353 nla_data(attr), nla_len(attr),
9354 nl80211_wowlan_tcp_policy);
9355 if (err)
9356 return err;
9357
9358 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9359 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9360 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9361 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9362 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9363 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9364 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9365 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9366 return -EINVAL;
9367
9368 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009369 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009370 return -EINVAL;
9371
9372 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009373 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009374 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009375 return -EINVAL;
9376
9377 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009378 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009379 return -EINVAL;
9380
9381 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9382 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9383 return -EINVAL;
9384
9385 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9386 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9387
9388 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9389 tokens_size = tokln - sizeof(*tok);
9390
9391 if (!tok->len || tokens_size % tok->len)
9392 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009393 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009394 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009395 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009396 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009397 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009398 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009399 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009400 return -EINVAL;
9401 if (tok->offset + tok->len > data_size)
9402 return -EINVAL;
9403 }
9404
9405 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9406 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009407 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009408 return -EINVAL;
9409 if (seq->len == 0 || seq->len > 4)
9410 return -EINVAL;
9411 if (seq->len + seq->offset > data_size)
9412 return -EINVAL;
9413 }
9414
9415 size = sizeof(*cfg);
9416 size += data_size;
9417 size += wake_size + wake_mask_size;
9418 size += tokens_size;
9419
9420 cfg = kzalloc(size, GFP_KERNEL);
9421 if (!cfg)
9422 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009423 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9424 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009425 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9426 ETH_ALEN);
9427 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9428 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9429 else
9430 port = 0;
9431#ifdef CONFIG_INET
9432 /* allocate a socket and port for it and use it */
9433 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9434 IPPROTO_TCP, &cfg->sock, 1);
9435 if (err) {
9436 kfree(cfg);
9437 return err;
9438 }
9439 if (inet_csk_get_port(cfg->sock->sk, port)) {
9440 sock_release(cfg->sock);
9441 kfree(cfg);
9442 return -EADDRINUSE;
9443 }
9444 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9445#else
9446 if (!port) {
9447 kfree(cfg);
9448 return -EINVAL;
9449 }
9450 cfg->src_port = port;
9451#endif
9452
9453 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9454 cfg->payload_len = data_size;
9455 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9456 memcpy((void *)cfg->payload,
9457 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9458 data_size);
9459 if (seq)
9460 cfg->payload_seq = *seq;
9461 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9462 cfg->wake_len = wake_size;
9463 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9464 memcpy((void *)cfg->wake_data,
9465 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9466 wake_size);
9467 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9468 data_size + wake_size;
9469 memcpy((void *)cfg->wake_mask,
9470 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9471 wake_mask_size);
9472 if (tok) {
9473 cfg->tokens_size = tokens_size;
9474 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9475 }
9476
9477 trig->tcp = cfg;
9478
9479 return 0;
9480}
9481
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009482static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9483 const struct wiphy_wowlan_support *wowlan,
9484 struct nlattr *attr,
9485 struct cfg80211_wowlan *trig)
9486{
9487 struct nlattr **tb;
9488 int err;
9489
9490 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9491 if (!tb)
9492 return -ENOMEM;
9493
9494 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9495 err = -EOPNOTSUPP;
9496 goto out;
9497 }
9498
9499 err = nla_parse(tb, NL80211_ATTR_MAX,
9500 nla_data(attr), nla_len(attr),
9501 nl80211_policy);
9502 if (err)
9503 goto out;
9504
Johannes Bergad2b26a2014-06-12 21:39:05 +02009505 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009506 err = PTR_ERR_OR_ZERO(trig->nd_config);
9507 if (err)
9508 trig->nd_config = NULL;
9509
9510out:
9511 kfree(tb);
9512 return err;
9513}
9514
Johannes Bergff1b6e62011-05-04 15:37:28 +02009515static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9516{
9517 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9518 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009519 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009520 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009521 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009522 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009523 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009524 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009525
Johannes Berg964dc9e2013-06-03 17:25:34 +02009526 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009527 return -EOPNOTSUPP;
9528
Johannes Bergae33bd82012-07-12 16:25:02 +02009529 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9530 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009531 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009532 goto set_wakeup;
9533 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009534
9535 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9536 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9537 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9538 nl80211_wowlan_policy);
9539 if (err)
9540 return err;
9541
9542 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9543 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9544 return -EINVAL;
9545 new_triggers.any = true;
9546 }
9547
9548 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9549 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9550 return -EINVAL;
9551 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009552 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009553 }
9554
9555 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9556 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9557 return -EINVAL;
9558 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009559 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009560 }
9561
Johannes Berg77dbbb12011-07-13 10:48:55 +02009562 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9563 return -EINVAL;
9564
9565 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9566 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9567 return -EINVAL;
9568 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009569 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009570 }
9571
9572 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9573 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9574 return -EINVAL;
9575 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009576 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009577 }
9578
9579 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9580 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9581 return -EINVAL;
9582 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009583 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009584 }
9585
9586 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9587 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9588 return -EINVAL;
9589 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009590 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009591 }
9592
Johannes Bergff1b6e62011-05-04 15:37:28 +02009593 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9594 struct nlattr *pat;
9595 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009596 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009597 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009598
Johannes Berg98fc4382015-03-01 09:10:13 +02009599 regular = true;
9600
Johannes Bergff1b6e62011-05-04 15:37:28 +02009601 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9602 rem)
9603 n_patterns++;
9604 if (n_patterns > wowlan->n_patterns)
9605 return -EINVAL;
9606
9607 new_triggers.patterns = kcalloc(n_patterns,
9608 sizeof(new_triggers.patterns[0]),
9609 GFP_KERNEL);
9610 if (!new_triggers.patterns)
9611 return -ENOMEM;
9612
9613 new_triggers.n_patterns = n_patterns;
9614 i = 0;
9615
9616 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9617 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009618 u8 *mask_pat;
9619
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009620 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9621 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009622 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009623 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9624 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009625 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009626 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009627 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009628 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009629 goto error;
9630 if (pat_len > wowlan->pattern_max_len ||
9631 pat_len < wowlan->pattern_min_len)
9632 goto error;
9633
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009634 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009635 pkt_offset = 0;
9636 else
9637 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009638 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009639 if (pkt_offset > wowlan->max_pkt_offset)
9640 goto error;
9641 new_triggers.patterns[i].pkt_offset = pkt_offset;
9642
Johannes Berg922bd802014-05-19 17:59:50 +02009643 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9644 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009645 err = -ENOMEM;
9646 goto error;
9647 }
Johannes Berg922bd802014-05-19 17:59:50 +02009648 new_triggers.patterns[i].mask = mask_pat;
9649 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009650 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009651 mask_pat += mask_len;
9652 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009653 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009654 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009655 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009656 pat_len);
9657 i++;
9658 }
9659 }
9660
Johannes Berg2a0e0472013-01-23 22:57:40 +01009661 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009662 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009663 err = nl80211_parse_wowlan_tcp(
9664 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9665 &new_triggers);
9666 if (err)
9667 goto error;
9668 }
9669
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009670 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009671 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009672 err = nl80211_parse_wowlan_nd(
9673 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9674 &new_triggers);
9675 if (err)
9676 goto error;
9677 }
9678
Johannes Berg98fc4382015-03-01 09:10:13 +02009679 /* The 'any' trigger means the device continues operating more or less
9680 * as in its normal operation mode and wakes up the host on most of the
9681 * normal interrupts (like packet RX, ...)
9682 * It therefore makes little sense to combine with the more constrained
9683 * wakeup trigger modes.
9684 */
9685 if (new_triggers.any && regular) {
9686 err = -EINVAL;
9687 goto error;
9688 }
9689
Johannes Bergae33bd82012-07-12 16:25:02 +02009690 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9691 if (!ntrig) {
9692 err = -ENOMEM;
9693 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009694 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009695 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009696 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009697
Johannes Bergae33bd82012-07-12 16:25:02 +02009698 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009699 if (rdev->ops->set_wakeup &&
9700 prev_enabled != !!rdev->wiphy.wowlan_config)
9701 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009702
Johannes Bergff1b6e62011-05-04 15:37:28 +02009703 return 0;
9704 error:
9705 for (i = 0; i < new_triggers.n_patterns; i++)
9706 kfree(new_triggers.patterns[i].mask);
9707 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009708 if (new_triggers.tcp && new_triggers.tcp->sock)
9709 sock_release(new_triggers.tcp->sock);
9710 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009711 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009712 return err;
9713}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009714#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009715
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009716static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9717 struct cfg80211_registered_device *rdev)
9718{
9719 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9720 int i, j, pat_len;
9721 struct cfg80211_coalesce_rules *rule;
9722
9723 if (!rdev->coalesce->n_rules)
9724 return 0;
9725
9726 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9727 if (!nl_rules)
9728 return -ENOBUFS;
9729
9730 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9731 nl_rule = nla_nest_start(msg, i + 1);
9732 if (!nl_rule)
9733 return -ENOBUFS;
9734
9735 rule = &rdev->coalesce->rules[i];
9736 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9737 rule->delay))
9738 return -ENOBUFS;
9739
9740 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9741 rule->condition))
9742 return -ENOBUFS;
9743
9744 nl_pats = nla_nest_start(msg,
9745 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9746 if (!nl_pats)
9747 return -ENOBUFS;
9748
9749 for (j = 0; j < rule->n_patterns; j++) {
9750 nl_pat = nla_nest_start(msg, j + 1);
9751 if (!nl_pat)
9752 return -ENOBUFS;
9753 pat_len = rule->patterns[j].pattern_len;
9754 if (nla_put(msg, NL80211_PKTPAT_MASK,
9755 DIV_ROUND_UP(pat_len, 8),
9756 rule->patterns[j].mask) ||
9757 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9758 rule->patterns[j].pattern) ||
9759 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9760 rule->patterns[j].pkt_offset))
9761 return -ENOBUFS;
9762 nla_nest_end(msg, nl_pat);
9763 }
9764 nla_nest_end(msg, nl_pats);
9765 nla_nest_end(msg, nl_rule);
9766 }
9767 nla_nest_end(msg, nl_rules);
9768
9769 return 0;
9770}
9771
9772static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9773{
9774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9775 struct sk_buff *msg;
9776 void *hdr;
9777
9778 if (!rdev->wiphy.coalesce)
9779 return -EOPNOTSUPP;
9780
9781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9782 if (!msg)
9783 return -ENOMEM;
9784
9785 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9786 NL80211_CMD_GET_COALESCE);
9787 if (!hdr)
9788 goto nla_put_failure;
9789
9790 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9791 goto nla_put_failure;
9792
9793 genlmsg_end(msg, hdr);
9794 return genlmsg_reply(msg, info);
9795
9796nla_put_failure:
9797 nlmsg_free(msg);
9798 return -ENOBUFS;
9799}
9800
9801void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9802{
9803 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9804 int i, j;
9805 struct cfg80211_coalesce_rules *rule;
9806
9807 if (!coalesce)
9808 return;
9809
9810 for (i = 0; i < coalesce->n_rules; i++) {
9811 rule = &coalesce->rules[i];
9812 for (j = 0; j < rule->n_patterns; j++)
9813 kfree(rule->patterns[j].mask);
9814 kfree(rule->patterns);
9815 }
9816 kfree(coalesce->rules);
9817 kfree(coalesce);
9818 rdev->coalesce = NULL;
9819}
9820
9821static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9822 struct nlattr *rule,
9823 struct cfg80211_coalesce_rules *new_rule)
9824{
9825 int err, i;
9826 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9827 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9828 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9829 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9830
9831 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9832 nla_len(rule), nl80211_coalesce_policy);
9833 if (err)
9834 return err;
9835
9836 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9837 new_rule->delay =
9838 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9839 if (new_rule->delay > coalesce->max_delay)
9840 return -EINVAL;
9841
9842 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9843 new_rule->condition =
9844 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9845 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9846 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9847 return -EINVAL;
9848
9849 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9850 return -EINVAL;
9851
9852 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9853 rem)
9854 n_patterns++;
9855 if (n_patterns > coalesce->n_patterns)
9856 return -EINVAL;
9857
9858 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9859 GFP_KERNEL);
9860 if (!new_rule->patterns)
9861 return -ENOMEM;
9862
9863 new_rule->n_patterns = n_patterns;
9864 i = 0;
9865
9866 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9867 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009868 u8 *mask_pat;
9869
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009870 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9871 nla_len(pat), NULL);
9872 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9873 !pat_tb[NL80211_PKTPAT_PATTERN])
9874 return -EINVAL;
9875 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9876 mask_len = DIV_ROUND_UP(pat_len, 8);
9877 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9878 return -EINVAL;
9879 if (pat_len > coalesce->pattern_max_len ||
9880 pat_len < coalesce->pattern_min_len)
9881 return -EINVAL;
9882
9883 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9884 pkt_offset = 0;
9885 else
9886 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9887 if (pkt_offset > coalesce->max_pkt_offset)
9888 return -EINVAL;
9889 new_rule->patterns[i].pkt_offset = pkt_offset;
9890
Johannes Berg922bd802014-05-19 17:59:50 +02009891 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9892 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009893 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009894
9895 new_rule->patterns[i].mask = mask_pat;
9896 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9897 mask_len);
9898
9899 mask_pat += mask_len;
9900 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009901 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009902 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9903 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009904 i++;
9905 }
9906
9907 return 0;
9908}
9909
9910static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9911{
9912 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9913 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9914 struct cfg80211_coalesce new_coalesce = {};
9915 struct cfg80211_coalesce *n_coalesce;
9916 int err, rem_rule, n_rules = 0, i, j;
9917 struct nlattr *rule;
9918 struct cfg80211_coalesce_rules *tmp_rule;
9919
9920 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9921 return -EOPNOTSUPP;
9922
9923 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9924 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +03009925 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009926 return 0;
9927 }
9928
9929 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9930 rem_rule)
9931 n_rules++;
9932 if (n_rules > coalesce->n_rules)
9933 return -EINVAL;
9934
9935 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9936 GFP_KERNEL);
9937 if (!new_coalesce.rules)
9938 return -ENOMEM;
9939
9940 new_coalesce.n_rules = n_rules;
9941 i = 0;
9942
9943 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9944 rem_rule) {
9945 err = nl80211_parse_coalesce_rule(rdev, rule,
9946 &new_coalesce.rules[i]);
9947 if (err)
9948 goto error;
9949
9950 i++;
9951 }
9952
Ilan Peera1056b12015-10-22 22:27:46 +03009953 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009954 if (err)
9955 goto error;
9956
9957 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9958 if (!n_coalesce) {
9959 err = -ENOMEM;
9960 goto error;
9961 }
9962 cfg80211_rdev_free_coalesce(rdev);
9963 rdev->coalesce = n_coalesce;
9964
9965 return 0;
9966error:
9967 for (i = 0; i < new_coalesce.n_rules; i++) {
9968 tmp_rule = &new_coalesce.rules[i];
9969 for (j = 0; j < tmp_rule->n_patterns; j++)
9970 kfree(tmp_rule->patterns[j].mask);
9971 kfree(tmp_rule->patterns);
9972 }
9973 kfree(new_coalesce.rules);
9974
9975 return err;
9976}
9977
Johannes Berge5497d72011-07-05 16:35:40 +02009978static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9979{
9980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9981 struct net_device *dev = info->user_ptr[1];
9982 struct wireless_dev *wdev = dev->ieee80211_ptr;
9983 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9984 struct cfg80211_gtk_rekey_data rekey_data;
9985 int err;
9986
9987 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9988 return -EINVAL;
9989
9990 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9991 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9992 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9993 nl80211_rekey_policy);
9994 if (err)
9995 return err;
9996
9997 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9998 return -ERANGE;
9999 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10000 return -ERANGE;
10001 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10002 return -ERANGE;
10003
Johannes Berg78f686c2014-09-10 22:28:06 +030010004 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10005 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10006 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010007
10008 wdev_lock(wdev);
10009 if (!wdev->current_bss) {
10010 err = -ENOTCONN;
10011 goto out;
10012 }
10013
10014 if (!rdev->ops->set_rekey_data) {
10015 err = -EOPNOTSUPP;
10016 goto out;
10017 }
10018
Hila Gonene35e4d22012-06-27 17:19:42 +030010019 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010020 out:
10021 wdev_unlock(wdev);
10022 return err;
10023}
10024
Johannes Berg28946da2011-11-04 11:18:12 +010010025static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10026 struct genl_info *info)
10027{
10028 struct net_device *dev = info->user_ptr[1];
10029 struct wireless_dev *wdev = dev->ieee80211_ptr;
10030
10031 if (wdev->iftype != NL80211_IFTYPE_AP &&
10032 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10033 return -EINVAL;
10034
Eric W. Biederman15e47302012-09-07 20:12:54 +000010035 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010036 return -EBUSY;
10037
Eric W. Biederman15e47302012-09-07 20:12:54 +000010038 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010039 return 0;
10040}
10041
Johannes Berg7f6cf312011-11-04 11:18:15 +010010042static int nl80211_probe_client(struct sk_buff *skb,
10043 struct genl_info *info)
10044{
10045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10046 struct net_device *dev = info->user_ptr[1];
10047 struct wireless_dev *wdev = dev->ieee80211_ptr;
10048 struct sk_buff *msg;
10049 void *hdr;
10050 const u8 *addr;
10051 u64 cookie;
10052 int err;
10053
10054 if (wdev->iftype != NL80211_IFTYPE_AP &&
10055 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10056 return -EOPNOTSUPP;
10057
10058 if (!info->attrs[NL80211_ATTR_MAC])
10059 return -EINVAL;
10060
10061 if (!rdev->ops->probe_client)
10062 return -EOPNOTSUPP;
10063
10064 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10065 if (!msg)
10066 return -ENOMEM;
10067
Eric W. Biederman15e47302012-09-07 20:12:54 +000010068 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010069 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010070 if (!hdr) {
10071 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010072 goto free_msg;
10073 }
10074
10075 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10076
Hila Gonene35e4d22012-06-27 17:19:42 +030010077 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010078 if (err)
10079 goto free_msg;
10080
David S. Miller9360ffd2012-03-29 04:41:26 -040010081 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10082 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010083
10084 genlmsg_end(msg, hdr);
10085
10086 return genlmsg_reply(msg, info);
10087
10088 nla_put_failure:
10089 err = -ENOBUFS;
10090 free_msg:
10091 nlmsg_free(msg);
10092 return err;
10093}
10094
Johannes Berg5e760232011-11-04 11:18:17 +010010095static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10096{
10097 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010098 struct cfg80211_beacon_registration *reg, *nreg;
10099 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010100
10101 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10102 return -EOPNOTSUPP;
10103
Ben Greear37c73b52012-10-26 14:49:25 -070010104 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10105 if (!nreg)
10106 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010010107
Ben Greear37c73b52012-10-26 14:49:25 -070010108 /* First, check if already registered. */
10109 spin_lock_bh(&rdev->beacon_registrations_lock);
10110 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10111 if (reg->nlportid == info->snd_portid) {
10112 rv = -EALREADY;
10113 goto out_err;
10114 }
10115 }
10116 /* Add it to the list */
10117 nreg->nlportid = info->snd_portid;
10118 list_add(&nreg->list, &rdev->beacon_registrations);
10119
10120 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010121
10122 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010123out_err:
10124 spin_unlock_bh(&rdev->beacon_registrations_lock);
10125 kfree(nreg);
10126 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010127}
10128
Johannes Berg98104fde2012-06-16 00:19:54 +020010129static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10130{
10131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10132 struct wireless_dev *wdev = info->user_ptr[1];
10133 int err;
10134
10135 if (!rdev->ops->start_p2p_device)
10136 return -EOPNOTSUPP;
10137
10138 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10139 return -EOPNOTSUPP;
10140
10141 if (wdev->p2p_started)
10142 return 0;
10143
Luciano Coelhob6a55012014-02-27 11:07:21 +020010144 if (rfkill_blocked(rdev->rfkill))
10145 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010146
Johannes Bergeeb126e2012-10-23 15:16:50 +020010147 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010148 if (err)
10149 return err;
10150
10151 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010152 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010153
10154 return 0;
10155}
10156
10157static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10158{
10159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10160 struct wireless_dev *wdev = info->user_ptr[1];
10161
10162 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10163 return -EOPNOTSUPP;
10164
10165 if (!rdev->ops->stop_p2p_device)
10166 return -EOPNOTSUPP;
10167
Johannes Bergf9f47522013-03-19 15:04:07 +010010168 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010169
10170 return 0;
10171}
10172
Johannes Berg3713b4e2013-02-14 16:19:38 +010010173static int nl80211_get_protocol_features(struct sk_buff *skb,
10174 struct genl_info *info)
10175{
10176 void *hdr;
10177 struct sk_buff *msg;
10178
10179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10180 if (!msg)
10181 return -ENOMEM;
10182
10183 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10184 NL80211_CMD_GET_PROTOCOL_FEATURES);
10185 if (!hdr)
10186 goto nla_put_failure;
10187
10188 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10189 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10190 goto nla_put_failure;
10191
10192 genlmsg_end(msg, hdr);
10193 return genlmsg_reply(msg, info);
10194
10195 nla_put_failure:
10196 kfree_skb(msg);
10197 return -ENOBUFS;
10198}
10199
Jouni Malinen355199e2013-02-27 17:14:27 +020010200static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10201{
10202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10203 struct cfg80211_update_ft_ies_params ft_params;
10204 struct net_device *dev = info->user_ptr[1];
10205
10206 if (!rdev->ops->update_ft_ies)
10207 return -EOPNOTSUPP;
10208
10209 if (!info->attrs[NL80211_ATTR_MDID] ||
10210 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10211 return -EINVAL;
10212
10213 memset(&ft_params, 0, sizeof(ft_params));
10214 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10215 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10216 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10217
10218 return rdev_update_ft_ies(rdev, dev, &ft_params);
10219}
10220
Arend van Spriel5de17982013-04-18 15:49:00 +020010221static int nl80211_crit_protocol_start(struct sk_buff *skb,
10222 struct genl_info *info)
10223{
10224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10225 struct wireless_dev *wdev = info->user_ptr[1];
10226 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10227 u16 duration;
10228 int ret;
10229
10230 if (!rdev->ops->crit_proto_start)
10231 return -EOPNOTSUPP;
10232
10233 if (WARN_ON(!rdev->ops->crit_proto_stop))
10234 return -EINVAL;
10235
10236 if (rdev->crit_proto_nlportid)
10237 return -EBUSY;
10238
10239 /* determine protocol if provided */
10240 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10241 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10242
10243 if (proto >= NUM_NL80211_CRIT_PROTO)
10244 return -EINVAL;
10245
10246 /* timeout must be provided */
10247 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10248 return -EINVAL;
10249
10250 duration =
10251 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10252
10253 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10254 return -ERANGE;
10255
10256 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10257 if (!ret)
10258 rdev->crit_proto_nlportid = info->snd_portid;
10259
10260 return ret;
10261}
10262
10263static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10264 struct genl_info *info)
10265{
10266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10267 struct wireless_dev *wdev = info->user_ptr[1];
10268
10269 if (!rdev->ops->crit_proto_stop)
10270 return -EOPNOTSUPP;
10271
10272 if (rdev->crit_proto_nlportid) {
10273 rdev->crit_proto_nlportid = 0;
10274 rdev_crit_proto_stop(rdev, wdev);
10275 }
10276 return 0;
10277}
10278
Johannes Bergad7e7182013-11-13 13:37:47 +010010279static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10280{
10281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10282 struct wireless_dev *wdev =
10283 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10284 int i, err;
10285 u32 vid, subcmd;
10286
10287 if (!rdev->wiphy.vendor_commands)
10288 return -EOPNOTSUPP;
10289
10290 if (IS_ERR(wdev)) {
10291 err = PTR_ERR(wdev);
10292 if (err != -EINVAL)
10293 return err;
10294 wdev = NULL;
10295 } else if (wdev->wiphy != &rdev->wiphy) {
10296 return -EINVAL;
10297 }
10298
10299 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10300 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10301 return -EINVAL;
10302
10303 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10304 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10305 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10306 const struct wiphy_vendor_command *vcmd;
10307 void *data = NULL;
10308 int len = 0;
10309
10310 vcmd = &rdev->wiphy.vendor_commands[i];
10311
10312 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10313 continue;
10314
10315 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10316 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10317 if (!wdev)
10318 return -EINVAL;
10319 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10320 !wdev->netdev)
10321 return -EINVAL;
10322
10323 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10324 if (wdev->netdev &&
10325 !netif_running(wdev->netdev))
10326 return -ENETDOWN;
10327 if (!wdev->netdev && !wdev->p2p_started)
10328 return -ENETDOWN;
10329 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010330
10331 if (!vcmd->doit)
10332 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010333 } else {
10334 wdev = NULL;
10335 }
10336
10337 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10338 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10339 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10340 }
10341
10342 rdev->cur_cmd_info = info;
10343 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10344 data, len);
10345 rdev->cur_cmd_info = NULL;
10346 return err;
10347 }
10348
10349 return -EOPNOTSUPP;
10350}
10351
Johannes Berg7bdbe402015-08-15 22:39:49 +030010352static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10353 struct netlink_callback *cb,
10354 struct cfg80211_registered_device **rdev,
10355 struct wireless_dev **wdev)
10356{
10357 u32 vid, subcmd;
10358 unsigned int i;
10359 int vcmd_idx = -1;
10360 int err;
10361 void *data = NULL;
10362 unsigned int data_len = 0;
10363
10364 rtnl_lock();
10365
10366 if (cb->args[0]) {
10367 /* subtract the 1 again here */
10368 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10369 struct wireless_dev *tmp;
10370
10371 if (!wiphy) {
10372 err = -ENODEV;
10373 goto out_unlock;
10374 }
10375 *rdev = wiphy_to_rdev(wiphy);
10376 *wdev = NULL;
10377
10378 if (cb->args[1]) {
10379 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10380 if (tmp->identifier == cb->args[1] - 1) {
10381 *wdev = tmp;
10382 break;
10383 }
10384 }
10385 }
10386
10387 /* keep rtnl locked in successful case */
10388 return 0;
10389 }
10390
10391 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10392 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10393 nl80211_policy);
10394 if (err)
10395 goto out_unlock;
10396
10397 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10398 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10399 err = -EINVAL;
10400 goto out_unlock;
10401 }
10402
10403 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10404 nl80211_fam.attrbuf);
10405 if (IS_ERR(*wdev))
10406 *wdev = NULL;
10407
10408 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10409 nl80211_fam.attrbuf);
10410 if (IS_ERR(*rdev)) {
10411 err = PTR_ERR(*rdev);
10412 goto out_unlock;
10413 }
10414
10415 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10416 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10417
10418 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10419 const struct wiphy_vendor_command *vcmd;
10420
10421 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10422
10423 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10424 continue;
10425
10426 if (!vcmd->dumpit) {
10427 err = -EOPNOTSUPP;
10428 goto out_unlock;
10429 }
10430
10431 vcmd_idx = i;
10432 break;
10433 }
10434
10435 if (vcmd_idx < 0) {
10436 err = -EOPNOTSUPP;
10437 goto out_unlock;
10438 }
10439
10440 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10441 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10442 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10443 }
10444
10445 /* 0 is the first index - add 1 to parse only once */
10446 cb->args[0] = (*rdev)->wiphy_idx + 1;
10447 /* add 1 to know if it was NULL */
10448 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10449 cb->args[2] = vcmd_idx;
10450 cb->args[3] = (unsigned long)data;
10451 cb->args[4] = data_len;
10452
10453 /* keep rtnl locked in successful case */
10454 return 0;
10455 out_unlock:
10456 rtnl_unlock();
10457 return err;
10458}
10459
10460static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10461 struct netlink_callback *cb)
10462{
10463 struct cfg80211_registered_device *rdev;
10464 struct wireless_dev *wdev;
10465 unsigned int vcmd_idx;
10466 const struct wiphy_vendor_command *vcmd;
10467 void *data;
10468 int data_len;
10469 int err;
10470 struct nlattr *vendor_data;
10471
10472 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10473 if (err)
10474 return err;
10475
10476 vcmd_idx = cb->args[2];
10477 data = (void *)cb->args[3];
10478 data_len = cb->args[4];
10479 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10480
10481 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10482 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10483 if (!wdev)
10484 return -EINVAL;
10485 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10486 !wdev->netdev)
10487 return -EINVAL;
10488
10489 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10490 if (wdev->netdev &&
10491 !netif_running(wdev->netdev))
10492 return -ENETDOWN;
10493 if (!wdev->netdev && !wdev->p2p_started)
10494 return -ENETDOWN;
10495 }
10496 }
10497
10498 while (1) {
10499 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10500 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10501 NL80211_CMD_VENDOR);
10502 if (!hdr)
10503 break;
10504
10505 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10506 (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV,
10507 wdev_id(wdev)))) {
10508 genlmsg_cancel(skb, hdr);
10509 break;
10510 }
10511
10512 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10513 if (!vendor_data) {
10514 genlmsg_cancel(skb, hdr);
10515 break;
10516 }
10517
10518 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10519 (unsigned long *)&cb->args[5]);
10520 nla_nest_end(skb, vendor_data);
10521
10522 if (err == -ENOBUFS || err == -ENOENT) {
10523 genlmsg_cancel(skb, hdr);
10524 break;
10525 } else if (err) {
10526 genlmsg_cancel(skb, hdr);
10527 goto out;
10528 }
10529
10530 genlmsg_end(skb, hdr);
10531 }
10532
10533 err = skb->len;
10534 out:
10535 rtnl_unlock();
10536 return err;
10537}
10538
Johannes Bergad7e7182013-11-13 13:37:47 +010010539struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10540 enum nl80211_commands cmd,
10541 enum nl80211_attrs attr,
10542 int approxlen)
10543{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010544 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010545
10546 if (WARN_ON(!rdev->cur_cmd_info))
10547 return NULL;
10548
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010549 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010550 rdev->cur_cmd_info->snd_portid,
10551 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010552 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010553}
10554EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10555
10556int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10557{
10558 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10559 void *hdr = ((void **)skb->cb)[1];
10560 struct nlattr *data = ((void **)skb->cb)[2];
10561
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010562 /* clear CB data for netlink core to own from now on */
10563 memset(skb->cb, 0, sizeof(skb->cb));
10564
Johannes Bergad7e7182013-11-13 13:37:47 +010010565 if (WARN_ON(!rdev->cur_cmd_info)) {
10566 kfree_skb(skb);
10567 return -EINVAL;
10568 }
10569
10570 nla_nest_end(skb, data);
10571 genlmsg_end(skb, hdr);
10572 return genlmsg_reply(skb, rdev->cur_cmd_info);
10573}
10574EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10575
10576
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010577static int nl80211_set_qos_map(struct sk_buff *skb,
10578 struct genl_info *info)
10579{
10580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10581 struct cfg80211_qos_map *qos_map = NULL;
10582 struct net_device *dev = info->user_ptr[1];
10583 u8 *pos, len, num_des, des_len, des;
10584 int ret;
10585
10586 if (!rdev->ops->set_qos_map)
10587 return -EOPNOTSUPP;
10588
10589 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10590 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10591 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10592
10593 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10594 len > IEEE80211_QOS_MAP_LEN_MAX)
10595 return -EINVAL;
10596
10597 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10598 if (!qos_map)
10599 return -ENOMEM;
10600
10601 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10602 if (num_des) {
10603 des_len = num_des *
10604 sizeof(struct cfg80211_dscp_exception);
10605 memcpy(qos_map->dscp_exception, pos, des_len);
10606 qos_map->num_des = num_des;
10607 for (des = 0; des < num_des; des++) {
10608 if (qos_map->dscp_exception[des].up > 7) {
10609 kfree(qos_map);
10610 return -EINVAL;
10611 }
10612 }
10613 pos += des_len;
10614 }
10615 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10616 }
10617
10618 wdev_lock(dev->ieee80211_ptr);
10619 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10620 if (!ret)
10621 ret = rdev_set_qos_map(rdev, dev, qos_map);
10622 wdev_unlock(dev->ieee80211_ptr);
10623
10624 kfree(qos_map);
10625 return ret;
10626}
10627
Johannes Berg960d01a2014-09-09 22:55:35 +030010628static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10629{
10630 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10631 struct net_device *dev = info->user_ptr[1];
10632 struct wireless_dev *wdev = dev->ieee80211_ptr;
10633 const u8 *peer;
10634 u8 tsid, up;
10635 u16 admitted_time = 0;
10636 int err;
10637
Johannes Berg723e73a2014-10-22 09:25:06 +020010638 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010639 return -EOPNOTSUPP;
10640
10641 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10642 !info->attrs[NL80211_ATTR_USER_PRIO])
10643 return -EINVAL;
10644
10645 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10646 if (tsid >= IEEE80211_NUM_TIDS)
10647 return -EINVAL;
10648
10649 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10650 if (up >= IEEE80211_NUM_UPS)
10651 return -EINVAL;
10652
10653 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010654 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010655 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010656 * need more attributes for that (e.g. BA session requirement);
10657 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010658 */
10659 return -EINVAL;
10660 }
10661
10662 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10663
10664 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10665 admitted_time =
10666 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10667 if (!admitted_time)
10668 return -EINVAL;
10669 }
10670
10671 wdev_lock(wdev);
10672 switch (wdev->iftype) {
10673 case NL80211_IFTYPE_STATION:
10674 case NL80211_IFTYPE_P2P_CLIENT:
10675 if (wdev->current_bss)
10676 break;
10677 err = -ENOTCONN;
10678 goto out;
10679 default:
10680 err = -EOPNOTSUPP;
10681 goto out;
10682 }
10683
10684 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10685
10686 out:
10687 wdev_unlock(wdev);
10688 return err;
10689}
10690
10691static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10692{
10693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10694 struct net_device *dev = info->user_ptr[1];
10695 struct wireless_dev *wdev = dev->ieee80211_ptr;
10696 const u8 *peer;
10697 u8 tsid;
10698 int err;
10699
10700 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10701 return -EINVAL;
10702
10703 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10704 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10705
10706 wdev_lock(wdev);
10707 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10708 wdev_unlock(wdev);
10709
10710 return err;
10711}
10712
Arik Nemtsov1057d352014-11-19 12:54:26 +020010713static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10714 struct genl_info *info)
10715{
10716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10717 struct net_device *dev = info->user_ptr[1];
10718 struct wireless_dev *wdev = dev->ieee80211_ptr;
10719 struct cfg80211_chan_def chandef = {};
10720 const u8 *addr;
10721 u8 oper_class;
10722 int err;
10723
10724 if (!rdev->ops->tdls_channel_switch ||
10725 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10726 return -EOPNOTSUPP;
10727
10728 switch (dev->ieee80211_ptr->iftype) {
10729 case NL80211_IFTYPE_STATION:
10730 case NL80211_IFTYPE_P2P_CLIENT:
10731 break;
10732 default:
10733 return -EOPNOTSUPP;
10734 }
10735
10736 if (!info->attrs[NL80211_ATTR_MAC] ||
10737 !info->attrs[NL80211_ATTR_OPER_CLASS])
10738 return -EINVAL;
10739
10740 err = nl80211_parse_chandef(rdev, info, &chandef);
10741 if (err)
10742 return err;
10743
10744 /*
10745 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10746 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10747 * specification is not defined for them.
10748 */
10749 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10750 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10751 chandef.width != NL80211_CHAN_WIDTH_20)
10752 return -EINVAL;
10753
10754 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010755 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10756 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010757 return -EINVAL;
10758
10759 /* don't allow switching to DFS channels */
10760 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10761 return -EINVAL;
10762
10763 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10764 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10765
10766 wdev_lock(wdev);
10767 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10768 wdev_unlock(wdev);
10769
10770 return err;
10771}
10772
10773static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10774 struct genl_info *info)
10775{
10776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10777 struct net_device *dev = info->user_ptr[1];
10778 struct wireless_dev *wdev = dev->ieee80211_ptr;
10779 const u8 *addr;
10780
10781 if (!rdev->ops->tdls_channel_switch ||
10782 !rdev->ops->tdls_cancel_channel_switch ||
10783 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10784 return -EOPNOTSUPP;
10785
10786 switch (dev->ieee80211_ptr->iftype) {
10787 case NL80211_IFTYPE_STATION:
10788 case NL80211_IFTYPE_P2P_CLIENT:
10789 break;
10790 default:
10791 return -EOPNOTSUPP;
10792 }
10793
10794 if (!info->attrs[NL80211_ATTR_MAC])
10795 return -EINVAL;
10796
10797 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10798
10799 wdev_lock(wdev);
10800 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10801 wdev_unlock(wdev);
10802
10803 return 0;
10804}
10805
Johannes Berg4c476992010-10-04 21:36:35 +020010806#define NL80211_FLAG_NEED_WIPHY 0x01
10807#define NL80211_FLAG_NEED_NETDEV 0x02
10808#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010809#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10810#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10811 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010812#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010813/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010814#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10815 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010816#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010817
Johannes Bergf84f7712013-11-14 17:14:45 +010010818static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010819 struct genl_info *info)
10820{
10821 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010822 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010823 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010824 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10825
10826 if (rtnl)
10827 rtnl_lock();
10828
10829 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010830 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010831 if (IS_ERR(rdev)) {
10832 if (rtnl)
10833 rtnl_unlock();
10834 return PTR_ERR(rdev);
10835 }
10836 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010837 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10838 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010839 ASSERT_RTNL();
10840
Johannes Berg89a54e42012-06-15 14:33:17 +020010841 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10842 info->attrs);
10843 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010844 if (rtnl)
10845 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010846 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010847 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010848
Johannes Berg89a54e42012-06-15 14:33:17 +020010849 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010850 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010851
Johannes Berg1bf614e2012-06-15 15:23:36 +020010852 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10853 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010854 if (rtnl)
10855 rtnl_unlock();
10856 return -EINVAL;
10857 }
10858
10859 info->user_ptr[1] = dev;
10860 } else {
10861 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010862 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010863
Johannes Berg1bf614e2012-06-15 15:23:36 +020010864 if (dev) {
10865 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10866 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010867 if (rtnl)
10868 rtnl_unlock();
10869 return -ENETDOWN;
10870 }
10871
10872 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010873 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10874 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010875 if (rtnl)
10876 rtnl_unlock();
10877 return -ENETDOWN;
10878 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010879 }
10880
Johannes Berg4c476992010-10-04 21:36:35 +020010881 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010882 }
10883
10884 return 0;
10885}
10886
Johannes Bergf84f7712013-11-14 17:14:45 +010010887static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010888 struct genl_info *info)
10889{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010890 if (info->user_ptr[1]) {
10891 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10892 struct wireless_dev *wdev = info->user_ptr[1];
10893
10894 if (wdev->netdev)
10895 dev_put(wdev->netdev);
10896 } else {
10897 dev_put(info->user_ptr[1]);
10898 }
10899 }
Johannes Berg5393b912014-09-10 15:00:16 +030010900
Johannes Berg4c476992010-10-04 21:36:35 +020010901 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10902 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010903
10904 /* If needed, clear the netlink message payload from the SKB
10905 * as it might contain key data that shouldn't stick around on
10906 * the heap after the SKB is freed. The netlink message header
10907 * is still needed for further processing, so leave it intact.
10908 */
10909 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10910 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10911
10912 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10913 }
Johannes Berg4c476992010-10-04 21:36:35 +020010914}
10915
Johannes Berg4534de82013-11-14 17:14:46 +010010916static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010917 {
10918 .cmd = NL80211_CMD_GET_WIPHY,
10919 .doit = nl80211_get_wiphy,
10920 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010921 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010922 .policy = nl80211_policy,
10923 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010924 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10925 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010926 },
10927 {
10928 .cmd = NL80211_CMD_SET_WIPHY,
10929 .doit = nl80211_set_wiphy,
10930 .policy = nl80211_policy,
10931 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010932 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010933 },
10934 {
10935 .cmd = NL80211_CMD_GET_INTERFACE,
10936 .doit = nl80211_get_interface,
10937 .dumpit = nl80211_dump_interface,
10938 .policy = nl80211_policy,
10939 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010940 .internal_flags = NL80211_FLAG_NEED_WDEV |
10941 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010942 },
10943 {
10944 .cmd = NL80211_CMD_SET_INTERFACE,
10945 .doit = nl80211_set_interface,
10946 .policy = nl80211_policy,
10947 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010948 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10949 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010950 },
10951 {
10952 .cmd = NL80211_CMD_NEW_INTERFACE,
10953 .doit = nl80211_new_interface,
10954 .policy = nl80211_policy,
10955 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010956 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10957 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010958 },
10959 {
10960 .cmd = NL80211_CMD_DEL_INTERFACE,
10961 .doit = nl80211_del_interface,
10962 .policy = nl80211_policy,
10963 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010964 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010965 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010966 },
Johannes Berg41ade002007-12-19 02:03:29 +010010967 {
10968 .cmd = NL80211_CMD_GET_KEY,
10969 .doit = nl80211_get_key,
10970 .policy = nl80211_policy,
10971 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010972 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010973 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010974 },
10975 {
10976 .cmd = NL80211_CMD_SET_KEY,
10977 .doit = nl80211_set_key,
10978 .policy = nl80211_policy,
10979 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010981 NL80211_FLAG_NEED_RTNL |
10982 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010983 },
10984 {
10985 .cmd = NL80211_CMD_NEW_KEY,
10986 .doit = nl80211_new_key,
10987 .policy = nl80211_policy,
10988 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010989 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010990 NL80211_FLAG_NEED_RTNL |
10991 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010992 },
10993 {
10994 .cmd = NL80211_CMD_DEL_KEY,
10995 .doit = nl80211_del_key,
10996 .policy = nl80211_policy,
10997 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010998 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010999 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011000 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011001 {
11002 .cmd = NL80211_CMD_SET_BEACON,
11003 .policy = nl80211_policy,
11004 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011005 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011006 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011007 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011008 },
11009 {
Johannes Berg88600202012-02-13 15:17:18 +010011010 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011011 .policy = nl80211_policy,
11012 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011013 .doit = nl80211_start_ap,
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_STOP_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_stop_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 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011025 {
11026 .cmd = NL80211_CMD_GET_STATION,
11027 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011028 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011029 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011030 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11031 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011032 },
11033 {
11034 .cmd = NL80211_CMD_SET_STATION,
11035 .doit = nl80211_set_station,
11036 .policy = nl80211_policy,
11037 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011038 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011039 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011040 },
11041 {
11042 .cmd = NL80211_CMD_NEW_STATION,
11043 .doit = nl80211_new_station,
11044 .policy = nl80211_policy,
11045 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +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_DEL_STATION,
11051 .doit = nl80211_del_station,
11052 .policy = nl80211_policy,
11053 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +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 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011057 {
11058 .cmd = NL80211_CMD_GET_MPATH,
11059 .doit = nl80211_get_mpath,
11060 .dumpit = nl80211_dump_mpath,
11061 .policy = nl80211_policy,
11062 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011064 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011065 },
11066 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011067 .cmd = NL80211_CMD_GET_MPP,
11068 .doit = nl80211_get_mpp,
11069 .dumpit = nl80211_dump_mpp,
11070 .policy = nl80211_policy,
11071 .flags = GENL_ADMIN_PERM,
11072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11073 NL80211_FLAG_NEED_RTNL,
11074 },
11075 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011076 .cmd = NL80211_CMD_SET_MPATH,
11077 .doit = nl80211_set_mpath,
11078 .policy = nl80211_policy,
11079 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011080 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011081 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011082 },
11083 {
11084 .cmd = NL80211_CMD_NEW_MPATH,
11085 .doit = nl80211_new_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_DEL_MPATH,
11093 .doit = nl80211_del_mpath,
11094 .policy = nl80211_policy,
11095 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011097 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011098 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011099 {
11100 .cmd = NL80211_CMD_SET_BSS,
11101 .doit = nl80211_set_bss,
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,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011106 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011107 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011108 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011109 .doit = nl80211_get_reg_do,
11110 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011111 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011112 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011113 /* can be retrieved by unprivileged users */
11114 },
Johannes Bergb6863032015-10-15 09:25:18 +020011115#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011116 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011117 .cmd = NL80211_CMD_SET_REG,
11118 .doit = nl80211_set_reg,
11119 .policy = nl80211_policy,
11120 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011121 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011122 },
Johannes Bergb6863032015-10-15 09:25:18 +020011123#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011124 {
11125 .cmd = NL80211_CMD_REQ_SET_REG,
11126 .doit = nl80211_req_set_reg,
11127 .policy = nl80211_policy,
11128 .flags = GENL_ADMIN_PERM,
11129 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011130 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011131 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11132 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011133 .policy = nl80211_policy,
11134 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011135 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011136 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011137 },
11138 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011139 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11140 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011141 .policy = nl80211_policy,
11142 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011143 .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 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011146 {
Johannes Berg2a519312009-02-10 21:25:55 +010011147 .cmd = NL80211_CMD_TRIGGER_SCAN,
11148 .doit = nl80211_trigger_scan,
11149 .policy = nl80211_policy,
11150 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011151 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011152 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011153 },
11154 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011155 .cmd = NL80211_CMD_ABORT_SCAN,
11156 .doit = nl80211_abort_scan,
11157 .policy = nl80211_policy,
11158 .flags = GENL_ADMIN_PERM,
11159 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11160 NL80211_FLAG_NEED_RTNL,
11161 },
11162 {
Johannes Berg2a519312009-02-10 21:25:55 +010011163 .cmd = NL80211_CMD_GET_SCAN,
11164 .policy = nl80211_policy,
11165 .dumpit = nl80211_dump_scan,
11166 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011167 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011168 .cmd = NL80211_CMD_START_SCHED_SCAN,
11169 .doit = nl80211_start_sched_scan,
11170 .policy = nl80211_policy,
11171 .flags = GENL_ADMIN_PERM,
11172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11173 NL80211_FLAG_NEED_RTNL,
11174 },
11175 {
11176 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11177 .doit = nl80211_stop_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 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011184 .cmd = NL80211_CMD_AUTHENTICATE,
11185 .doit = nl80211_authenticate,
11186 .policy = nl80211_policy,
11187 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011188 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011189 NL80211_FLAG_NEED_RTNL |
11190 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011191 },
11192 {
11193 .cmd = NL80211_CMD_ASSOCIATE,
11194 .doit = nl80211_associate,
11195 .policy = nl80211_policy,
11196 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011197 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011198 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011199 },
11200 {
11201 .cmd = NL80211_CMD_DEAUTHENTICATE,
11202 .doit = nl80211_deauthenticate,
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_DISASSOCIATE,
11210 .doit = nl80211_disassociate,
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 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011216 {
11217 .cmd = NL80211_CMD_JOIN_IBSS,
11218 .doit = nl80211_join_ibss,
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,
Johannes Berg04a773a2009-04-19 21:24:32 +020011223 },
11224 {
11225 .cmd = NL80211_CMD_LEAVE_IBSS,
11226 .doit = nl80211_leave_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 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011232#ifdef CONFIG_NL80211_TESTMODE
11233 {
11234 .cmd = NL80211_CMD_TESTMODE,
11235 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011236 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011237 .policy = nl80211_policy,
11238 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011239 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11240 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011241 },
11242#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011243 {
11244 .cmd = NL80211_CMD_CONNECT,
11245 .doit = nl80211_connect,
11246 .policy = nl80211_policy,
11247 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011248 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011249 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011250 },
11251 {
11252 .cmd = NL80211_CMD_DISCONNECT,
11253 .doit = nl80211_disconnect,
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 },
Johannes Berg463d0182009-07-14 00:33:35 +020011259 {
11260 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11261 .doit = nl80211_wiphy_netns,
11262 .policy = nl80211_policy,
11263 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011264 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11265 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011266 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011267 {
11268 .cmd = NL80211_CMD_GET_SURVEY,
11269 .policy = nl80211_policy,
11270 .dumpit = nl80211_dump_survey,
11271 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011272 {
11273 .cmd = NL80211_CMD_SET_PMKSA,
11274 .doit = nl80211_setdel_pmksa,
11275 .policy = nl80211_policy,
11276 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011277 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011278 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011279 },
11280 {
11281 .cmd = NL80211_CMD_DEL_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_FLUSH_PMKSA,
11290 .doit = nl80211_flush_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 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011296 {
11297 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11298 .doit = nl80211_remain_on_channel,
11299 .policy = nl80211_policy,
11300 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011301 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011302 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011303 },
11304 {
11305 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11306 .doit = nl80211_cancel_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 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011312 {
11313 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11314 .doit = nl80211_set_tx_bitrate_mask,
11315 .policy = nl80211_policy,
11316 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011317 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11318 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011319 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011320 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011321 .cmd = NL80211_CMD_REGISTER_FRAME,
11322 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011323 .policy = nl80211_policy,
11324 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011325 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011326 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011327 },
11328 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011329 .cmd = NL80211_CMD_FRAME,
11330 .doit = nl80211_tx_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_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011334 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011335 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011336 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011337 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11338 .doit = nl80211_tx_mgmt_cancel_wait,
11339 .policy = nl80211_policy,
11340 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011341 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011342 NL80211_FLAG_NEED_RTNL,
11343 },
11344 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011345 .cmd = NL80211_CMD_SET_POWER_SAVE,
11346 .doit = nl80211_set_power_save,
11347 .policy = nl80211_policy,
11348 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011349 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11350 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011351 },
11352 {
11353 .cmd = NL80211_CMD_GET_POWER_SAVE,
11354 .doit = nl80211_get_power_save,
11355 .policy = nl80211_policy,
11356 /* can be retrieved by unprivileged users */
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 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011360 {
11361 .cmd = NL80211_CMD_SET_CQM,
11362 .doit = nl80211_set_cqm,
11363 .policy = nl80211_policy,
11364 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011365 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11366 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011367 },
Johannes Bergf444de02010-05-05 15:25:02 +020011368 {
11369 .cmd = NL80211_CMD_SET_CHANNEL,
11370 .doit = nl80211_set_channel,
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,
Johannes Bergf444de02010-05-05 15:25:02 +020011375 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011376 {
11377 .cmd = NL80211_CMD_SET_WDS_PEER,
11378 .doit = nl80211_set_wds_peer,
11379 .policy = nl80211_policy,
11380 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011381 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11382 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011383 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011384 {
11385 .cmd = NL80211_CMD_JOIN_MESH,
11386 .doit = nl80211_join_mesh,
11387 .policy = nl80211_policy,
11388 .flags = GENL_ADMIN_PERM,
11389 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11390 NL80211_FLAG_NEED_RTNL,
11391 },
11392 {
11393 .cmd = NL80211_CMD_LEAVE_MESH,
11394 .doit = nl80211_leave_mesh,
11395 .policy = nl80211_policy,
11396 .flags = GENL_ADMIN_PERM,
11397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11398 NL80211_FLAG_NEED_RTNL,
11399 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011400 {
11401 .cmd = NL80211_CMD_JOIN_OCB,
11402 .doit = nl80211_join_ocb,
11403 .policy = nl80211_policy,
11404 .flags = GENL_ADMIN_PERM,
11405 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11406 NL80211_FLAG_NEED_RTNL,
11407 },
11408 {
11409 .cmd = NL80211_CMD_LEAVE_OCB,
11410 .doit = nl80211_leave_ocb,
11411 .policy = nl80211_policy,
11412 .flags = GENL_ADMIN_PERM,
11413 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11414 NL80211_FLAG_NEED_RTNL,
11415 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011416#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011417 {
11418 .cmd = NL80211_CMD_GET_WOWLAN,
11419 .doit = nl80211_get_wowlan,
11420 .policy = nl80211_policy,
11421 /* can be retrieved by unprivileged users */
11422 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11423 NL80211_FLAG_NEED_RTNL,
11424 },
11425 {
11426 .cmd = NL80211_CMD_SET_WOWLAN,
11427 .doit = nl80211_set_wowlan,
11428 .policy = nl80211_policy,
11429 .flags = GENL_ADMIN_PERM,
11430 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11431 NL80211_FLAG_NEED_RTNL,
11432 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011433#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011434 {
11435 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11436 .doit = nl80211_set_rekey_data,
11437 .policy = nl80211_policy,
11438 .flags = GENL_ADMIN_PERM,
11439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011440 NL80211_FLAG_NEED_RTNL |
11441 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011442 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011443 {
11444 .cmd = NL80211_CMD_TDLS_MGMT,
11445 .doit = nl80211_tdls_mgmt,
11446 .policy = nl80211_policy,
11447 .flags = GENL_ADMIN_PERM,
11448 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11449 NL80211_FLAG_NEED_RTNL,
11450 },
11451 {
11452 .cmd = NL80211_CMD_TDLS_OPER,
11453 .doit = nl80211_tdls_oper,
11454 .policy = nl80211_policy,
11455 .flags = GENL_ADMIN_PERM,
11456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11457 NL80211_FLAG_NEED_RTNL,
11458 },
Johannes Berg28946da2011-11-04 11:18:12 +010011459 {
11460 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11461 .doit = nl80211_register_unexpected_frame,
11462 .policy = nl80211_policy,
11463 .flags = GENL_ADMIN_PERM,
11464 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11465 NL80211_FLAG_NEED_RTNL,
11466 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011467 {
11468 .cmd = NL80211_CMD_PROBE_CLIENT,
11469 .doit = nl80211_probe_client,
11470 .policy = nl80211_policy,
11471 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011473 NL80211_FLAG_NEED_RTNL,
11474 },
Johannes Berg5e760232011-11-04 11:18:17 +010011475 {
11476 .cmd = NL80211_CMD_REGISTER_BEACONS,
11477 .doit = nl80211_register_beacons,
11478 .policy = nl80211_policy,
11479 .flags = GENL_ADMIN_PERM,
11480 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11481 NL80211_FLAG_NEED_RTNL,
11482 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011483 {
11484 .cmd = NL80211_CMD_SET_NOACK_MAP,
11485 .doit = nl80211_set_noack_map,
11486 .policy = nl80211_policy,
11487 .flags = GENL_ADMIN_PERM,
11488 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11489 NL80211_FLAG_NEED_RTNL,
11490 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011491 {
11492 .cmd = NL80211_CMD_START_P2P_DEVICE,
11493 .doit = nl80211_start_p2p_device,
11494 .policy = nl80211_policy,
11495 .flags = GENL_ADMIN_PERM,
11496 .internal_flags = NL80211_FLAG_NEED_WDEV |
11497 NL80211_FLAG_NEED_RTNL,
11498 },
11499 {
11500 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11501 .doit = nl80211_stop_p2p_device,
11502 .policy = nl80211_policy,
11503 .flags = GENL_ADMIN_PERM,
11504 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11505 NL80211_FLAG_NEED_RTNL,
11506 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011507 {
11508 .cmd = NL80211_CMD_SET_MCAST_RATE,
11509 .doit = nl80211_set_mcast_rate,
11510 .policy = nl80211_policy,
11511 .flags = GENL_ADMIN_PERM,
11512 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11513 NL80211_FLAG_NEED_RTNL,
11514 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011515 {
11516 .cmd = NL80211_CMD_SET_MAC_ACL,
11517 .doit = nl80211_set_mac_acl,
11518 .policy = nl80211_policy,
11519 .flags = GENL_ADMIN_PERM,
11520 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11521 NL80211_FLAG_NEED_RTNL,
11522 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011523 {
11524 .cmd = NL80211_CMD_RADAR_DETECT,
11525 .doit = nl80211_start_radar_detection,
11526 .policy = nl80211_policy,
11527 .flags = GENL_ADMIN_PERM,
11528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11529 NL80211_FLAG_NEED_RTNL,
11530 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011531 {
11532 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11533 .doit = nl80211_get_protocol_features,
11534 .policy = nl80211_policy,
11535 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011536 {
11537 .cmd = NL80211_CMD_UPDATE_FT_IES,
11538 .doit = nl80211_update_ft_ies,
11539 .policy = nl80211_policy,
11540 .flags = GENL_ADMIN_PERM,
11541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11542 NL80211_FLAG_NEED_RTNL,
11543 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011544 {
11545 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11546 .doit = nl80211_crit_protocol_start,
11547 .policy = nl80211_policy,
11548 .flags = GENL_ADMIN_PERM,
11549 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11550 NL80211_FLAG_NEED_RTNL,
11551 },
11552 {
11553 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11554 .doit = nl80211_crit_protocol_stop,
11555 .policy = nl80211_policy,
11556 .flags = GENL_ADMIN_PERM,
11557 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11558 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011559 },
11560 {
11561 .cmd = NL80211_CMD_GET_COALESCE,
11562 .doit = nl80211_get_coalesce,
11563 .policy = nl80211_policy,
11564 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11565 NL80211_FLAG_NEED_RTNL,
11566 },
11567 {
11568 .cmd = NL80211_CMD_SET_COALESCE,
11569 .doit = nl80211_set_coalesce,
11570 .policy = nl80211_policy,
11571 .flags = GENL_ADMIN_PERM,
11572 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11573 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011574 },
11575 {
11576 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11577 .doit = nl80211_channel_switch,
11578 .policy = nl80211_policy,
11579 .flags = GENL_ADMIN_PERM,
11580 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11581 NL80211_FLAG_NEED_RTNL,
11582 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011583 {
11584 .cmd = NL80211_CMD_VENDOR,
11585 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011586 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011587 .policy = nl80211_policy,
11588 .flags = GENL_ADMIN_PERM,
11589 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11590 NL80211_FLAG_NEED_RTNL,
11591 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011592 {
11593 .cmd = NL80211_CMD_SET_QOS_MAP,
11594 .doit = nl80211_set_qos_map,
11595 .policy = nl80211_policy,
11596 .flags = GENL_ADMIN_PERM,
11597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11598 NL80211_FLAG_NEED_RTNL,
11599 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011600 {
11601 .cmd = NL80211_CMD_ADD_TX_TS,
11602 .doit = nl80211_add_tx_ts,
11603 .policy = nl80211_policy,
11604 .flags = GENL_ADMIN_PERM,
11605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11606 NL80211_FLAG_NEED_RTNL,
11607 },
11608 {
11609 .cmd = NL80211_CMD_DEL_TX_TS,
11610 .doit = nl80211_del_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 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011616 {
11617 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11618 .doit = nl80211_tdls_channel_switch,
11619 .policy = nl80211_policy,
11620 .flags = GENL_ADMIN_PERM,
11621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11622 NL80211_FLAG_NEED_RTNL,
11623 },
11624 {
11625 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11626 .doit = nl80211_tdls_cancel_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 },
Johannes Berg55682962007-09-20 13:09:35 -040011632};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011633
Johannes Berg55682962007-09-20 13:09:35 -040011634/* notification functions */
11635
Johannes Berg3bb20552014-05-26 13:52:25 +020011636void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11637 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011638{
11639 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011640 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011641
Johannes Berg3bb20552014-05-26 13:52:25 +020011642 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11643 cmd != NL80211_CMD_DEL_WIPHY);
11644
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011645 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011646 if (!msg)
11647 return;
11648
Johannes Berg3bb20552014-05-26 13:52:25 +020011649 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011650 nlmsg_free(msg);
11651 return;
11652 }
11653
Johannes Berg68eb5502013-11-19 15:19:38 +010011654 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011655 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011656}
11657
Johannes Berg362a4152009-05-24 16:43:15 +020011658static int nl80211_add_scan_req(struct sk_buff *msg,
11659 struct cfg80211_registered_device *rdev)
11660{
11661 struct cfg80211_scan_request *req = rdev->scan_req;
11662 struct nlattr *nest;
11663 int i;
11664
11665 if (WARN_ON(!req))
11666 return 0;
11667
11668 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11669 if (!nest)
11670 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011671 for (i = 0; i < req->n_ssids; i++) {
11672 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11673 goto nla_put_failure;
11674 }
Johannes Berg362a4152009-05-24 16:43:15 +020011675 nla_nest_end(msg, nest);
11676
11677 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11678 if (!nest)
11679 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011680 for (i = 0; i < req->n_channels; i++) {
11681 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11682 goto nla_put_failure;
11683 }
Johannes Berg362a4152009-05-24 16:43:15 +020011684 nla_nest_end(msg, nest);
11685
David S. Miller9360ffd2012-03-29 04:41:26 -040011686 if (req->ie &&
11687 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11688 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011689
Johannes Bergae917c92013-10-25 11:05:22 +020011690 if (req->flags &&
11691 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11692 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011693
Johannes Berg362a4152009-05-24 16:43:15 +020011694 return 0;
11695 nla_put_failure:
11696 return -ENOBUFS;
11697}
11698
Johannes Berga538e2d2009-06-16 19:56:42 +020011699static int nl80211_send_scan_msg(struct sk_buff *msg,
11700 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011701 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011702 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011703 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011704{
11705 void *hdr;
11706
Eric W. Biederman15e47302012-09-07 20:12:54 +000011707 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011708 if (!hdr)
11709 return -1;
11710
David S. Miller9360ffd2012-03-29 04:41:26 -040011711 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011712 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11713 wdev->netdev->ifindex)) ||
11714 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011715 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011716
Johannes Berg362a4152009-05-24 16:43:15 +020011717 /* ignore errors and send incomplete event anyway */
11718 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011719
Johannes Berg053c0952015-01-16 22:09:00 +010011720 genlmsg_end(msg, hdr);
11721 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011722
11723 nla_put_failure:
11724 genlmsg_cancel(msg, hdr);
11725 return -EMSGSIZE;
11726}
11727
Luciano Coelho807f8a82011-05-11 17:09:35 +030011728static int
11729nl80211_send_sched_scan_msg(struct sk_buff *msg,
11730 struct cfg80211_registered_device *rdev,
11731 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011732 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011733{
11734 void *hdr;
11735
Eric W. Biederman15e47302012-09-07 20:12:54 +000011736 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011737 if (!hdr)
11738 return -1;
11739
David S. Miller9360ffd2012-03-29 04:41:26 -040011740 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11741 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11742 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011743
Johannes Berg053c0952015-01-16 22:09:00 +010011744 genlmsg_end(msg, hdr);
11745 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011746
11747 nla_put_failure:
11748 genlmsg_cancel(msg, hdr);
11749 return -EMSGSIZE;
11750}
11751
Johannes Berga538e2d2009-06-16 19:56:42 +020011752void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011753 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011754{
11755 struct sk_buff *msg;
11756
Thomas Graf58050fc2012-06-28 03:57:45 +000011757 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011758 if (!msg)
11759 return;
11760
Johannes Bergfd014282012-06-18 19:17:03 +020011761 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011762 NL80211_CMD_TRIGGER_SCAN) < 0) {
11763 nlmsg_free(msg);
11764 return;
11765 }
11766
Johannes Berg68eb5502013-11-19 15:19:38 +010011767 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011768 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011769}
11770
Johannes Bergf9d15d12014-01-22 11:14:19 +020011771struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11772 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011773{
11774 struct sk_buff *msg;
11775
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011777 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011778 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011779
Johannes Bergfd014282012-06-18 19:17:03 +020011780 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011781 aborted ? NL80211_CMD_SCAN_ABORTED :
11782 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011783 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011784 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011785 }
11786
Johannes Bergf9d15d12014-01-22 11:14:19 +020011787 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011788}
11789
Johannes Bergf9d15d12014-01-22 11:14:19 +020011790void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11791 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011792{
Johannes Berg2a519312009-02-10 21:25:55 +010011793 if (!msg)
11794 return;
11795
Johannes Berg68eb5502013-11-19 15:19:38 +010011796 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011797 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011798}
11799
Luciano Coelho807f8a82011-05-11 17:09:35 +030011800void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11801 struct net_device *netdev)
11802{
11803 struct sk_buff *msg;
11804
11805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11806 if (!msg)
11807 return;
11808
11809 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11810 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11811 nlmsg_free(msg);
11812 return;
11813 }
11814
Johannes Berg68eb5502013-11-19 15:19:38 +010011815 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011816 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011817}
11818
11819void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11820 struct net_device *netdev, u32 cmd)
11821{
11822 struct sk_buff *msg;
11823
Thomas Graf58050fc2012-06-28 03:57:45 +000011824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011825 if (!msg)
11826 return;
11827
11828 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11829 nlmsg_free(msg);
11830 return;
11831 }
11832
Johannes Berg68eb5502013-11-19 15:19:38 +010011833 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011834 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011835}
11836
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011837static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11838 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011839{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011840 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011841 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11842 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011843
David S. Miller9360ffd2012-03-29 04:41:26 -040011844 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11845 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11846 NL80211_REGDOM_TYPE_WORLD))
11847 goto nla_put_failure;
11848 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11849 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11850 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11851 goto nla_put_failure;
11852 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11853 request->intersect) {
11854 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11855 NL80211_REGDOM_TYPE_INTERSECTION))
11856 goto nla_put_failure;
11857 } else {
11858 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11859 NL80211_REGDOM_TYPE_COUNTRY) ||
11860 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11861 request->alpha2))
11862 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011863 }
11864
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011865 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11866 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11867
11868 if (wiphy &&
11869 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11870 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011871
11872 if (wiphy &&
11873 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11874 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11875 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011876 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011877
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011878 return true;
11879
11880nla_put_failure:
11881 return false;
11882}
11883
11884/*
11885 * This can happen on global regulatory changes or device specific settings
11886 * based on custom regulatory domains.
11887 */
11888void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11889 struct regulatory_request *request)
11890{
11891 struct sk_buff *msg;
11892 void *hdr;
11893
11894 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11895 if (!msg)
11896 return;
11897
11898 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11899 if (!hdr) {
11900 nlmsg_free(msg);
11901 return;
11902 }
11903
11904 if (nl80211_reg_change_event_fill(msg, request) == false)
11905 goto nla_put_failure;
11906
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011907 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011908
Johannes Bergbc43b282009-07-25 10:54:13 +020011909 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011910 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011911 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011912 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011913
11914 return;
11915
11916nla_put_failure:
11917 genlmsg_cancel(msg, hdr);
11918 nlmsg_free(msg);
11919}
11920
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011921static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11922 struct net_device *netdev,
11923 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011924 enum nl80211_commands cmd, gfp_t gfp,
11925 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011926{
11927 struct sk_buff *msg;
11928 void *hdr;
11929
Johannes Berge6d6e342009-07-01 21:26:47 +020011930 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011931 if (!msg)
11932 return;
11933
11934 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11935 if (!hdr) {
11936 nlmsg_free(msg);
11937 return;
11938 }
11939
David S. Miller9360ffd2012-03-29 04:41:26 -040011940 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11941 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11942 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11943 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011944
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011945 if (uapsd_queues >= 0) {
11946 struct nlattr *nla_wmm =
11947 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11948 if (!nla_wmm)
11949 goto nla_put_failure;
11950
11951 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11952 uapsd_queues))
11953 goto nla_put_failure;
11954
11955 nla_nest_end(msg, nla_wmm);
11956 }
11957
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011958 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011959
Johannes Berg68eb5502013-11-19 15:19:38 +010011960 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011961 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011962 return;
11963
11964 nla_put_failure:
11965 genlmsg_cancel(msg, hdr);
11966 nlmsg_free(msg);
11967}
11968
11969void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011970 struct net_device *netdev, const u8 *buf,
11971 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011972{
11973 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011974 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011975}
11976
11977void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11978 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011979 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011980{
Johannes Berge6d6e342009-07-01 21:26:47 +020011981 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011982 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011983}
11984
Jouni Malinen53b46b82009-03-27 20:53:56 +020011985void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011986 struct net_device *netdev, const u8 *buf,
11987 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011988{
11989 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011990 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011991}
11992
Jouni Malinen53b46b82009-03-27 20:53:56 +020011993void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11994 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011995 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011996{
11997 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011998 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011999}
12000
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012001void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12002 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012003{
Johannes Berg947add32013-02-22 22:05:20 +010012004 struct wireless_dev *wdev = dev->ieee80211_ptr;
12005 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012006 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012007 const struct ieee80211_mgmt *mgmt = (void *)buf;
12008 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012009
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012010 if (WARN_ON(len < 2))
12011 return;
12012
12013 if (ieee80211_is_deauth(mgmt->frame_control))
12014 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12015 else
12016 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12017
12018 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012019 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012020}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012021EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012022
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012023static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12024 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012025 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012026{
12027 struct sk_buff *msg;
12028 void *hdr;
12029
Johannes Berge6d6e342009-07-01 21:26:47 +020012030 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012031 if (!msg)
12032 return;
12033
12034 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12035 if (!hdr) {
12036 nlmsg_free(msg);
12037 return;
12038 }
12039
David S. Miller9360ffd2012-03-29 04:41:26 -040012040 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12041 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12042 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12043 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12044 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012045
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012046 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012047
Johannes Berg68eb5502013-11-19 15:19:38 +010012048 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012049 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012050 return;
12051
12052 nla_put_failure:
12053 genlmsg_cancel(msg, hdr);
12054 nlmsg_free(msg);
12055}
12056
12057void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012058 struct net_device *netdev, const u8 *addr,
12059 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012060{
12061 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012062 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012063}
12064
12065void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012066 struct net_device *netdev, const u8 *addr,
12067 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012068{
Johannes Berge6d6e342009-07-01 21:26:47 +020012069 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12070 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012071}
12072
Samuel Ortizb23aa672009-07-01 21:26:54 +020012073void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12074 struct net_device *netdev, const u8 *bssid,
12075 const u8 *req_ie, size_t req_ie_len,
12076 const u8 *resp_ie, size_t resp_ie_len,
12077 u16 status, gfp_t gfp)
12078{
12079 struct sk_buff *msg;
12080 void *hdr;
12081
Thomas Graf58050fc2012-06-28 03:57:45 +000012082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012083 if (!msg)
12084 return;
12085
12086 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12087 if (!hdr) {
12088 nlmsg_free(msg);
12089 return;
12090 }
12091
David S. Miller9360ffd2012-03-29 04:41:26 -040012092 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12093 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12094 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
12095 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
12096 (req_ie &&
12097 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12098 (resp_ie &&
12099 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12100 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012101
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012102 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012103
Johannes Berg68eb5502013-11-19 15:19:38 +010012104 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012105 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012106 return;
12107
12108 nla_put_failure:
12109 genlmsg_cancel(msg, hdr);
12110 nlmsg_free(msg);
12111
12112}
12113
12114void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12115 struct net_device *netdev, const u8 *bssid,
12116 const u8 *req_ie, size_t req_ie_len,
12117 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12118{
12119 struct sk_buff *msg;
12120 void *hdr;
12121
Thomas Graf58050fc2012-06-28 03:57:45 +000012122 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012123 if (!msg)
12124 return;
12125
12126 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12127 if (!hdr) {
12128 nlmsg_free(msg);
12129 return;
12130 }
12131
David S. Miller9360ffd2012-03-29 04:41:26 -040012132 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12133 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12134 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12135 (req_ie &&
12136 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12137 (resp_ie &&
12138 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12139 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012140
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012141 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012142
Johannes Berg68eb5502013-11-19 15:19:38 +010012143 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012144 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012145 return;
12146
12147 nla_put_failure:
12148 genlmsg_cancel(msg, hdr);
12149 nlmsg_free(msg);
12150
12151}
12152
12153void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12154 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020012155 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012156{
12157 struct sk_buff *msg;
12158 void *hdr;
12159
Thomas Graf58050fc2012-06-28 03:57:45 +000012160 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012161 if (!msg)
12162 return;
12163
12164 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12165 if (!hdr) {
12166 nlmsg_free(msg);
12167 return;
12168 }
12169
David S. Miller9360ffd2012-03-29 04:41:26 -040012170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12171 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12172 (from_ap && reason &&
12173 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12174 (from_ap &&
12175 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12176 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12177 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012178
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012179 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012180
Johannes Berg68eb5502013-11-19 15:19:38 +010012181 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012182 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012183 return;
12184
12185 nla_put_failure:
12186 genlmsg_cancel(msg, hdr);
12187 nlmsg_free(msg);
12188
12189}
12190
Johannes Berg04a773a2009-04-19 21:24:32 +020012191void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12192 struct net_device *netdev, const u8 *bssid,
12193 gfp_t gfp)
12194{
12195 struct sk_buff *msg;
12196 void *hdr;
12197
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012198 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012199 if (!msg)
12200 return;
12201
12202 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12203 if (!hdr) {
12204 nlmsg_free(msg);
12205 return;
12206 }
12207
David S. Miller9360ffd2012-03-29 04:41:26 -040012208 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12209 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12210 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12211 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012212
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012213 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012214
Johannes Berg68eb5502013-11-19 15:19:38 +010012215 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012216 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012217 return;
12218
12219 nla_put_failure:
12220 genlmsg_cancel(msg, hdr);
12221 nlmsg_free(msg);
12222}
12223
Johannes Berg947add32013-02-22 22:05:20 +010012224void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12225 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012226{
Johannes Berg947add32013-02-22 22:05:20 +010012227 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012228 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012229 struct sk_buff *msg;
12230 void *hdr;
12231
Johannes Berg947add32013-02-22 22:05:20 +010012232 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12233 return;
12234
12235 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12236
Javier Cardonac93b5e72011-04-07 15:08:34 -070012237 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12238 if (!msg)
12239 return;
12240
12241 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12242 if (!hdr) {
12243 nlmsg_free(msg);
12244 return;
12245 }
12246
David S. Miller9360ffd2012-03-29 04:41:26 -040012247 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012248 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12249 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012250 (ie_len && ie &&
12251 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12252 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012253
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012254 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012255
Johannes Berg68eb5502013-11-19 15:19:38 +010012256 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012257 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012258 return;
12259
12260 nla_put_failure:
12261 genlmsg_cancel(msg, hdr);
12262 nlmsg_free(msg);
12263}
Johannes Berg947add32013-02-22 22:05:20 +010012264EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012265
Jouni Malinena3b8b052009-03-27 21:59:49 +020012266void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12267 struct net_device *netdev, const u8 *addr,
12268 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012269 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012270{
12271 struct sk_buff *msg;
12272 void *hdr;
12273
Johannes Berge6d6e342009-07-01 21:26:47 +020012274 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012275 if (!msg)
12276 return;
12277
12278 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12279 if (!hdr) {
12280 nlmsg_free(msg);
12281 return;
12282 }
12283
David S. Miller9360ffd2012-03-29 04:41:26 -040012284 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12285 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12286 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12287 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12288 (key_id != -1 &&
12289 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12290 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12291 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012292
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012293 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012294
Johannes Berg68eb5502013-11-19 15:19:38 +010012295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012296 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012297 return;
12298
12299 nla_put_failure:
12300 genlmsg_cancel(msg, hdr);
12301 nlmsg_free(msg);
12302}
12303
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012304void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12305 struct ieee80211_channel *channel_before,
12306 struct ieee80211_channel *channel_after)
12307{
12308 struct sk_buff *msg;
12309 void *hdr;
12310 struct nlattr *nl_freq;
12311
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012312 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012313 if (!msg)
12314 return;
12315
12316 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12317 if (!hdr) {
12318 nlmsg_free(msg);
12319 return;
12320 }
12321
12322 /*
12323 * Since we are applying the beacon hint to a wiphy we know its
12324 * wiphy_idx is valid
12325 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012326 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12327 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012328
12329 /* Before */
12330 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12331 if (!nl_freq)
12332 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012333 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012334 goto nla_put_failure;
12335 nla_nest_end(msg, nl_freq);
12336
12337 /* After */
12338 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12339 if (!nl_freq)
12340 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012341 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012342 goto nla_put_failure;
12343 nla_nest_end(msg, nl_freq);
12344
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012345 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012346
Johannes Berg463d0182009-07-14 00:33:35 +020012347 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012348 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012349 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012350 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012351
12352 return;
12353
12354nla_put_failure:
12355 genlmsg_cancel(msg, hdr);
12356 nlmsg_free(msg);
12357}
12358
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012359static void nl80211_send_remain_on_chan_event(
12360 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012361 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012362 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012363 unsigned int duration, gfp_t gfp)
12364{
12365 struct sk_buff *msg;
12366 void *hdr;
12367
12368 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12369 if (!msg)
12370 return;
12371
12372 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12373 if (!hdr) {
12374 nlmsg_free(msg);
12375 return;
12376 }
12377
David S. Miller9360ffd2012-03-29 04:41:26 -040012378 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012379 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12380 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020012381 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012382 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012383 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12384 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012385 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
12386 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012387
David S. Miller9360ffd2012-03-29 04:41:26 -040012388 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12389 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12390 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012391
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012392 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012393
Johannes Berg68eb5502013-11-19 15:19:38 +010012394 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012395 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012396 return;
12397
12398 nla_put_failure:
12399 genlmsg_cancel(msg, hdr);
12400 nlmsg_free(msg);
12401}
12402
Johannes Berg947add32013-02-22 22:05:20 +010012403void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12404 struct ieee80211_channel *chan,
12405 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012406{
Johannes Berg947add32013-02-22 22:05:20 +010012407 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012408 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012409
12410 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012411 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012412 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012413 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012414}
Johannes Berg947add32013-02-22 22:05:20 +010012415EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012416
Johannes Berg947add32013-02-22 22:05:20 +010012417void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12418 struct ieee80211_channel *chan,
12419 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012420{
Johannes Berg947add32013-02-22 22:05:20 +010012421 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012422 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012423
12424 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012425 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012426 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012427}
Johannes Berg947add32013-02-22 22:05:20 +010012428EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012429
Johannes Berg947add32013-02-22 22:05:20 +010012430void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12431 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012432{
Johannes Berg947add32013-02-22 22:05:20 +010012433 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012434 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012435 struct sk_buff *msg;
12436
Johannes Berg947add32013-02-22 22:05:20 +010012437 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12438
Thomas Graf58050fc2012-06-28 03:57:45 +000012439 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012440 if (!msg)
12441 return;
12442
Johannes Bergcf5ead82014-11-14 17:14:00 +010012443 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012444 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012445 nlmsg_free(msg);
12446 return;
12447 }
12448
Johannes Berg68eb5502013-11-19 15:19:38 +010012449 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012450 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012451}
Johannes Berg947add32013-02-22 22:05:20 +010012452EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012453
Johannes Bergcf5ead82014-11-14 17:14:00 +010012454void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12455 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012456{
Johannes Berg947add32013-02-22 22:05:20 +010012457 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012458 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012459 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012460 struct station_info empty_sinfo = {};
12461
12462 if (!sinfo)
12463 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012464
Johannes Berg947add32013-02-22 22:05:20 +010012465 trace_cfg80211_del_sta(dev, mac_addr);
12466
Thomas Graf58050fc2012-06-28 03:57:45 +000012467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012468 if (!msg)
12469 return;
12470
Johannes Bergcf5ead82014-11-14 17:14:00 +010012471 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012472 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012473 nlmsg_free(msg);
12474 return;
12475 }
12476
Johannes Berg68eb5502013-11-19 15:19:38 +010012477 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012478 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012479}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012480EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012481
Johannes Berg947add32013-02-22 22:05:20 +010012482void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12483 enum nl80211_connect_failed_reason reason,
12484 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012485{
Johannes Berg947add32013-02-22 22:05:20 +010012486 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012487 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012488 struct sk_buff *msg;
12489 void *hdr;
12490
12491 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12492 if (!msg)
12493 return;
12494
12495 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12496 if (!hdr) {
12497 nlmsg_free(msg);
12498 return;
12499 }
12500
12501 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12502 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12503 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12504 goto nla_put_failure;
12505
12506 genlmsg_end(msg, hdr);
12507
Johannes Berg68eb5502013-11-19 15:19:38 +010012508 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012509 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012510 return;
12511
12512 nla_put_failure:
12513 genlmsg_cancel(msg, hdr);
12514 nlmsg_free(msg);
12515}
Johannes Berg947add32013-02-22 22:05:20 +010012516EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012517
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012518static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12519 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012520{
12521 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012522 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012523 struct sk_buff *msg;
12524 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012525 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012526
Eric W. Biederman15e47302012-09-07 20:12:54 +000012527 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012528 return false;
12529
12530 msg = nlmsg_new(100, gfp);
12531 if (!msg)
12532 return true;
12533
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012534 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012535 if (!hdr) {
12536 nlmsg_free(msg);
12537 return true;
12538 }
12539
David S. Miller9360ffd2012-03-29 04:41:26 -040012540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12541 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12542 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12543 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012544
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012545 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012546 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012547 return true;
12548
12549 nla_put_failure:
12550 genlmsg_cancel(msg, hdr);
12551 nlmsg_free(msg);
12552 return true;
12553}
12554
Johannes Berg947add32013-02-22 22:05:20 +010012555bool cfg80211_rx_spurious_frame(struct net_device *dev,
12556 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012557{
Johannes Berg947add32013-02-22 22:05:20 +010012558 struct wireless_dev *wdev = dev->ieee80211_ptr;
12559 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012560
Johannes Berg947add32013-02-22 22:05:20 +010012561 trace_cfg80211_rx_spurious_frame(dev, addr);
12562
12563 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12564 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12565 trace_cfg80211_return_bool(false);
12566 return false;
12567 }
12568 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12569 addr, gfp);
12570 trace_cfg80211_return_bool(ret);
12571 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012572}
Johannes Berg947add32013-02-22 22:05:20 +010012573EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12574
12575bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12576 const u8 *addr, gfp_t gfp)
12577{
12578 struct wireless_dev *wdev = dev->ieee80211_ptr;
12579 bool ret;
12580
12581 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12582
12583 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12584 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12585 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12586 trace_cfg80211_return_bool(false);
12587 return false;
12588 }
12589 ret = __nl80211_unexpected_frame(dev,
12590 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12591 addr, gfp);
12592 trace_cfg80211_return_bool(ret);
12593 return ret;
12594}
12595EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012596
Johannes Berg2e161f72010-08-12 15:38:38 +020012597int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012598 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012599 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012600 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012601{
Johannes Berg71bbc992012-06-15 15:30:18 +020012602 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012603 struct sk_buff *msg;
12604 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012605
12606 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12607 if (!msg)
12608 return -ENOMEM;
12609
Johannes Berg2e161f72010-08-12 15:38:38 +020012610 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012611 if (!hdr) {
12612 nlmsg_free(msg);
12613 return -ENOMEM;
12614 }
12615
David S. Miller9360ffd2012-03-29 04:41:26 -040012616 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012617 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12618 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012619 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012620 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12621 (sig_dbm &&
12622 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012623 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12624 (flags &&
12625 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012626 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012627
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012628 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012629
Eric W. Biederman15e47302012-09-07 20:12:54 +000012630 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012631
12632 nla_put_failure:
12633 genlmsg_cancel(msg, hdr);
12634 nlmsg_free(msg);
12635 return -ENOBUFS;
12636}
12637
Johannes Berg947add32013-02-22 22:05:20 +010012638void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12639 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012640{
Johannes Berg947add32013-02-22 22:05:20 +010012641 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012642 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012643 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012644 struct sk_buff *msg;
12645 void *hdr;
12646
Johannes Berg947add32013-02-22 22:05:20 +010012647 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12648
Jouni Malinen026331c2010-02-15 12:53:10 +020012649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12650 if (!msg)
12651 return;
12652
Johannes Berg2e161f72010-08-12 15:38:38 +020012653 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012654 if (!hdr) {
12655 nlmsg_free(msg);
12656 return;
12657 }
12658
David S. Miller9360ffd2012-03-29 04:41:26 -040012659 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012660 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12661 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012662 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012663 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12664 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12665 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12666 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012667
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012668 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012669
Johannes Berg68eb5502013-11-19 15:19:38 +010012670 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012671 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012672 return;
12673
12674 nla_put_failure:
12675 genlmsg_cancel(msg, hdr);
12676 nlmsg_free(msg);
12677}
Johannes Berg947add32013-02-22 22:05:20 +010012678EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012679
Johannes Berg5b97f492014-11-26 12:37:43 +010012680static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12681 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012682{
Johannes Berg947add32013-02-22 22:05:20 +010012683 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012684 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12685 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12686 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012687
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012688 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012689 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012690
Johannes Berg5b97f492014-11-26 12:37:43 +010012691 cb = (void **)msg->cb;
12692
12693 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12694 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012695 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012696 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012697 }
12698
David S. Miller9360ffd2012-03-29 04:41:26 -040012699 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012700 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012701 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012702
Johannes Berg5b97f492014-11-26 12:37:43 +010012703 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012704 goto nla_put_failure;
12705
Johannes Berg5b97f492014-11-26 12:37:43 +010012706 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12707 if (!cb[1])
12708 goto nla_put_failure;
12709
12710 cb[2] = rdev;
12711
12712 return msg;
12713 nla_put_failure:
12714 nlmsg_free(msg);
12715 return NULL;
12716}
12717
12718static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12719{
12720 void **cb = (void **)msg->cb;
12721 struct cfg80211_registered_device *rdev = cb[2];
12722
12723 nla_nest_end(msg, cb[1]);
12724 genlmsg_end(msg, cb[0]);
12725
12726 memset(msg->cb, 0, sizeof(msg->cb));
12727
12728 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12729 NL80211_MCGRP_MLME, gfp);
12730}
12731
12732void cfg80211_cqm_rssi_notify(struct net_device *dev,
12733 enum nl80211_cqm_rssi_threshold_event rssi_event,
12734 gfp_t gfp)
12735{
12736 struct sk_buff *msg;
12737
12738 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12739
Johannes Berg98f03342014-11-26 12:42:02 +010012740 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12741 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12742 return;
12743
Johannes Berg5b97f492014-11-26 12:37:43 +010012744 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12745 if (!msg)
12746 return;
12747
David S. Miller9360ffd2012-03-29 04:41:26 -040012748 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12749 rssi_event))
12750 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012751
Johannes Berg5b97f492014-11-26 12:37:43 +010012752 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012753
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012754 return;
12755
12756 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012757 nlmsg_free(msg);
12758}
Johannes Berg947add32013-02-22 22:05:20 +010012759EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012760
Johannes Berg5b97f492014-11-26 12:37:43 +010012761void cfg80211_cqm_txe_notify(struct net_device *dev,
12762 const u8 *peer, u32 num_packets,
12763 u32 rate, u32 intvl, gfp_t gfp)
12764{
12765 struct sk_buff *msg;
12766
12767 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12768 if (!msg)
12769 return;
12770
12771 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12772 goto nla_put_failure;
12773
12774 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12775 goto nla_put_failure;
12776
12777 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12778 goto nla_put_failure;
12779
12780 cfg80211_send_cqm(msg, gfp);
12781 return;
12782
12783 nla_put_failure:
12784 nlmsg_free(msg);
12785}
12786EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12787
12788void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12789 const u8 *peer, u32 num_packets, gfp_t gfp)
12790{
12791 struct sk_buff *msg;
12792
12793 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12794
12795 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12796 if (!msg)
12797 return;
12798
12799 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12800 goto nla_put_failure;
12801
12802 cfg80211_send_cqm(msg, gfp);
12803 return;
12804
12805 nla_put_failure:
12806 nlmsg_free(msg);
12807}
12808EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12809
Johannes Berg98f03342014-11-26 12:42:02 +010012810void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12811{
12812 struct sk_buff *msg;
12813
12814 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12815 if (!msg)
12816 return;
12817
12818 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12819 goto nla_put_failure;
12820
12821 cfg80211_send_cqm(msg, gfp);
12822 return;
12823
12824 nla_put_failure:
12825 nlmsg_free(msg);
12826}
12827EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12828
Johannes Berg947add32013-02-22 22:05:20 +010012829static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12830 struct net_device *netdev, const u8 *bssid,
12831 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012832{
12833 struct sk_buff *msg;
12834 struct nlattr *rekey_attr;
12835 void *hdr;
12836
Thomas Graf58050fc2012-06-28 03:57:45 +000012837 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012838 if (!msg)
12839 return;
12840
12841 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12842 if (!hdr) {
12843 nlmsg_free(msg);
12844 return;
12845 }
12846
David S. Miller9360ffd2012-03-29 04:41:26 -040012847 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12848 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12849 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12850 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012851
12852 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12853 if (!rekey_attr)
12854 goto nla_put_failure;
12855
David S. Miller9360ffd2012-03-29 04:41:26 -040012856 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12857 NL80211_REPLAY_CTR_LEN, replay_ctr))
12858 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012859
12860 nla_nest_end(msg, rekey_attr);
12861
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012862 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012863
Johannes Berg68eb5502013-11-19 15:19:38 +010012864 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012865 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012866 return;
12867
12868 nla_put_failure:
12869 genlmsg_cancel(msg, hdr);
12870 nlmsg_free(msg);
12871}
12872
Johannes Berg947add32013-02-22 22:05:20 +010012873void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12874 const u8 *replay_ctr, gfp_t gfp)
12875{
12876 struct wireless_dev *wdev = dev->ieee80211_ptr;
12877 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012878 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012879
12880 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12881 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12882}
12883EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12884
12885static void
12886nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12887 struct net_device *netdev, int index,
12888 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012889{
12890 struct sk_buff *msg;
12891 struct nlattr *attr;
12892 void *hdr;
12893
Thomas Graf58050fc2012-06-28 03:57:45 +000012894 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012895 if (!msg)
12896 return;
12897
12898 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12899 if (!hdr) {
12900 nlmsg_free(msg);
12901 return;
12902 }
12903
David S. Miller9360ffd2012-03-29 04:41:26 -040012904 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12905 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12906 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012907
12908 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12909 if (!attr)
12910 goto nla_put_failure;
12911
David S. Miller9360ffd2012-03-29 04:41:26 -040012912 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12913 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12914 (preauth &&
12915 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12916 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012917
12918 nla_nest_end(msg, attr);
12919
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012920 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012921
Johannes Berg68eb5502013-11-19 15:19:38 +010012922 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012923 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012924 return;
12925
12926 nla_put_failure:
12927 genlmsg_cancel(msg, hdr);
12928 nlmsg_free(msg);
12929}
12930
Johannes Berg947add32013-02-22 22:05:20 +010012931void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12932 const u8 *bssid, bool preauth, gfp_t gfp)
12933{
12934 struct wireless_dev *wdev = dev->ieee80211_ptr;
12935 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012936 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012937
12938 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12939 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12940}
12941EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12942
12943static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12944 struct net_device *netdev,
12945 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012946 gfp_t gfp,
12947 enum nl80211_commands notif,
12948 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012949{
12950 struct sk_buff *msg;
12951 void *hdr;
12952
Thomas Graf58050fc2012-06-28 03:57:45 +000012953 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012954 if (!msg)
12955 return;
12956
Luciano Coelhof8d75522014-11-07 14:31:35 +020012957 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012958 if (!hdr) {
12959 nlmsg_free(msg);
12960 return;
12961 }
12962
Johannes Berg683b6d32012-11-08 21:25:48 +010012963 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12964 goto nla_put_failure;
12965
12966 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012967 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012968
Luciano Coelhof8d75522014-11-07 14:31:35 +020012969 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12970 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12971 goto nla_put_failure;
12972
Thomas Pedersen53145262012-04-06 13:35:47 -070012973 genlmsg_end(msg, hdr);
12974
Johannes Berg68eb5502013-11-19 15:19:38 +010012975 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012976 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012977 return;
12978
12979 nla_put_failure:
12980 genlmsg_cancel(msg, hdr);
12981 nlmsg_free(msg);
12982}
12983
Johannes Berg947add32013-02-22 22:05:20 +010012984void cfg80211_ch_switch_notify(struct net_device *dev,
12985 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012986{
Johannes Berg947add32013-02-22 22:05:20 +010012987 struct wireless_dev *wdev = dev->ieee80211_ptr;
12988 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012989 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012990
Simon Wunderliche487eae2013-11-21 18:19:51 +010012991 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012992
Simon Wunderliche487eae2013-11-21 18:19:51 +010012993 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012994
Michal Kazior9e0e2962014-01-29 14:22:27 +010012995 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012996 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012997 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12998 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012999}
13000EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13001
Luciano Coelhof8d75522014-11-07 14:31:35 +020013002void cfg80211_ch_switch_started_notify(struct net_device *dev,
13003 struct cfg80211_chan_def *chandef,
13004 u8 count)
13005{
13006 struct wireless_dev *wdev = dev->ieee80211_ptr;
13007 struct wiphy *wiphy = wdev->wiphy;
13008 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13009
13010 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13011
13012 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13013 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13014}
13015EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13016
Thomas Pedersen84f10702012-07-12 16:17:33 -070013017void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013018nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013019 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013020 enum nl80211_radar_event event,
13021 struct net_device *netdev, gfp_t gfp)
13022{
13023 struct sk_buff *msg;
13024 void *hdr;
13025
13026 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13027 if (!msg)
13028 return;
13029
13030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13031 if (!hdr) {
13032 nlmsg_free(msg);
13033 return;
13034 }
13035
13036 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13037 goto nla_put_failure;
13038
13039 /* NOP and radar events don't need a netdev parameter */
13040 if (netdev) {
13041 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13042
13043 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13044 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13045 goto nla_put_failure;
13046 }
13047
13048 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13049 goto nla_put_failure;
13050
13051 if (nl80211_send_chandef(msg, chandef))
13052 goto nla_put_failure;
13053
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013054 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013055
Johannes Berg68eb5502013-11-19 15:19:38 +010013056 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013057 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013058 return;
13059
13060 nla_put_failure:
13061 genlmsg_cancel(msg, hdr);
13062 nlmsg_free(msg);
13063}
13064
Johannes Berg7f6cf312011-11-04 11:18:15 +010013065void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13066 u64 cookie, bool acked, gfp_t gfp)
13067{
13068 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013069 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013070 struct sk_buff *msg;
13071 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013072
Beni Lev4ee3e062012-08-27 12:49:39 +030013073 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13074
Thomas Graf58050fc2012-06-28 03:57:45 +000013075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013076
Johannes Berg7f6cf312011-11-04 11:18:15 +010013077 if (!msg)
13078 return;
13079
13080 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13081 if (!hdr) {
13082 nlmsg_free(msg);
13083 return;
13084 }
13085
David S. Miller9360ffd2012-03-29 04:41:26 -040013086 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13087 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13088 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
13089 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
13090 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13091 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013092
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013093 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013094
Johannes Berg68eb5502013-11-19 15:19:38 +010013095 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013096 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013097 return;
13098
13099 nla_put_failure:
13100 genlmsg_cancel(msg, hdr);
13101 nlmsg_free(msg);
13102}
13103EXPORT_SYMBOL(cfg80211_probe_status);
13104
Johannes Berg5e760232011-11-04 11:18:17 +010013105void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13106 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013107 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010013108{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013109 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010013110 struct sk_buff *msg;
13111 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013112 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010013113
Beni Lev4ee3e062012-08-27 12:49:39 +030013114 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13115
Ben Greear37c73b52012-10-26 14:49:25 -070013116 spin_lock_bh(&rdev->beacon_registrations_lock);
13117 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13118 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13119 if (!msg) {
13120 spin_unlock_bh(&rdev->beacon_registrations_lock);
13121 return;
13122 }
Johannes Berg5e760232011-11-04 11:18:17 +010013123
Ben Greear37c73b52012-10-26 14:49:25 -070013124 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13125 if (!hdr)
13126 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010013127
Ben Greear37c73b52012-10-26 14:49:25 -070013128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13129 (freq &&
13130 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13131 (sig_dbm &&
13132 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13133 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13134 goto nla_put_failure;
13135
13136 genlmsg_end(msg, hdr);
13137
13138 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010013139 }
Ben Greear37c73b52012-10-26 14:49:25 -070013140 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010013141 return;
13142
13143 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013144 spin_unlock_bh(&rdev->beacon_registrations_lock);
13145 if (hdr)
13146 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010013147 nlmsg_free(msg);
13148}
13149EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13150
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013151#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013152static int cfg80211_net_detect_results(struct sk_buff *msg,
13153 struct cfg80211_wowlan_wakeup *wakeup)
13154{
13155 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13156 struct nlattr *nl_results, *nl_match, *nl_freqs;
13157 int i, j;
13158
13159 nl_results = nla_nest_start(
13160 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13161 if (!nl_results)
13162 return -EMSGSIZE;
13163
13164 for (i = 0; i < nd->n_matches; i++) {
13165 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13166
13167 nl_match = nla_nest_start(msg, i);
13168 if (!nl_match)
13169 break;
13170
13171 /* The SSID attribute is optional in nl80211, but for
13172 * simplicity reasons it's always present in the
13173 * cfg80211 structure. If a driver can't pass the
13174 * SSID, that needs to be changed. A zero length SSID
13175 * is still a valid SSID (wildcard), so it cannot be
13176 * used for this purpose.
13177 */
13178 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13179 match->ssid.ssid)) {
13180 nla_nest_cancel(msg, nl_match);
13181 goto out;
13182 }
13183
13184 if (match->n_channels) {
13185 nl_freqs = nla_nest_start(
13186 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13187 if (!nl_freqs) {
13188 nla_nest_cancel(msg, nl_match);
13189 goto out;
13190 }
13191
13192 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013193 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013194 nla_nest_cancel(msg, nl_freqs);
13195 nla_nest_cancel(msg, nl_match);
13196 goto out;
13197 }
13198 }
13199
13200 nla_nest_end(msg, nl_freqs);
13201 }
13202
13203 nla_nest_end(msg, nl_match);
13204 }
13205
13206out:
13207 nla_nest_end(msg, nl_results);
13208 return 0;
13209}
13210
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013211void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13212 struct cfg80211_wowlan_wakeup *wakeup,
13213 gfp_t gfp)
13214{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013215 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013216 struct sk_buff *msg;
13217 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013218 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013219
13220 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13221
13222 if (wakeup)
13223 size += wakeup->packet_present_len;
13224
13225 msg = nlmsg_new(size, gfp);
13226 if (!msg)
13227 return;
13228
13229 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13230 if (!hdr)
13231 goto free_msg;
13232
13233 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13234 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13235 goto free_msg;
13236
13237 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13238 wdev->netdev->ifindex))
13239 goto free_msg;
13240
13241 if (wakeup) {
13242 struct nlattr *reasons;
13243
13244 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013245 if (!reasons)
13246 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013247
13248 if (wakeup->disconnect &&
13249 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13250 goto free_msg;
13251 if (wakeup->magic_pkt &&
13252 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13253 goto free_msg;
13254 if (wakeup->gtk_rekey_failure &&
13255 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13256 goto free_msg;
13257 if (wakeup->eap_identity_req &&
13258 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13259 goto free_msg;
13260 if (wakeup->four_way_handshake &&
13261 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13262 goto free_msg;
13263 if (wakeup->rfkill_release &&
13264 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13265 goto free_msg;
13266
13267 if (wakeup->pattern_idx >= 0 &&
13268 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13269 wakeup->pattern_idx))
13270 goto free_msg;
13271
Johannes Bergae917c92013-10-25 11:05:22 +020013272 if (wakeup->tcp_match &&
13273 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13274 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013275
Johannes Bergae917c92013-10-25 11:05:22 +020013276 if (wakeup->tcp_connlost &&
13277 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13278 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013279
Johannes Bergae917c92013-10-25 11:05:22 +020013280 if (wakeup->tcp_nomoretokens &&
13281 nla_put_flag(msg,
13282 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13283 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013284
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013285 if (wakeup->packet) {
13286 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13287 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13288
13289 if (!wakeup->packet_80211) {
13290 pkt_attr =
13291 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13292 len_attr =
13293 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13294 }
13295
13296 if (wakeup->packet_len &&
13297 nla_put_u32(msg, len_attr, wakeup->packet_len))
13298 goto free_msg;
13299
13300 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13301 wakeup->packet))
13302 goto free_msg;
13303 }
13304
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013305 if (wakeup->net_detect &&
13306 cfg80211_net_detect_results(msg, wakeup))
13307 goto free_msg;
13308
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013309 nla_nest_end(msg, reasons);
13310 }
13311
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013312 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013313
Johannes Berg68eb5502013-11-19 15:19:38 +010013314 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013315 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013316 return;
13317
13318 free_msg:
13319 nlmsg_free(msg);
13320}
13321EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13322#endif
13323
Jouni Malinen3475b092012-11-16 22:49:57 +020013324void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13325 enum nl80211_tdls_operation oper,
13326 u16 reason_code, gfp_t gfp)
13327{
13328 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013329 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013330 struct sk_buff *msg;
13331 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013332
13333 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13334 reason_code);
13335
13336 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13337 if (!msg)
13338 return;
13339
13340 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13341 if (!hdr) {
13342 nlmsg_free(msg);
13343 return;
13344 }
13345
13346 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13347 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13348 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13349 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13350 (reason_code > 0 &&
13351 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13352 goto nla_put_failure;
13353
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013354 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013355
Johannes Berg68eb5502013-11-19 15:19:38 +010013356 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013357 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013358 return;
13359
13360 nla_put_failure:
13361 genlmsg_cancel(msg, hdr);
13362 nlmsg_free(msg);
13363}
13364EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13365
Jouni Malinen026331c2010-02-15 12:53:10 +020013366static int nl80211_netlink_notify(struct notifier_block * nb,
13367 unsigned long state,
13368 void *_notify)
13369{
13370 struct netlink_notify *notify = _notify;
13371 struct cfg80211_registered_device *rdev;
13372 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013373 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013374
13375 if (state != NETLINK_URELEASE)
13376 return NOTIFY_DONE;
13377
13378 rcu_read_lock();
13379
Johannes Berg5e760232011-11-04 11:18:17 +010013380 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013381 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013382 bool schedule_scan_stop = false;
13383 struct cfg80211_sched_scan_request *sched_scan_req =
13384 rcu_dereference(rdev->sched_scan_req);
13385
13386 if (sched_scan_req && notify->portid &&
13387 sched_scan_req->owner_nlportid == notify->portid)
13388 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013389
13390 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013391 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013392
Johannes Berg78f22b62014-03-24 17:57:27 +010013393 if (wdev->owner_nlportid == notify->portid)
13394 schedule_destroy_work = true;
13395 }
13396
Ben Greear37c73b52012-10-26 14:49:25 -070013397 spin_lock_bh(&rdev->beacon_registrations_lock);
13398 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13399 list) {
13400 if (reg->nlportid == notify->portid) {
13401 list_del(&reg->list);
13402 kfree(reg);
13403 break;
13404 }
13405 }
13406 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013407
13408 if (schedule_destroy_work) {
13409 struct cfg80211_iface_destroy *destroy;
13410
13411 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13412 if (destroy) {
13413 destroy->nlportid = notify->portid;
13414 spin_lock(&rdev->destroy_list_lock);
13415 list_add(&destroy->list, &rdev->destroy_list);
13416 spin_unlock(&rdev->destroy_list_lock);
13417 schedule_work(&rdev->destroy_work);
13418 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013419 } else if (schedule_scan_stop) {
13420 sched_scan_req->owner_nlportid = 0;
13421
13422 if (rdev->ops->sched_scan_stop &&
13423 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13424 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013425 }
Johannes Berg5e760232011-11-04 11:18:17 +010013426 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013427
13428 rcu_read_unlock();
13429
Ilan peer05050752015-03-04 00:32:06 -050013430 /*
13431 * It is possible that the user space process that is controlling the
13432 * indoor setting disappeared, so notify the regulatory core.
13433 */
13434 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013435 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013436}
13437
13438static struct notifier_block nl80211_netlink_notifier = {
13439 .notifier_call = nl80211_netlink_notify,
13440};
13441
Jouni Malinen355199e2013-02-27 17:14:27 +020013442void cfg80211_ft_event(struct net_device *netdev,
13443 struct cfg80211_ft_event_params *ft_event)
13444{
13445 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013446 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013447 struct sk_buff *msg;
13448 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013449
13450 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13451
13452 if (!ft_event->target_ap)
13453 return;
13454
13455 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13456 if (!msg)
13457 return;
13458
13459 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013460 if (!hdr)
13461 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013462
Johannes Bergae917c92013-10-25 11:05:22 +020013463 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13464 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13465 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13466 goto out;
13467
13468 if (ft_event->ies &&
13469 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13470 goto out;
13471 if (ft_event->ric_ies &&
13472 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13473 ft_event->ric_ies))
13474 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013475
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013476 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013477
Johannes Berg68eb5502013-11-19 15:19:38 +010013478 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013479 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013480 return;
13481 out:
13482 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013483}
13484EXPORT_SYMBOL(cfg80211_ft_event);
13485
Arend van Spriel5de17982013-04-18 15:49:00 +020013486void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13487{
13488 struct cfg80211_registered_device *rdev;
13489 struct sk_buff *msg;
13490 void *hdr;
13491 u32 nlportid;
13492
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013493 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013494 if (!rdev->crit_proto_nlportid)
13495 return;
13496
13497 nlportid = rdev->crit_proto_nlportid;
13498 rdev->crit_proto_nlportid = 0;
13499
13500 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13501 if (!msg)
13502 return;
13503
13504 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13505 if (!hdr)
13506 goto nla_put_failure;
13507
13508 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13509 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13510 goto nla_put_failure;
13511
13512 genlmsg_end(msg, hdr);
13513
13514 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13515 return;
13516
13517 nla_put_failure:
13518 if (hdr)
13519 genlmsg_cancel(msg, hdr);
13520 nlmsg_free(msg);
13521
13522}
13523EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13524
Johannes Berg348baf02014-01-24 14:06:29 +010013525void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13526{
13527 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013528 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013529 struct sk_buff *msg;
13530 void *hdr;
13531
13532 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13533 if (!msg)
13534 return;
13535
13536 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13537 if (!hdr)
13538 goto out;
13539
13540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13541 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
13542 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13543 goto out;
13544
13545 genlmsg_end(msg, hdr);
13546
13547 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13548 NL80211_MCGRP_MLME, GFP_KERNEL);
13549 return;
13550 out:
13551 nlmsg_free(msg);
13552}
13553
Johannes Berg55682962007-09-20 13:09:35 -040013554/* initialisation/exit functions */
13555
13556int nl80211_init(void)
13557{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013558 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013559
Johannes Berg2a94fe42013-11-19 15:19:39 +010013560 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13561 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013562 if (err)
13563 return err;
13564
Jouni Malinen026331c2010-02-15 12:53:10 +020013565 err = netlink_register_notifier(&nl80211_netlink_notifier);
13566 if (err)
13567 goto err_out;
13568
Johannes Berg55682962007-09-20 13:09:35 -040013569 return 0;
13570 err_out:
13571 genl_unregister_family(&nl80211_fam);
13572 return err;
13573}
13574
13575void nl80211_exit(void)
13576{
Jouni Malinen026331c2010-02-15 12:53:10 +020013577 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013578 genl_unregister_family(&nl80211_fam);
13579}