blob: 5b0d2c8c2165d439ac0cb8bc05aa0a533f0f1c66 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Beni Lev0c9ca112016-02-17 20:30:00 +02006 * Copyright 2015-2016 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg89a54e42012-06-15 14:33:17 +0200106 list_for_each_entry(wdev, &rdev->wdev_list, list) {
107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee4772012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200152 list_for_each_entry(wdev, &tmp->wdev_list, list) {
153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800170 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200171 if (netdev) {
172 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800173 tmp = wiphy_to_rdev(
174 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200175 else
176 tmp = NULL;
177
Johannes Berg7fee4772012-06-15 14:09:58 +0200178 /* not wireless device -- return error */
179 if (!tmp)
180 return ERR_PTR(-EINVAL);
181
182 /* mismatch -- return error */
183 if (rdev && tmp != rdev)
184 return ERR_PTR(-EINVAL);
185
186 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
189
Johannes Berg4f7eff12012-06-15 14:14:22 +0200190 if (!rdev)
191 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (netns != wiphy_net(&rdev->wiphy))
194 return ERR_PTR(-ENODEV);
195
196 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200197}
198
199/*
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200202 *
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
205 */
206static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200207cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200208{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200209 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200210}
211
Johannes Berg55682962007-09-20 13:09:35 -0400212/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300213static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400214 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
215 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700216 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200217 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100218
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200219 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
224
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200225 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200230 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400231
232 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Eliad Pellere007b852011-11-24 18:13:56 +0200236 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
237 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100238
Johannes Bergb9454e82009-07-08 13:29:08 +0200239 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100240 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
241 .len = WLAN_MAX_KEY_LEN },
242 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
243 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
244 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200245 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200246 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100247
248 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
249 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
250 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
252 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100254 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
255 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
256 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
258 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100260 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200261 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800263 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100264 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300265
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700266 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
267 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
268
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300269 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200272 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
273 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100274 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300275
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800276 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700277 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700278
Johannes Berg6c739412011-11-03 09:27:01 +0100279 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200280
281 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
282 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
283 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100284 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
285 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200286
287 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_SSID_LEN },
289 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
290 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200291 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300292 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300293 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300294 [NL80211_ATTR_STA_FLAGS2] = {
295 .len = sizeof(struct nl80211_sta_flag_update),
296 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300297 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200300 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
301 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
302 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200303 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100304 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100305 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
306 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100307 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
308 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200309 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200310 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
311 .len = IEEE80211_MAX_DATA_LEN },
312 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200313 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200314 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300315 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200316 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300317 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200319 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900320 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100322 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100323 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100324 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200325 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700326 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300327 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200328 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200329 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300330 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300331 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
332 .len = IEEE80211_MAX_DATA_LEN },
333 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530335 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300336 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530337 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300338 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
342 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300343 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000358 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700359 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100360 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
361 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530362 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
363 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200364 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
365 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100366 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100367 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
368 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
369 .len = NL80211_VHT_CAPABILITY_LEN,
370 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200371 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
372 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
373 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300374 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200375 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
377 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300378 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
379 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200382 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100383 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100384 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800387 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
388 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200389 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
390 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530391 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200392 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300393 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300394 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300395 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
396 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
397 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300398 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200399 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200401 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200402 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500403 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200404 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100405 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200406 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400407};
408
Johannes Berge31b8212010-10-05 19:39:30 +0200409/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000410static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200411 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200412 [NL80211_KEY_IDX] = { .type = NLA_U8 },
413 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200414 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200415 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
416 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200417 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100418 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
419};
420
421/* policy for the key default flags */
422static const struct nla_policy
423nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
424 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
425 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200426};
427
Johannes Bergff1b6e62011-05-04 15:37:28 +0200428/* policy for WoWLAN attributes */
429static const struct nla_policy
430nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
431 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200435 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
436 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
437 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100439 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300440 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100441};
442
443static const struct nla_policy
444nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
445 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
446 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
447 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
448 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
449 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
451 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
452 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
453 },
454 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
455 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
456 },
457 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
458 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
459 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200460};
461
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700462/* policy for coalesce rule attributes */
463static const struct nla_policy
464nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
465 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
466 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
467 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
468};
469
Johannes Berge5497d72011-07-05 16:35:40 +0200470/* policy for GTK rekey offload attributes */
471static const struct nla_policy
472nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
473 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
474 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
475 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
476};
477
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300478static const struct nla_policy
479nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200480 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300481 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700482 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300483};
484
Avraham Stern3b06d272015-10-12 09:51:34 +0300485static const struct nla_policy
486nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
487 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
488 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
489};
490
Arend van Spriel38de03d2016-03-02 20:37:18 +0100491static const struct nla_policy
492nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
493 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
494 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
495 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
496 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
497 },
498};
499
Johannes Berg97990a02013-04-19 01:02:55 +0200500static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
501 struct netlink_callback *cb,
502 struct cfg80211_registered_device **rdev,
503 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100504{
Johannes Berg67748892010-10-04 21:14:06 +0200505 int err;
506
Johannes Berg67748892010-10-04 21:14:06 +0200507 rtnl_lock();
508
Johannes Berg97990a02013-04-19 01:02:55 +0200509 if (!cb->args[0]) {
510 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
511 nl80211_fam.attrbuf, nl80211_fam.maxattr,
512 nl80211_policy);
513 if (err)
514 goto out_unlock;
515
516 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
517 nl80211_fam.attrbuf);
518 if (IS_ERR(*wdev)) {
519 err = PTR_ERR(*wdev);
520 goto out_unlock;
521 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800522 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200523 /* 0 is the first index - add 1 to parse only once */
524 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200525 cb->args[1] = (*wdev)->identifier;
526 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200527 /* subtract the 1 again here */
528 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200529 struct wireless_dev *tmp;
530
531 if (!wiphy) {
532 err = -ENODEV;
533 goto out_unlock;
534 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800535 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200536 *wdev = NULL;
537
Johannes Berg97990a02013-04-19 01:02:55 +0200538 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
539 if (tmp->identifier == cb->args[1]) {
540 *wdev = tmp;
541 break;
542 }
543 }
Johannes Berg97990a02013-04-19 01:02:55 +0200544
545 if (!*wdev) {
546 err = -ENODEV;
547 goto out_unlock;
548 }
Johannes Berg67748892010-10-04 21:14:06 +0200549 }
550
Johannes Berg67748892010-10-04 21:14:06 +0200551 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200552 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200553 rtnl_unlock();
554 return err;
555}
556
Johannes Berg97990a02013-04-19 01:02:55 +0200557static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200558{
Johannes Berg67748892010-10-04 21:14:06 +0200559 rtnl_unlock();
560}
561
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100562/* IE validation */
563static bool is_valid_ie_attr(const struct nlattr *attr)
564{
565 const u8 *pos;
566 int len;
567
568 if (!attr)
569 return true;
570
571 pos = nla_data(attr);
572 len = nla_len(attr);
573
574 while (len) {
575 u8 elemlen;
576
577 if (len < 2)
578 return false;
579 len -= 2;
580
581 elemlen = pos[1];
582 if (elemlen > len)
583 return false;
584
585 len -= elemlen;
586 pos += 2 + elemlen;
587 }
588
589 return true;
590}
591
Johannes Berg55682962007-09-20 13:09:35 -0400592/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000593static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400594 int flags, u8 cmd)
595{
596 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000597 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400598}
599
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400600static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100601 struct ieee80211_channel *chan,
602 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400603{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200604 /* Some channels must be completely excluded from the
605 * list to protect old user-space tools from breaking
606 */
607 if (!large && chan->flags &
608 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
609 return 0;
610
David S. Miller9360ffd2012-03-29 04:41:26 -0400611 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
612 chan->center_freq))
613 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400614
David S. Miller9360ffd2012-03-29 04:41:26 -0400615 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
616 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
617 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200618 if (chan->flags & IEEE80211_CHAN_NO_IR) {
619 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
620 goto nla_put_failure;
621 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
622 goto nla_put_failure;
623 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100624 if (chan->flags & IEEE80211_CHAN_RADAR) {
625 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
626 goto nla_put_failure;
627 if (large) {
628 u32 time;
629
630 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
631
632 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
633 chan->dfs_state))
634 goto nla_put_failure;
635 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
636 time))
637 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100638 if (nla_put_u32(msg,
639 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
640 chan->dfs_cac_ms))
641 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100642 }
643 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400644
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100645 if (large) {
646 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
647 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
648 goto nla_put_failure;
649 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
650 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
651 goto nla_put_failure;
652 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
653 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
654 goto nla_put_failure;
655 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
656 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
657 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200658 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
659 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
660 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300661 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
662 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200663 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200664 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
665 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
666 goto nla_put_failure;
667 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
668 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
669 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100670 }
671
David S. Miller9360ffd2012-03-29 04:41:26 -0400672 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
673 DBM_TO_MBM(chan->max_power)))
674 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400675
676 return 0;
677
678 nla_put_failure:
679 return -ENOBUFS;
680}
681
Johannes Berg55682962007-09-20 13:09:35 -0400682/* netlink command implementations */
683
Johannes Bergb9454e82009-07-08 13:29:08 +0200684struct key_parse {
685 struct key_params p;
686 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200687 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200688 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100689 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200690};
691
692static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
693{
694 struct nlattr *tb[NL80211_KEY_MAX + 1];
695 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
696 nl80211_key_policy);
697 if (err)
698 return err;
699
700 k->def = !!tb[NL80211_KEY_DEFAULT];
701 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
702
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100703 if (k->def) {
704 k->def_uni = true;
705 k->def_multi = true;
706 }
707 if (k->defmgmt)
708 k->def_multi = true;
709
Johannes Bergb9454e82009-07-08 13:29:08 +0200710 if (tb[NL80211_KEY_IDX])
711 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
712
713 if (tb[NL80211_KEY_DATA]) {
714 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
715 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
716 }
717
718 if (tb[NL80211_KEY_SEQ]) {
719 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
720 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
721 }
722
723 if (tb[NL80211_KEY_CIPHER])
724 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
725
Johannes Berge31b8212010-10-05 19:39:30 +0200726 if (tb[NL80211_KEY_TYPE]) {
727 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
728 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
729 return -EINVAL;
730 }
731
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100732 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
733 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100734 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
735 tb[NL80211_KEY_DEFAULT_TYPES],
736 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100737 if (err)
738 return err;
739
740 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
741 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
742 }
743
Johannes Bergb9454e82009-07-08 13:29:08 +0200744 return 0;
745}
746
747static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
748{
749 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
750 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
751 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
752 }
753
754 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
755 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
756 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
757 }
758
759 if (info->attrs[NL80211_ATTR_KEY_IDX])
760 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
761
762 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
763 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
764
765 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
766 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
767
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100768 if (k->def) {
769 k->def_uni = true;
770 k->def_multi = true;
771 }
772 if (k->defmgmt)
773 k->def_multi = true;
774
Johannes Berge31b8212010-10-05 19:39:30 +0200775 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
776 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
777 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
778 return -EINVAL;
779 }
780
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100781 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
782 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
783 int err = nla_parse_nested(
784 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
785 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
786 nl80211_key_default_policy);
787 if (err)
788 return err;
789
790 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
791 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
792 }
793
Johannes Bergb9454e82009-07-08 13:29:08 +0200794 return 0;
795}
796
797static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
798{
799 int err;
800
801 memset(k, 0, sizeof(*k));
802 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200803 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200804
805 if (info->attrs[NL80211_ATTR_KEY])
806 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
807 else
808 err = nl80211_parse_key_old(info, k);
809
810 if (err)
811 return err;
812
813 if (k->def && k->defmgmt)
814 return -EINVAL;
815
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100816 if (k->defmgmt) {
817 if (k->def_uni || !k->def_multi)
818 return -EINVAL;
819 }
820
Johannes Bergb9454e82009-07-08 13:29:08 +0200821 if (k->idx != -1) {
822 if (k->defmgmt) {
823 if (k->idx < 4 || k->idx > 5)
824 return -EINVAL;
825 } else if (k->def) {
826 if (k->idx < 0 || k->idx > 3)
827 return -EINVAL;
828 } else {
829 if (k->idx < 0 || k->idx > 5)
830 return -EINVAL;
831 }
832 }
833
834 return 0;
835}
836
Johannes Bergfffd0932009-07-08 14:22:54 +0200837static struct cfg80211_cached_keys *
838nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530839 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200840{
841 struct key_parse parse;
842 struct nlattr *key;
843 struct cfg80211_cached_keys *result;
844 int rem, err, def = 0;
845
846 result = kzalloc(sizeof(*result), GFP_KERNEL);
847 if (!result)
848 return ERR_PTR(-ENOMEM);
849
850 result->def = -1;
851 result->defmgmt = -1;
852
853 nla_for_each_nested(key, keys, rem) {
854 memset(&parse, 0, sizeof(parse));
855 parse.idx = -1;
856
857 err = nl80211_parse_key_new(key, &parse);
858 if (err)
859 goto error;
860 err = -EINVAL;
861 if (!parse.p.key)
862 goto error;
863 if (parse.idx < 0 || parse.idx > 4)
864 goto error;
865 if (parse.def) {
866 if (def)
867 goto error;
868 def = 1;
869 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100870 if (!parse.def_uni || !parse.def_multi)
871 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200872 } else if (parse.defmgmt)
873 goto error;
874 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200875 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 if (err)
877 goto error;
878 result->params[parse.idx].cipher = parse.p.cipher;
879 result->params[parse.idx].key_len = parse.p.key_len;
880 result->params[parse.idx].key = result->data[parse.idx];
881 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530882
883 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
884 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
885 if (no_ht)
886 *no_ht = true;
887 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 }
889
890 return result;
891 error:
892 kfree(result);
893 return ERR_PTR(err);
894}
895
896static int nl80211_key_allowed(struct wireless_dev *wdev)
897{
898 ASSERT_WDEV_LOCK(wdev);
899
Johannes Bergfffd0932009-07-08 14:22:54 +0200900 switch (wdev->iftype) {
901 case NL80211_IFTYPE_AP:
902 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200903 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700904 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200905 break;
906 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200907 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200908 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200909 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200910 return -ENOLINK;
911 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100912 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100913 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100914 case NL80211_IFTYPE_MONITOR:
915 case NL80211_IFTYPE_P2P_DEVICE:
916 case NL80211_IFTYPE_WDS:
917 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200918 return -EINVAL;
919 }
920
921 return 0;
922}
923
Jouni Malinen664834d2014-01-15 00:01:44 +0200924static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
925 struct nlattr *tb)
926{
927 struct ieee80211_channel *chan;
928
929 if (tb == NULL)
930 return NULL;
931 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
932 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
933 return NULL;
934 return chan;
935}
936
Johannes Berg7527a782011-05-13 10:58:57 +0200937static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
938{
939 struct nlattr *nl_modes = nla_nest_start(msg, attr);
940 int i;
941
942 if (!nl_modes)
943 goto nla_put_failure;
944
945 i = 0;
946 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400947 if ((ifmodes & 1) && nla_put_flag(msg, i))
948 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200949 ifmodes >>= 1;
950 i++;
951 }
952
953 nla_nest_end(msg, nl_modes);
954 return 0;
955
956nla_put_failure:
957 return -ENOBUFS;
958}
959
960static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100961 struct sk_buff *msg,
962 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200963{
964 struct nlattr *nl_combis;
965 int i, j;
966
967 nl_combis = nla_nest_start(msg,
968 NL80211_ATTR_INTERFACE_COMBINATIONS);
969 if (!nl_combis)
970 goto nla_put_failure;
971
972 for (i = 0; i < wiphy->n_iface_combinations; i++) {
973 const struct ieee80211_iface_combination *c;
974 struct nlattr *nl_combi, *nl_limits;
975
976 c = &wiphy->iface_combinations[i];
977
978 nl_combi = nla_nest_start(msg, i + 1);
979 if (!nl_combi)
980 goto nla_put_failure;
981
982 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
983 if (!nl_limits)
984 goto nla_put_failure;
985
986 for (j = 0; j < c->n_limits; j++) {
987 struct nlattr *nl_limit;
988
989 nl_limit = nla_nest_start(msg, j + 1);
990 if (!nl_limit)
991 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400992 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
993 c->limits[j].max))
994 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200995 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
996 c->limits[j].types))
997 goto nla_put_failure;
998 nla_nest_end(msg, nl_limit);
999 }
1000
1001 nla_nest_end(msg, nl_limits);
1002
David S. Miller9360ffd2012-03-29 04:41:26 -04001003 if (c->beacon_int_infra_match &&
1004 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1005 goto nla_put_failure;
1006 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1007 c->num_different_channels) ||
1008 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1009 c->max_interfaces))
1010 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001011 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001012 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1013 c->radar_detect_widths) ||
1014 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1015 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001016 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001017
1018 nla_nest_end(msg, nl_combi);
1019 }
1020
1021 nla_nest_end(msg, nl_combis);
1022
1023 return 0;
1024nla_put_failure:
1025 return -ENOBUFS;
1026}
1027
Johannes Berg3713b4e2013-02-14 16:19:38 +01001028#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001029static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1030 struct sk_buff *msg)
1031{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001032 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001033 struct nlattr *nl_tcp;
1034
1035 if (!tcp)
1036 return 0;
1037
1038 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1039 if (!nl_tcp)
1040 return -ENOBUFS;
1041
1042 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1043 tcp->data_payload_max))
1044 return -ENOBUFS;
1045
1046 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1047 tcp->data_payload_max))
1048 return -ENOBUFS;
1049
1050 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1051 return -ENOBUFS;
1052
1053 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1054 sizeof(*tcp->tok), tcp->tok))
1055 return -ENOBUFS;
1056
1057 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1058 tcp->data_interval_max))
1059 return -ENOBUFS;
1060
1061 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1062 tcp->wake_payload_max))
1063 return -ENOBUFS;
1064
1065 nla_nest_end(msg, nl_tcp);
1066 return 0;
1067}
1068
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001071 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072{
1073 struct nlattr *nl_wowlan;
1074
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 return 0;
1077
1078 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1079 if (!nl_wowlan)
1080 return -ENOBUFS;
1081
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001083 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001084 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001085 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1098 return -ENOBUFS;
1099
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001101 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1103 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1104 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1105 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001106 };
1107
1108 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1109 sizeof(pat), &pat))
1110 return -ENOBUFS;
1111 }
1112
Luciano Coelho75453cc2015-01-09 14:06:37 +02001113 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1114 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1115 rdev->wiphy.wowlan->max_nd_match_sets))
1116 return -ENOBUFS;
1117
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001118 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001119 return -ENOBUFS;
1120
Johannes Berg3713b4e2013-02-14 16:19:38 +01001121 nla_nest_end(msg, nl_wowlan);
1122
1123 return 0;
1124}
1125#endif
1126
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001127static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001128 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001129{
1130 struct nl80211_coalesce_rule_support rule;
1131
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001132 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001133 return 0;
1134
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001135 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1136 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1137 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1138 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1139 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1140 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001141
1142 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1143 return -ENOBUFS;
1144
1145 return 0;
1146}
1147
Johannes Berg3713b4e2013-02-14 16:19:38 +01001148static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1149 struct ieee80211_supported_band *sband)
1150{
1151 struct nlattr *nl_rates, *nl_rate;
1152 struct ieee80211_rate *rate;
1153 int i;
1154
1155 /* add HT info */
1156 if (sband->ht_cap.ht_supported &&
1157 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1158 sizeof(sband->ht_cap.mcs),
1159 &sband->ht_cap.mcs) ||
1160 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1161 sband->ht_cap.cap) ||
1162 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1163 sband->ht_cap.ampdu_factor) ||
1164 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1165 sband->ht_cap.ampdu_density)))
1166 return -ENOBUFS;
1167
1168 /* add VHT info */
1169 if (sband->vht_cap.vht_supported &&
1170 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1171 sizeof(sband->vht_cap.vht_mcs),
1172 &sband->vht_cap.vht_mcs) ||
1173 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1174 sband->vht_cap.cap)))
1175 return -ENOBUFS;
1176
1177 /* add bitrates */
1178 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1179 if (!nl_rates)
1180 return -ENOBUFS;
1181
1182 for (i = 0; i < sband->n_bitrates; i++) {
1183 nl_rate = nla_nest_start(msg, i);
1184 if (!nl_rate)
1185 return -ENOBUFS;
1186
1187 rate = &sband->bitrates[i];
1188 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1189 rate->bitrate))
1190 return -ENOBUFS;
1191 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1192 nla_put_flag(msg,
1193 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1194 return -ENOBUFS;
1195
1196 nla_nest_end(msg, nl_rate);
1197 }
1198
1199 nla_nest_end(msg, nl_rates);
1200
1201 return 0;
1202}
1203
1204static int
1205nl80211_send_mgmt_stypes(struct sk_buff *msg,
1206 const struct ieee80211_txrx_stypes *mgmt_stypes)
1207{
1208 u16 stypes;
1209 struct nlattr *nl_ftypes, *nl_ifs;
1210 enum nl80211_iftype ift;
1211 int i;
1212
1213 if (!mgmt_stypes)
1214 return 0;
1215
1216 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1217 if (!nl_ifs)
1218 return -ENOBUFS;
1219
1220 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1221 nl_ftypes = nla_nest_start(msg, ift);
1222 if (!nl_ftypes)
1223 return -ENOBUFS;
1224 i = 0;
1225 stypes = mgmt_stypes[ift].tx;
1226 while (stypes) {
1227 if ((stypes & 1) &&
1228 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1229 (i << 4) | IEEE80211_FTYPE_MGMT))
1230 return -ENOBUFS;
1231 stypes >>= 1;
1232 i++;
1233 }
1234 nla_nest_end(msg, nl_ftypes);
1235 }
1236
1237 nla_nest_end(msg, nl_ifs);
1238
1239 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1240 if (!nl_ifs)
1241 return -ENOBUFS;
1242
1243 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1244 nl_ftypes = nla_nest_start(msg, ift);
1245 if (!nl_ftypes)
1246 return -ENOBUFS;
1247 i = 0;
1248 stypes = mgmt_stypes[ift].rx;
1249 while (stypes) {
1250 if ((stypes & 1) &&
1251 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1252 (i << 4) | IEEE80211_FTYPE_MGMT))
1253 return -ENOBUFS;
1254 stypes >>= 1;
1255 i++;
1256 }
1257 nla_nest_end(msg, nl_ftypes);
1258 }
1259 nla_nest_end(msg, nl_ifs);
1260
1261 return 0;
1262}
1263
Johannes Berg86e8cf92013-06-19 10:57:22 +02001264struct nl80211_dump_wiphy_state {
1265 s64 filter_wiphy;
1266 long start;
1267 long split_start, band_start, chan_start;
1268 bool split;
1269};
1270
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001272 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001275{
1276 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001277 struct nlattr *nl_bands, *nl_band;
1278 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001279 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001280 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001281 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001282 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001283 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001285 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001286
Johannes Berg3bb20552014-05-26 13:52:25 +02001287 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001288 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 return -ENOBUFS;
1290
Johannes Berg86e8cf92013-06-19 10:57:22 +02001291 if (WARN_ON(!state))
1292 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001293
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001297 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001299 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001300
Johannes Berg3bb20552014-05-26 13:52:25 +02001301 if (cmd != NL80211_CMD_NEW_WIPHY)
1302 goto finish;
1303
Johannes Berg86e8cf92013-06-19 10:57:22 +02001304 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 case 0:
1306 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001325 rdev->wiphy.max_match_sets) ||
1326 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1327 rdev->wiphy.max_sched_scan_plans) ||
1328 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1329 rdev->wiphy.max_sched_scan_plan_interval) ||
1330 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1331 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001332 goto nla_put_failure;
1333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1336 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1339 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1342 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1345 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1348 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001351 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001352 state->split_start++;
1353 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 break;
1355 case 1:
1356 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001357 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1358 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001359 goto nla_put_failure;
1360
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001362 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001363 goto nla_put_failure;
1364
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001365 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1367 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001368
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001370 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001372 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001374
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001375 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001377 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001379
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001380 if ((rdev->wiphy.available_antennas_tx ||
1381 rdev->wiphy.available_antennas_rx) &&
1382 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 u32 tx_ant = 0, rx_ant = 0;
1384 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001385 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 if (!res) {
1387 if (nla_put_u32(msg,
1388 NL80211_ATTR_WIPHY_ANTENNA_TX,
1389 tx_ant) ||
1390 nla_put_u32(msg,
1391 NL80211_ATTR_WIPHY_ANTENNA_RX,
1392 rx_ant))
1393 goto nla_put_failure;
1394 }
Johannes Bergee688b002008-01-24 19:38:39 +01001395 }
1396
Johannes Berg86e8cf92013-06-19 10:57:22 +02001397 state->split_start++;
1398 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 break;
1400 case 2:
1401 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001402 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->split_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 case 3:
1408 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1409 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001410 goto nla_put_failure;
1411
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001413 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 struct ieee80211_supported_band *sband;
1415
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001416 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417
1418 if (!sband)
1419 continue;
1420
1421 nl_band = nla_nest_start(msg, band);
1422 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001423 goto nla_put_failure;
1424
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 case 0:
1427 if (nl80211_send_band_rateinfo(msg, sband))
1428 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 state->chan_start++;
1430 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 break;
1432 default:
1433 /* add frequencies */
1434 nl_freqs = nla_nest_start(
1435 msg, NL80211_BAND_ATTR_FREQS);
1436 if (!nl_freqs)
1437 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001438
Johannes Berg86e8cf92013-06-19 10:57:22 +02001439 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 i < sband->n_channels;
1441 i++) {
1442 nl_freq = nla_nest_start(msg, i);
1443 if (!nl_freq)
1444 goto nla_put_failure;
1445
1446 chan = &sband->channels[i];
1447
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 if (nl80211_msg_put_channel(
1449 msg, chan,
1450 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 goto nla_put_failure;
1452
1453 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001454 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 break;
1456 }
1457 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001458 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001460 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 nla_nest_end(msg, nl_freqs);
1462 }
1463
1464 nla_nest_end(msg, nl_band);
1465
Johannes Berg86e8cf92013-06-19 10:57:22 +02001466 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 band--;
1470 break;
1471 }
Johannes Bergee688b002008-01-24 19:38:39 +01001472 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001474
Johannes Berg57fbcce2016-04-12 15:56:15 +02001475 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001476 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001478 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001479
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 if (state->band_start == 0 && state->chan_start == 0)
1482 state->split_start++;
1483 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 break;
1485 case 4:
1486 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1487 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001488 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001489
1490 i = 0;
1491#define CMD(op, n) \
1492 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 i++; \
1495 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1496 goto nla_put_failure; \
1497 } \
1498 } while (0)
1499
1500 CMD(add_virtual_intf, NEW_INTERFACE);
1501 CMD(change_virtual_intf, SET_INTERFACE);
1502 CMD(add_key, NEW_KEY);
1503 CMD(start_ap, START_AP);
1504 CMD(add_station, NEW_STATION);
1505 CMD(add_mpath, NEW_MPATH);
1506 CMD(update_mesh_config, SET_MESH_CONFIG);
1507 CMD(change_bss, SET_BSS);
1508 CMD(auth, AUTHENTICATE);
1509 CMD(assoc, ASSOCIATE);
1510 CMD(deauth, DEAUTHENTICATE);
1511 CMD(disassoc, DISASSOCIATE);
1512 CMD(join_ibss, JOIN_IBSS);
1513 CMD(join_mesh, JOIN_MESH);
1514 CMD(set_pmksa, SET_PMKSA);
1515 CMD(del_pmksa, DEL_PMKSA);
1516 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1519 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1520 CMD(mgmt_tx, FRAME);
1521 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 i++;
1524 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1525 goto nla_put_failure;
1526 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001527 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1528 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 i++;
1530 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1531 goto nla_put_failure;
1532 }
1533 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 CMD(tdls_mgmt, TDLS_MGMT);
1536 CMD(tdls_oper, TDLS_OPER);
1537 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 CMD(sched_scan_start, START_SCHED_SCAN);
1540 CMD(probe_client, PROBE_CLIENT);
1541 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001542 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 i++;
1544 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1545 goto nla_put_failure;
1546 }
1547 CMD(start_p2p_device, START_P2P_DEVICE);
1548 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001549#ifdef CONFIG_NL80211_TESTMODE
1550 CMD(testmode_cmd, TESTMODE);
1551#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001552 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001553 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1554 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001556 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001557 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001558 if (rdev->wiphy.features &
1559 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001560 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001561 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001562 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001563#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001564
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 i++;
1567 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001568 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001569 }
1570
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 i++;
1573 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1574 goto nla_put_failure;
1575 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001576
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001578 state->split_start++;
1579 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 break;
1581 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 if (rdev->ops->remain_on_channel &&
1583 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_put_u32(msg,
1585 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001587 goto nla_put_failure;
1588
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1591 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001592
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1594 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001595 state->split_start++;
1596 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 break;
1598 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001599#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001600 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001601 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split_start++;
1603 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 break;
1605#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001606 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607#endif
1608 case 7:
1609 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001611 goto nla_put_failure;
1612
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001614 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001616
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 state->split_start++;
1618 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 break;
1620 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 goto nla_put_failure;
1625
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001627 /*
1628 * We can only add the per-channel limit information if the
1629 * dump is split, otherwise it makes it too big. Therefore
1630 * only advertise it in that case.
1631 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001633 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1634 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 goto nla_put_failure;
1636
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1640 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 goto nla_put_failure;
1642
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001643 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1644 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647 goto nla_put_failure;
1648
1649 /*
1650 * Any information below this point is only available to
1651 * applications that can deal with it being split. This
1652 * helps ensure that newly added capabilities don't break
1653 * older tools by overrunning their buffers.
1654 *
1655 * We still increment split_start so that in the split
1656 * case we'll continue with more data in the next round,
1657 * but break unconditionally so unsplit data stops here.
1658 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001659 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001660 break;
1661 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001662 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001663 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 rdev->wiphy.extended_capabilities_len,
1665 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001666 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001667 rdev->wiphy.extended_capabilities_len,
1668 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001669 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001672 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1674 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001675 goto nla_put_failure;
1676
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001677 state->split_start++;
1678 break;
1679 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001681 goto nla_put_failure;
1682
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001683 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001684 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1685 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1686 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001687
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001689 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001691 goto nla_put_failure;
1692
Johannes Bergad7e7182013-11-13 13:37:47 +01001693 state->split_start++;
1694 break;
1695 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001697 const struct nl80211_vendor_cmd_info *info;
1698 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001699
Johannes Berg567ffc32013-12-18 14:43:31 +01001700 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1701 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001702 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001703
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001704 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1705 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001706 if (nla_put(msg, i + 1, sizeof(*info), info))
1707 goto nla_put_failure;
1708 }
1709 nla_nest_end(msg, nested);
1710 }
1711
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001712 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001713 const struct nl80211_vendor_cmd_info *info;
1714 struct nlattr *nested;
1715
1716 nested = nla_nest_start(msg,
1717 NL80211_ATTR_VENDOR_EVENTS);
1718 if (!nested)
1719 goto nla_put_failure;
1720
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001721 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1722 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001723 if (nla_put(msg, i + 1, sizeof(*info), info))
1724 goto nla_put_failure;
1725 }
1726 nla_nest_end(msg, nested);
1727 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001728 state->split_start++;
1729 break;
1730 case 12:
1731 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1732 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1733 rdev->wiphy.max_num_csa_counters))
1734 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001735
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001736 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1737 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1738 goto nla_put_failure;
1739
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001740 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1741 sizeof(rdev->wiphy.ext_features),
1742 rdev->wiphy.ext_features))
1743 goto nla_put_failure;
1744
Arend van Spriel38de03d2016-03-02 20:37:18 +01001745 if (rdev->wiphy.bss_select_support) {
1746 struct nlattr *nested;
1747 u32 bss_select_support = rdev->wiphy.bss_select_support;
1748
1749 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1750 if (!nested)
1751 goto nla_put_failure;
1752
1753 i = 0;
1754 while (bss_select_support) {
1755 if ((bss_select_support & 1) &&
1756 nla_put_flag(msg, i))
1757 goto nla_put_failure;
1758 i++;
1759 bss_select_support >>= 1;
1760 }
1761 nla_nest_end(msg, nested);
1762 }
1763
Johannes Berg3713b4e2013-02-14 16:19:38 +01001764 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001765 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001766 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001767 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001768 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001769 genlmsg_end(msg, hdr);
1770 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001771
1772 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001773 genlmsg_cancel(msg, hdr);
1774 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001775}
1776
Johannes Berg86e8cf92013-06-19 10:57:22 +02001777static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1778 struct netlink_callback *cb,
1779 struct nl80211_dump_wiphy_state *state)
1780{
1781 struct nlattr **tb = nl80211_fam.attrbuf;
1782 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1783 tb, nl80211_fam.maxattr, nl80211_policy);
1784 /* ignore parse errors for backward compatibility */
1785 if (ret)
1786 return 0;
1787
1788 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1789 if (tb[NL80211_ATTR_WIPHY])
1790 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1791 if (tb[NL80211_ATTR_WDEV])
1792 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1793 if (tb[NL80211_ATTR_IFINDEX]) {
1794 struct net_device *netdev;
1795 struct cfg80211_registered_device *rdev;
1796 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1797
Ying Xue7f2b8562014-01-15 10:23:45 +08001798 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001799 if (!netdev)
1800 return -ENODEV;
1801 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001802 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001803 netdev->ieee80211_ptr->wiphy);
1804 state->filter_wiphy = rdev->wiphy_idx;
1805 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806 }
1807
1808 return 0;
1809}
1810
Johannes Berg55682962007-09-20 13:09:35 -04001811static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1812{
Johannes Berg645e77d2013-03-01 14:03:49 +01001813 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001815 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001816
Johannes Berg5fe231e2013-05-08 21:45:15 +02001817 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 if (!state) {
1819 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001820 if (!state) {
1821 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001822 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001823 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001824 state->filter_wiphy = -1;
1825 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1826 if (ret) {
1827 kfree(state);
1828 rtnl_unlock();
1829 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001830 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001831 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001832 }
1833
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001834 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1835 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001836 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001837 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001838 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001839 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001840 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001841 continue;
1842 /* attempt to fit multiple wiphy data chunks into the skb */
1843 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001844 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1845 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001846 NETLINK_CB(cb->skb).portid,
1847 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001848 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001849 if (ret < 0) {
1850 /*
1851 * If sending the wiphy data didn't fit (ENOBUFS
1852 * or EMSGSIZE returned), this SKB is still
1853 * empty (so it's not too big because another
1854 * wiphy dataset is already in the skb) and
1855 * we've not tried to adjust the dump allocation
1856 * yet ... then adjust the alloc size to be
1857 * bigger, and return 1 but with the empty skb.
1858 * This results in an empty message being RX'ed
1859 * in userspace, but that is ignored.
1860 *
1861 * We can then retry with the larger buffer.
1862 */
1863 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001864 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001865 cb->min_dump_alloc < 4096) {
1866 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001867 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001868 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001869 return 1;
1870 }
1871 idx--;
1872 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001873 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001874 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001875 break;
Johannes Berg55682962007-09-20 13:09:35 -04001876 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001877 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001878
Johannes Berg86e8cf92013-06-19 10:57:22 +02001879 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001880
1881 return skb->len;
1882}
1883
Johannes Berg86e8cf92013-06-19 10:57:22 +02001884static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1885{
1886 kfree((void *)cb->args[0]);
1887 return 0;
1888}
1889
Johannes Berg55682962007-09-20 13:09:35 -04001890static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1891{
1892 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001894 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001895
Johannes Berg645e77d2013-03-01 14:03:49 +01001896 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001897 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001898 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001899
Johannes Berg3bb20552014-05-26 13:52:25 +02001900 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1901 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001902 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001903 nlmsg_free(msg);
1904 return -ENOBUFS;
1905 }
Johannes Berg55682962007-09-20 13:09:35 -04001906
Johannes Berg134e6372009-07-10 09:51:34 +00001907 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001908}
1909
Jouni Malinen31888482008-10-30 16:59:24 +02001910static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1911 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1912 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1913 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1914 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1915 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1916};
1917
1918static int parse_txq_params(struct nlattr *tb[],
1919 struct ieee80211_txq_params *txq_params)
1920{
Johannes Berga3304b02012-03-28 11:04:24 +02001921 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001922 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1923 !tb[NL80211_TXQ_ATTR_AIFS])
1924 return -EINVAL;
1925
Johannes Berga3304b02012-03-28 11:04:24 +02001926 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001927 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1928 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1929 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1930 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1931
Johannes Berga3304b02012-03-28 11:04:24 +02001932 if (txq_params->ac >= NL80211_NUM_ACS)
1933 return -EINVAL;
1934
Jouni Malinen31888482008-10-30 16:59:24 +02001935 return 0;
1936}
1937
Johannes Bergf444de02010-05-05 15:25:02 +02001938static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1939{
1940 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001941 * You can only set the channel explicitly for WDS interfaces,
1942 * all others have their channel managed via their respective
1943 * "establish a connection" command (connect, join, ...)
1944 *
1945 * For AP/GO and mesh mode, the channel can be set with the
1946 * channel userspace API, but is only stored and passed to the
1947 * low-level driver when the AP starts or the mesh is joined.
1948 * This is for backward compatibility, userspace can also give
1949 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001950 *
1951 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001952 * whatever else is going on, so they have their own special
1953 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001954 */
1955 return !wdev ||
1956 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001957 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001958 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1959 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001960}
1961
Johannes Berg683b6d32012-11-08 21:25:48 +01001962static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1963 struct genl_info *info,
1964 struct cfg80211_chan_def *chandef)
1965{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301966 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001967
1968 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1969 return -EINVAL;
1970
1971 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1972
1973 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001974 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1975 chandef->center_freq1 = control_freq;
1976 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001977
1978 /* Primary channel not allowed */
1979 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1980 return -EINVAL;
1981
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001982 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1983 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001984
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001985 chantype = nla_get_u32(
1986 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1987
1988 switch (chantype) {
1989 case NL80211_CHAN_NO_HT:
1990 case NL80211_CHAN_HT20:
1991 case NL80211_CHAN_HT40PLUS:
1992 case NL80211_CHAN_HT40MINUS:
1993 cfg80211_chandef_create(chandef, chandef->chan,
1994 chantype);
1995 break;
1996 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001997 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001998 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001999 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2000 chandef->width =
2001 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2002 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2003 chandef->center_freq1 =
2004 nla_get_u32(
2005 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2006 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2007 chandef->center_freq2 =
2008 nla_get_u32(
2009 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2010 }
2011
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002012 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002013 return -EINVAL;
2014
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002015 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2016 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002017 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002018
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002019 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2020 chandef->width == NL80211_CHAN_WIDTH_10) &&
2021 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2022 return -EINVAL;
2023
Johannes Berg683b6d32012-11-08 21:25:48 +01002024 return 0;
2025}
2026
Johannes Bergf444de02010-05-05 15:25:02 +02002027static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002028 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002029 struct genl_info *info)
2030{
Johannes Berg683b6d32012-11-08 21:25:48 +01002031 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002032 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002033 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002034 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002035
Jouni Malinene16821b2014-04-28 11:22:08 +03002036 if (dev)
2037 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002038 if (!nl80211_can_set_dev_channel(wdev))
2039 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002040 if (wdev)
2041 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002042
Johannes Berg683b6d32012-11-08 21:25:48 +01002043 result = nl80211_parse_chandef(rdev, info, &chandef);
2044 if (result)
2045 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002046
Johannes Berge8c9bd52012-06-06 08:18:22 +02002047 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002048 case NL80211_IFTYPE_AP:
2049 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002050 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2051 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002052 result = -EINVAL;
2053 break;
2054 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002055 if (wdev->beacon_interval) {
2056 if (!dev || !rdev->ops->set_ap_chanwidth ||
2057 !(rdev->wiphy.features &
2058 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2059 result = -EBUSY;
2060 break;
2061 }
2062
2063 /* Only allow dynamic channel width changes */
2064 if (chandef.chan != wdev->preset_chandef.chan) {
2065 result = -EBUSY;
2066 break;
2067 }
2068 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2069 if (result)
2070 break;
2071 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002072 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002073 result = 0;
2074 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002075 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002076 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002077 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002078 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002079 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002080 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002081 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002082 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002083 }
Johannes Bergf444de02010-05-05 15:25:02 +02002084
2085 return result;
2086}
2087
2088static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2089{
Johannes Berg4c476992010-10-04 21:36:35 +02002090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2091 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002092
Jouni Malinene16821b2014-04-28 11:22:08 +03002093 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002094}
2095
Bill Jordane8347eb2010-10-01 13:54:28 -04002096static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2097{
Johannes Berg43b19952010-10-07 13:10:30 +02002098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2099 struct net_device *dev = info->user_ptr[1];
2100 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002101 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002102
2103 if (!info->attrs[NL80211_ATTR_MAC])
2104 return -EINVAL;
2105
Johannes Berg43b19952010-10-07 13:10:30 +02002106 if (netif_running(dev))
2107 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002108
Johannes Berg43b19952010-10-07 13:10:30 +02002109 if (!rdev->ops->set_wds_peer)
2110 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002111
Johannes Berg43b19952010-10-07 13:10:30 +02002112 if (wdev->iftype != NL80211_IFTYPE_WDS)
2113 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002114
2115 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002116 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002117}
2118
2119
Johannes Berg55682962007-09-20 13:09:35 -04002120static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2121{
2122 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002123 struct net_device *netdev = NULL;
2124 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002125 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002126 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002127 u32 changed;
2128 u8 retry_short = 0, retry_long = 0;
2129 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002130 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002131
Johannes Berg5fe231e2013-05-08 21:45:15 +02002132 ASSERT_RTNL();
2133
Johannes Bergf444de02010-05-05 15:25:02 +02002134 /*
2135 * Try to find the wiphy and netdev. Normally this
2136 * function shouldn't need the netdev, but this is
2137 * done for backward compatibility -- previously
2138 * setting the channel was done per wiphy, but now
2139 * it is per netdev. Previous userland like hostapd
2140 * also passed a netdev to set_wiphy, so that it is
2141 * possible to let that go to the right netdev!
2142 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002143
Johannes Bergf444de02010-05-05 15:25:02 +02002144 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2145 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2146
Ying Xue7f2b8562014-01-15 10:23:45 +08002147 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002148 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002149 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002150 else
Johannes Bergf444de02010-05-05 15:25:02 +02002151 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002152 }
2153
Johannes Bergf444de02010-05-05 15:25:02 +02002154 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002155 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2156 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002157 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002158 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002159 wdev = NULL;
2160 netdev = NULL;
2161 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002162 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002163 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002164
2165 /*
2166 * end workaround code, by now the rdev is available
2167 * and locked, and wdev may or may not be NULL.
2168 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002169
2170 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002171 result = cfg80211_dev_rename(
2172 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002173
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002174 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002176
Jouni Malinen31888482008-10-30 16:59:24 +02002177 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2178 struct ieee80211_txq_params txq_params;
2179 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2180
Ying Xue7f2b8562014-01-15 10:23:45 +08002181 if (!rdev->ops->set_txq_params)
2182 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002183
Ying Xue7f2b8562014-01-15 10:23:45 +08002184 if (!netdev)
2185 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002186
Johannes Berg133a3ff2011-11-03 14:50:13 +01002187 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002188 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2189 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002190
Ying Xue7f2b8562014-01-15 10:23:45 +08002191 if (!netif_running(netdev))
2192 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002193
Jouni Malinen31888482008-10-30 16:59:24 +02002194 nla_for_each_nested(nl_txq_params,
2195 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2196 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002197 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2198 nla_data(nl_txq_params),
2199 nla_len(nl_txq_params),
2200 txq_params_policy);
2201 if (result)
2202 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002203 result = parse_txq_params(tb, &txq_params);
2204 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002205 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002206
Hila Gonene35e4d22012-06-27 17:19:42 +03002207 result = rdev_set_txq_params(rdev, netdev,
2208 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002209 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002211 }
2212 }
2213
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002214 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002215 result = __nl80211_set_channel(
2216 rdev,
2217 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2218 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002219 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002220 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002221 }
2222
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002223 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002224 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002225 enum nl80211_tx_power_setting type;
2226 int idx, mbm = 0;
2227
Johannes Bergc8442112012-10-24 10:17:18 +02002228 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2229 txp_wdev = NULL;
2230
Ying Xue7f2b8562014-01-15 10:23:45 +08002231 if (!rdev->ops->set_tx_power)
2232 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002233
2234 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2235 type = nla_get_u32(info->attrs[idx]);
2236
2237 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 (type != NL80211_TX_POWER_AUTOMATIC))
2239 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002240
2241 if (type != NL80211_TX_POWER_AUTOMATIC) {
2242 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2243 mbm = nla_get_u32(info->attrs[idx]);
2244 }
2245
Johannes Bergc8442112012-10-24 10:17:18 +02002246 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002247 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002248 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002249 }
2250
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002251 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2252 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2253 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002254 if ((!rdev->wiphy.available_antennas_tx &&
2255 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002256 !rdev->ops->set_antenna)
2257 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002258
2259 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2260 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2261
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002262 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002263 * available antenna masks, except for the "all" mask */
2264 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002265 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2266 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002267
Bruno Randolf7f531e02010-12-16 11:30:22 +09002268 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2269 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002270
Hila Gonene35e4d22012-06-27 17:19:42 +03002271 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002272 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002273 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002274 }
2275
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002276 changed = 0;
2277
2278 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2279 retry_short = nla_get_u8(
2280 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002281 if (retry_short == 0)
2282 return -EINVAL;
2283
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002284 changed |= WIPHY_PARAM_RETRY_SHORT;
2285 }
2286
2287 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2288 retry_long = nla_get_u8(
2289 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002290 if (retry_long == 0)
2291 return -EINVAL;
2292
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002293 changed |= WIPHY_PARAM_RETRY_LONG;
2294 }
2295
2296 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2297 frag_threshold = nla_get_u32(
2298 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002299 if (frag_threshold < 256)
2300 return -EINVAL;
2301
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002302 if (frag_threshold != (u32) -1) {
2303 /*
2304 * Fragments (apart from the last one) are required to
2305 * have even length. Make the fragmentation code
2306 * simpler by stripping LSB should someone try to use
2307 * odd threshold value.
2308 */
2309 frag_threshold &= ~0x1;
2310 }
2311 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2312 }
2313
2314 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2315 rts_threshold = nla_get_u32(
2316 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2317 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2318 }
2319
Lukáš Turek81077e82009-12-21 22:50:47 +01002320 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002321 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2322 return -EINVAL;
2323
Lukáš Turek81077e82009-12-21 22:50:47 +01002324 coverage_class = nla_get_u8(
2325 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2326 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2327 }
2328
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002329 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2330 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2331 return -EOPNOTSUPP;
2332
2333 changed |= WIPHY_PARAM_DYN_ACK;
2334 }
2335
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002336 if (changed) {
2337 u8 old_retry_short, old_retry_long;
2338 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002339 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002340
Ying Xue7f2b8562014-01-15 10:23:45 +08002341 if (!rdev->ops->set_wiphy_params)
2342 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002343
2344 old_retry_short = rdev->wiphy.retry_short;
2345 old_retry_long = rdev->wiphy.retry_long;
2346 old_frag_threshold = rdev->wiphy.frag_threshold;
2347 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002348 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002349
2350 if (changed & WIPHY_PARAM_RETRY_SHORT)
2351 rdev->wiphy.retry_short = retry_short;
2352 if (changed & WIPHY_PARAM_RETRY_LONG)
2353 rdev->wiphy.retry_long = retry_long;
2354 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2355 rdev->wiphy.frag_threshold = frag_threshold;
2356 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2357 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002358 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2359 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002360
Hila Gonene35e4d22012-06-27 17:19:42 +03002361 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002362 if (result) {
2363 rdev->wiphy.retry_short = old_retry_short;
2364 rdev->wiphy.retry_long = old_retry_long;
2365 rdev->wiphy.frag_threshold = old_frag_threshold;
2366 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002367 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002368 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002369 }
2370 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002371 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002372}
2373
Johannes Berg71bbc992012-06-15 15:30:18 +02002374static inline u64 wdev_id(struct wireless_dev *wdev)
2375{
2376 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002377 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002378}
Johannes Berg55682962007-09-20 13:09:35 -04002379
Johannes Berg683b6d32012-11-08 21:25:48 +01002380static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002381 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002382{
Johannes Berg601555c2014-11-27 17:26:56 +01002383 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2384 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002385
Johannes Berg683b6d32012-11-08 21:25:48 +01002386 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2387 chandef->chan->center_freq))
2388 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002389 switch (chandef->width) {
2390 case NL80211_CHAN_WIDTH_20_NOHT:
2391 case NL80211_CHAN_WIDTH_20:
2392 case NL80211_CHAN_WIDTH_40:
2393 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2394 cfg80211_get_chandef_type(chandef)))
2395 return -ENOBUFS;
2396 break;
2397 default:
2398 break;
2399 }
2400 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2401 return -ENOBUFS;
2402 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2403 return -ENOBUFS;
2404 if (chandef->center_freq2 &&
2405 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002406 return -ENOBUFS;
2407 return 0;
2408}
2409
Eric W. Biederman15e47302012-09-07 20:12:54 +00002410static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002411 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002412 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002413{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002414 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002415 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002416 void *hdr;
2417
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002418 if (removal)
2419 cmd = NL80211_CMD_DEL_INTERFACE;
2420
2421 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002422 if (!hdr)
2423 return -1;
2424
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002425 if (dev &&
2426 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002427 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002428 goto nla_put_failure;
2429
2430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2431 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002432 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2433 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002434 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002435 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2436 rdev->devlist_generation ^
2437 (cfg80211_rdev_list_generation << 2)))
2438 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002439
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002440 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002441 int ret;
2442 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002443
Johannes Berg683b6d32012-11-08 21:25:48 +01002444 ret = rdev_get_channel(rdev, wdev, &chandef);
2445 if (ret == 0) {
2446 if (nl80211_send_chandef(msg, &chandef))
2447 goto nla_put_failure;
2448 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002449 }
2450
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002451 if (rdev->ops->get_tx_power) {
2452 int dbm, ret;
2453
2454 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2455 if (ret == 0 &&
2456 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2457 DBM_TO_MBM(dbm)))
2458 goto nla_put_failure;
2459 }
2460
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002461 if (wdev->ssid_len) {
2462 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2463 goto nla_put_failure;
2464 }
2465
Johannes Berg053c0952015-01-16 22:09:00 +01002466 genlmsg_end(msg, hdr);
2467 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002468
2469 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002470 genlmsg_cancel(msg, hdr);
2471 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002472}
2473
2474static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2475{
2476 int wp_idx = 0;
2477 int if_idx = 0;
2478 int wp_start = cb->args[0];
2479 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002480 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002481 struct wireless_dev *wdev;
2482
Johannes Berg5fe231e2013-05-08 21:45:15 +02002483 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002484 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2485 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002486 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002487 if (wp_idx < wp_start) {
2488 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002489 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002490 }
Johannes Berg55682962007-09-20 13:09:35 -04002491 if_idx = 0;
2492
Johannes Berg89a54e42012-06-15 14:33:17 +02002493 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002494 if (if_idx < if_start) {
2495 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002496 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002497 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002498 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002499 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002500 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002501 goto out;
2502 }
2503 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002504 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002505
2506 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002507 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002508 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002509 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002510
2511 cb->args[0] = wp_idx;
2512 cb->args[1] = if_idx;
2513
2514 return skb->len;
2515}
2516
2517static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2518{
2519 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002521 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002522
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002524 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002525 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002526
Eric W. Biederman15e47302012-09-07 20:12:54 +00002527 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002528 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002529 nlmsg_free(msg);
2530 return -ENOBUFS;
2531 }
Johannes Berg55682962007-09-20 13:09:35 -04002532
Johannes Berg134e6372009-07-10 09:51:34 +00002533 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002534}
2535
Michael Wu66f7ac52008-01-31 19:48:22 +01002536static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2537 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2538 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2539 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2540 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2541 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002542 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002543};
2544
2545static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2546{
2547 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2548 int flag;
2549
2550 *mntrflags = 0;
2551
2552 if (!nla)
2553 return -EINVAL;
2554
2555 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2556 nla, mntr_flags_policy))
2557 return -EINVAL;
2558
2559 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2560 if (flags[flag])
2561 *mntrflags |= (1<<flag);
2562
2563 return 0;
2564}
2565
Johannes Berg9bc383d2009-11-19 11:55:19 +01002566static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002567 struct net_device *netdev, u8 use_4addr,
2568 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002569{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002570 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002571 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002572 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002573 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002574 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002575
2576 switch (iftype) {
2577 case NL80211_IFTYPE_AP_VLAN:
2578 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2579 return 0;
2580 break;
2581 case NL80211_IFTYPE_STATION:
2582 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2583 return 0;
2584 break;
2585 default:
2586 break;
2587 }
2588
2589 return -EOPNOTSUPP;
2590}
2591
Johannes Berg55682962007-09-20 13:09:35 -04002592static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2593{
Johannes Berg4c476992010-10-04 21:36:35 +02002594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002595 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002596 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002597 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002598 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002599 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002600 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002601
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002602 memset(&params, 0, sizeof(params));
2603
Johannes Berg04a773a2009-04-19 21:24:32 +02002604 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002605
Johannes Berg723b0382008-09-16 20:22:09 +02002606 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002607 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002608 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002609 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002610 if (ntype > NL80211_IFTYPE_MAX)
2611 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002612 }
2613
Johannes Berg92ffe052008-09-16 20:39:36 +02002614 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002615 struct wireless_dev *wdev = dev->ieee80211_ptr;
2616
Johannes Berg4c476992010-10-04 21:36:35 +02002617 if (ntype != NL80211_IFTYPE_MESH_POINT)
2618 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002619 if (netif_running(dev))
2620 return -EBUSY;
2621
2622 wdev_lock(wdev);
2623 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2624 IEEE80211_MAX_MESH_ID_LEN);
2625 wdev->mesh_id_up_len =
2626 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2627 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2628 wdev->mesh_id_up_len);
2629 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002630 }
2631
Felix Fietkau8b787642009-11-10 18:53:10 +01002632 if (info->attrs[NL80211_ATTR_4ADDR]) {
2633 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2634 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002635 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002636 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002637 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002638 } else {
2639 params.use_4addr = -1;
2640 }
2641
Johannes Berg92ffe052008-09-16 20:39:36 +02002642 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002643 if (ntype != NL80211_IFTYPE_MONITOR)
2644 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002645 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2646 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002647 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002648 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002649
2650 flags = &_flags;
2651 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002652 }
Johannes Berg3b858752009-03-12 09:55:09 +01002653
Luciano Coelho18003292013-08-29 13:26:57 +03002654 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002655 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2656 return -EOPNOTSUPP;
2657
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002658 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002659 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002660 else
2661 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002662
Johannes Berg9bc383d2009-11-19 11:55:19 +01002663 if (!err && params.use_4addr != -1)
2664 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2665
Johannes Berg55682962007-09-20 13:09:35 -04002666 return err;
2667}
2668
2669static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2670{
Johannes Berg4c476992010-10-04 21:36:35 +02002671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002672 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002673 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002674 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002675 int err;
2676 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002677 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002678
Johannes Berg78f22b62014-03-24 17:57:27 +01002679 /* to avoid failing a new interface creation due to pending removal */
2680 cfg80211_destroy_ifaces(rdev);
2681
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002682 memset(&params, 0, sizeof(params));
2683
Johannes Berg55682962007-09-20 13:09:35 -04002684 if (!info->attrs[NL80211_ATTR_IFNAME])
2685 return -EINVAL;
2686
2687 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2688 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2689 if (type > NL80211_IFTYPE_MAX)
2690 return -EINVAL;
2691 }
2692
Johannes Berg79c97e92009-07-07 03:56:12 +02002693 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002694 !(rdev->wiphy.interface_modes & (1 << type)))
2695 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002696
Ben Greeare8f479b2014-10-22 12:23:05 -07002697 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2698 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2699 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002700 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2701 ETH_ALEN);
2702 if (!is_valid_ether_addr(params.macaddr))
2703 return -EADDRNOTAVAIL;
2704 }
2705
Johannes Berg9bc383d2009-11-19 11:55:19 +01002706 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002707 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002708 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002709 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002710 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002711 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002712
Michael Wu66f7ac52008-01-31 19:48:22 +01002713 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2714 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2715 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002716
Luciano Coelho18003292013-08-29 13:26:57 +03002717 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002718 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2719 return -EOPNOTSUPP;
2720
Johannes Berga18c7192015-02-24 10:56:42 +01002721 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2722 if (!msg)
2723 return -ENOMEM;
2724
Hila Gonene35e4d22012-06-27 17:19:42 +03002725 wdev = rdev_add_virtual_intf(rdev,
2726 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002727 NET_NAME_USER, type, err ? NULL : &flags,
2728 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002729 if (WARN_ON(!wdev)) {
2730 nlmsg_free(msg);
2731 return -EPROTO;
2732 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002733 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002734 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002735 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002736
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002737 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002738 wdev->owner_nlportid = info->snd_portid;
2739
Johannes Berg98104fde2012-06-16 00:19:54 +02002740 switch (type) {
2741 case NL80211_IFTYPE_MESH_POINT:
2742 if (!info->attrs[NL80211_ATTR_MESH_ID])
2743 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002744 wdev_lock(wdev);
2745 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2746 IEEE80211_MAX_MESH_ID_LEN);
2747 wdev->mesh_id_up_len =
2748 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2749 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2750 wdev->mesh_id_up_len);
2751 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002752 break;
2753 case NL80211_IFTYPE_P2P_DEVICE:
2754 /*
2755 * P2P Device doesn't have a netdev, so doesn't go
2756 * through the netdev notifier and must be added here
2757 */
2758 mutex_init(&wdev->mtx);
2759 INIT_LIST_HEAD(&wdev->event_list);
2760 spin_lock_init(&wdev->event_lock);
2761 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2762 spin_lock_init(&wdev->mgmt_registrations_lock);
2763
Johannes Berg98104fde2012-06-16 00:19:54 +02002764 wdev->identifier = ++rdev->wdev_id;
2765 list_add_rcu(&wdev->list, &rdev->wdev_list);
2766 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002767 break;
2768 default:
2769 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002770 }
2771
Eric W. Biederman15e47302012-09-07 20:12:54 +00002772 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002773 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002774 nlmsg_free(msg);
2775 return -ENOBUFS;
2776 }
2777
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002778 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2779 if (event) {
2780 if (nl80211_send_iface(event, 0, 0, 0,
2781 rdev, wdev, false) < 0) {
2782 nlmsg_free(event);
2783 goto out;
2784 }
2785
2786 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2787 event, 0, NL80211_MCGRP_CONFIG,
2788 GFP_KERNEL);
2789 }
2790
2791out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002792 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002793}
2794
2795static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2796{
Johannes Berg4c476992010-10-04 21:36:35 +02002797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002798 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002799 struct sk_buff *msg;
2800 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002801
Johannes Berg4c476992010-10-04 21:36:35 +02002802 if (!rdev->ops->del_virtual_intf)
2803 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002804
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2806 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2807 nlmsg_free(msg);
2808 msg = NULL;
2809 }
2810
Johannes Berg84efbb82012-06-16 00:00:26 +02002811 /*
2812 * If we remove a wireless device without a netdev then clear
2813 * user_ptr[1] so that nl80211_post_doit won't dereference it
2814 * to check if it needs to do dev_put(). Otherwise it crashes
2815 * since the wdev has been freed, unlike with a netdev where
2816 * we need the dev_put() for the netdev to really be freed.
2817 */
2818 if (!wdev->netdev)
2819 info->user_ptr[1] = NULL;
2820
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002821 status = rdev_del_virtual_intf(rdev, wdev);
2822 if (status >= 0 && msg)
2823 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2824 msg, 0, NL80211_MCGRP_CONFIG,
2825 GFP_KERNEL);
2826 else
2827 nlmsg_free(msg);
2828
2829 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002830}
2831
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002832static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2833{
2834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2835 struct net_device *dev = info->user_ptr[1];
2836 u16 noack_map;
2837
2838 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2839 return -EINVAL;
2840
2841 if (!rdev->ops->set_noack_map)
2842 return -EOPNOTSUPP;
2843
2844 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2845
Hila Gonene35e4d22012-06-27 17:19:42 +03002846 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002847}
2848
Johannes Berg41ade002007-12-19 02:03:29 +01002849struct get_key_cookie {
2850 struct sk_buff *msg;
2851 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002852 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002853};
2854
2855static void get_key_callback(void *c, struct key_params *params)
2856{
Johannes Bergb9454e82009-07-08 13:29:08 +02002857 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002858 struct get_key_cookie *cookie = c;
2859
David S. Miller9360ffd2012-03-29 04:41:26 -04002860 if ((params->key &&
2861 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2862 params->key_len, params->key)) ||
2863 (params->seq &&
2864 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2865 params->seq_len, params->seq)) ||
2866 (params->cipher &&
2867 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2868 params->cipher)))
2869 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002870
Johannes Bergb9454e82009-07-08 13:29:08 +02002871 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2872 if (!key)
2873 goto nla_put_failure;
2874
David S. Miller9360ffd2012-03-29 04:41:26 -04002875 if ((params->key &&
2876 nla_put(cookie->msg, NL80211_KEY_DATA,
2877 params->key_len, params->key)) ||
2878 (params->seq &&
2879 nla_put(cookie->msg, NL80211_KEY_SEQ,
2880 params->seq_len, params->seq)) ||
2881 (params->cipher &&
2882 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2883 params->cipher)))
2884 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002885
David S. Miller9360ffd2012-03-29 04:41:26 -04002886 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2887 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002888
2889 nla_nest_end(cookie->msg, key);
2890
Johannes Berg41ade002007-12-19 02:03:29 +01002891 return;
2892 nla_put_failure:
2893 cookie->error = 1;
2894}
2895
2896static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2897{
Johannes Berg4c476992010-10-04 21:36:35 +02002898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002899 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002900 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002901 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002902 const u8 *mac_addr = NULL;
2903 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002904 struct get_key_cookie cookie = {
2905 .error = 0,
2906 };
2907 void *hdr;
2908 struct sk_buff *msg;
2909
2910 if (info->attrs[NL80211_ATTR_KEY_IDX])
2911 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2912
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002913 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return -EINVAL;
2915
2916 if (info->attrs[NL80211_ATTR_MAC])
2917 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2918
Johannes Berge31b8212010-10-05 19:39:30 +02002919 pairwise = !!mac_addr;
2920 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2921 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2922 if (kt >= NUM_NL80211_KEYTYPES)
2923 return -EINVAL;
2924 if (kt != NL80211_KEYTYPE_GROUP &&
2925 kt != NL80211_KEYTYPE_PAIRWISE)
2926 return -EINVAL;
2927 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2928 }
2929
Johannes Berg4c476992010-10-04 21:36:35 +02002930 if (!rdev->ops->get_key)
2931 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002932
Johannes Berg0fa7b392015-01-23 11:10:12 +01002933 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2934 return -ENOENT;
2935
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002936 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002937 if (!msg)
2938 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002939
Eric W. Biederman15e47302012-09-07 20:12:54 +00002940 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002941 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002942 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002943 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002944
2945 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002946 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002947
David S. Miller9360ffd2012-03-29 04:41:26 -04002948 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2949 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2950 goto nla_put_failure;
2951 if (mac_addr &&
2952 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2953 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002954
Hila Gonene35e4d22012-06-27 17:19:42 +03002955 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2956 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002957
2958 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002959 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002960
2961 if (cookie.error)
2962 goto nla_put_failure;
2963
2964 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002965 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002966
2967 nla_put_failure:
2968 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002969 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002970 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002971 return err;
2972}
2973
2974static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2975{
Johannes Berg4c476992010-10-04 21:36:35 +02002976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002977 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002978 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002979 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002980
Johannes Bergb9454e82009-07-08 13:29:08 +02002981 err = nl80211_parse_key(info, &key);
2982 if (err)
2983 return err;
2984
2985 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002986 return -EINVAL;
2987
Johannes Bergb9454e82009-07-08 13:29:08 +02002988 /* only support setting default key */
2989 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002990 return -EINVAL;
2991
Johannes Bergfffd0932009-07-08 14:22:54 +02002992 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002993
2994 if (key.def) {
2995 if (!rdev->ops->set_default_key) {
2996 err = -EOPNOTSUPP;
2997 goto out;
2998 }
2999
3000 err = nl80211_key_allowed(dev->ieee80211_ptr);
3001 if (err)
3002 goto out;
3003
Hila Gonene35e4d22012-06-27 17:19:42 +03003004 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003005 key.def_uni, key.def_multi);
3006
3007 if (err)
3008 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003009
Johannes Berg3d23e342009-09-29 23:27:28 +02003010#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003011 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003012#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003013 } else {
3014 if (key.def_uni || !key.def_multi) {
3015 err = -EINVAL;
3016 goto out;
3017 }
3018
3019 if (!rdev->ops->set_default_mgmt_key) {
3020 err = -EOPNOTSUPP;
3021 goto out;
3022 }
3023
3024 err = nl80211_key_allowed(dev->ieee80211_ptr);
3025 if (err)
3026 goto out;
3027
Hila Gonene35e4d22012-06-27 17:19:42 +03003028 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003029 if (err)
3030 goto out;
3031
3032#ifdef CONFIG_CFG80211_WEXT
3033 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3034#endif
3035 }
3036
3037 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003038 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003039
Johannes Berg41ade002007-12-19 02:03:29 +01003040 return err;
3041}
3042
3043static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3044{
Johannes Berg4c476992010-10-04 21:36:35 +02003045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003046 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003047 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003048 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003049 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003050
Johannes Bergb9454e82009-07-08 13:29:08 +02003051 err = nl80211_parse_key(info, &key);
3052 if (err)
3053 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003054
Johannes Bergb9454e82009-07-08 13:29:08 +02003055 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003056 return -EINVAL;
3057
Johannes Berg41ade002007-12-19 02:03:29 +01003058 if (info->attrs[NL80211_ATTR_MAC])
3059 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3060
Johannes Berge31b8212010-10-05 19:39:30 +02003061 if (key.type == -1) {
3062 if (mac_addr)
3063 key.type = NL80211_KEYTYPE_PAIRWISE;
3064 else
3065 key.type = NL80211_KEYTYPE_GROUP;
3066 }
3067
3068 /* for now */
3069 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3070 key.type != NL80211_KEYTYPE_GROUP)
3071 return -EINVAL;
3072
Johannes Berg4c476992010-10-04 21:36:35 +02003073 if (!rdev->ops->add_key)
3074 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003075
Johannes Berge31b8212010-10-05 19:39:30 +02003076 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3077 key.type == NL80211_KEYTYPE_PAIRWISE,
3078 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003079 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003080
3081 wdev_lock(dev->ieee80211_ptr);
3082 err = nl80211_key_allowed(dev->ieee80211_ptr);
3083 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003084 err = rdev_add_key(rdev, dev, key.idx,
3085 key.type == NL80211_KEYTYPE_PAIRWISE,
3086 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003087 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003088
Johannes Berg41ade002007-12-19 02:03:29 +01003089 return err;
3090}
3091
3092static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3093{
Johannes Berg4c476992010-10-04 21:36:35 +02003094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003095 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003096 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003097 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003098 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003099
Johannes Bergb9454e82009-07-08 13:29:08 +02003100 err = nl80211_parse_key(info, &key);
3101 if (err)
3102 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003103
3104 if (info->attrs[NL80211_ATTR_MAC])
3105 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3106
Johannes Berge31b8212010-10-05 19:39:30 +02003107 if (key.type == -1) {
3108 if (mac_addr)
3109 key.type = NL80211_KEYTYPE_PAIRWISE;
3110 else
3111 key.type = NL80211_KEYTYPE_GROUP;
3112 }
3113
3114 /* for now */
3115 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3116 key.type != NL80211_KEYTYPE_GROUP)
3117 return -EINVAL;
3118
Johannes Berg4c476992010-10-04 21:36:35 +02003119 if (!rdev->ops->del_key)
3120 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003121
Johannes Bergfffd0932009-07-08 14:22:54 +02003122 wdev_lock(dev->ieee80211_ptr);
3123 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003124
Johannes Berg0fa7b392015-01-23 11:10:12 +01003125 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003126 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3127 err = -ENOENT;
3128
Johannes Bergfffd0932009-07-08 14:22:54 +02003129 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003130 err = rdev_del_key(rdev, dev, key.idx,
3131 key.type == NL80211_KEYTYPE_PAIRWISE,
3132 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003133
Johannes Berg3d23e342009-09-29 23:27:28 +02003134#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003135 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003136 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003137 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003138 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003139 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3140 }
3141#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003142 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003143
Johannes Berg41ade002007-12-19 02:03:29 +01003144 return err;
3145}
3146
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303147/* This function returns an error or the number of nested attributes */
3148static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3149{
3150 struct nlattr *attr;
3151 int n_entries = 0, tmp;
3152
3153 nla_for_each_nested(attr, nl_attr, tmp) {
3154 if (nla_len(attr) != ETH_ALEN)
3155 return -EINVAL;
3156
3157 n_entries++;
3158 }
3159
3160 return n_entries;
3161}
3162
3163/*
3164 * This function parses ACL information and allocates memory for ACL data.
3165 * On successful return, the calling function is responsible to free the
3166 * ACL buffer returned by this function.
3167 */
3168static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3169 struct genl_info *info)
3170{
3171 enum nl80211_acl_policy acl_policy;
3172 struct nlattr *attr;
3173 struct cfg80211_acl_data *acl;
3174 int i = 0, n_entries, tmp;
3175
3176 if (!wiphy->max_acl_mac_addrs)
3177 return ERR_PTR(-EOPNOTSUPP);
3178
3179 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3180 return ERR_PTR(-EINVAL);
3181
3182 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3183 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3184 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3185 return ERR_PTR(-EINVAL);
3186
3187 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3188 return ERR_PTR(-EINVAL);
3189
3190 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3191 if (n_entries < 0)
3192 return ERR_PTR(n_entries);
3193
3194 if (n_entries > wiphy->max_acl_mac_addrs)
3195 return ERR_PTR(-ENOTSUPP);
3196
3197 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3198 GFP_KERNEL);
3199 if (!acl)
3200 return ERR_PTR(-ENOMEM);
3201
3202 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3203 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3204 i++;
3205 }
3206
3207 acl->n_acl_entries = n_entries;
3208 acl->acl_policy = acl_policy;
3209
3210 return acl;
3211}
3212
3213static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3214{
3215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3216 struct net_device *dev = info->user_ptr[1];
3217 struct cfg80211_acl_data *acl;
3218 int err;
3219
3220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3222 return -EOPNOTSUPP;
3223
3224 if (!dev->ieee80211_ptr->beacon_interval)
3225 return -EINVAL;
3226
3227 acl = parse_acl_data(&rdev->wiphy, info);
3228 if (IS_ERR(acl))
3229 return PTR_ERR(acl);
3230
3231 err = rdev_set_mac_acl(rdev, dev, acl);
3232
3233 kfree(acl);
3234
3235 return err;
3236}
3237
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003238static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003239 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003240{
Johannes Berg88600202012-02-13 15:17:18 +01003241 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003242
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003243 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3244 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3245 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3246 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003247 return -EINVAL;
3248
Johannes Berg88600202012-02-13 15:17:18 +01003249 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003250
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003251 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3252 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3253 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003254 if (!bcn->head_len)
3255 return -EINVAL;
3256 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003257 }
3258
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003259 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3260 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3261 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003262 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003263 }
3264
Johannes Berg4c476992010-10-04 21:36:35 +02003265 if (!haveinfo)
3266 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003267
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003268 if (attrs[NL80211_ATTR_IE]) {
3269 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3270 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003271 }
3272
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003273 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003274 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003275 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003276 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003277 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003278 }
3279
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003280 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003281 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003282 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003283 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003284 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003285 }
3286
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003287 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3288 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3289 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003290 }
3291
Johannes Berg88600202012-02-13 15:17:18 +01003292 return 0;
3293}
3294
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003295static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3296 struct cfg80211_ap_settings *params)
3297{
3298 struct wireless_dev *wdev;
3299 bool ret = false;
3300
Johannes Berg89a54e42012-06-15 14:33:17 +02003301 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003302 if (wdev->iftype != NL80211_IFTYPE_AP &&
3303 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3304 continue;
3305
Johannes Berg683b6d32012-11-08 21:25:48 +01003306 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003307 continue;
3308
Johannes Berg683b6d32012-11-08 21:25:48 +01003309 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003310 ret = true;
3311 break;
3312 }
3313
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003314 return ret;
3315}
3316
Jouni Malinene39e5b52012-09-30 19:29:39 +03003317static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3318 enum nl80211_auth_type auth_type,
3319 enum nl80211_commands cmd)
3320{
3321 if (auth_type > NL80211_AUTHTYPE_MAX)
3322 return false;
3323
3324 switch (cmd) {
3325 case NL80211_CMD_AUTHENTICATE:
3326 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3327 auth_type == NL80211_AUTHTYPE_SAE)
3328 return false;
3329 return true;
3330 case NL80211_CMD_CONNECT:
3331 case NL80211_CMD_START_AP:
3332 /* SAE not supported yet */
3333 if (auth_type == NL80211_AUTHTYPE_SAE)
3334 return false;
3335 return true;
3336 default:
3337 return false;
3338 }
3339}
3340
Johannes Berg88600202012-02-13 15:17:18 +01003341static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3342{
3343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3344 struct net_device *dev = info->user_ptr[1];
3345 struct wireless_dev *wdev = dev->ieee80211_ptr;
3346 struct cfg80211_ap_settings params;
3347 int err;
3348
3349 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3350 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3351 return -EOPNOTSUPP;
3352
3353 if (!rdev->ops->start_ap)
3354 return -EOPNOTSUPP;
3355
3356 if (wdev->beacon_interval)
3357 return -EALREADY;
3358
3359 memset(&params, 0, sizeof(params));
3360
3361 /* these are required for START_AP */
3362 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3363 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3364 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3365 return -EINVAL;
3366
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003367 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003368 if (err)
3369 return err;
3370
3371 params.beacon_interval =
3372 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3373 params.dtim_period =
3374 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3375
3376 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3377 if (err)
3378 return err;
3379
3380 /*
3381 * In theory, some of these attributes should be required here
3382 * but since they were not used when the command was originally
3383 * added, keep them optional for old user space programs to let
3384 * them continue to work with drivers that do not need the
3385 * additional information -- drivers must check!
3386 */
3387 if (info->attrs[NL80211_ATTR_SSID]) {
3388 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3389 params.ssid_len =
3390 nla_len(info->attrs[NL80211_ATTR_SSID]);
3391 if (params.ssid_len == 0 ||
3392 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3393 return -EINVAL;
3394 }
3395
3396 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3397 params.hidden_ssid = nla_get_u32(
3398 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3399 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3400 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3401 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3402 return -EINVAL;
3403 }
3404
3405 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3406
3407 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3408 params.auth_type = nla_get_u32(
3409 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003410 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3411 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003412 return -EINVAL;
3413 } else
3414 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3415
3416 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3417 NL80211_MAX_NR_CIPHER_SUITES);
3418 if (err)
3419 return err;
3420
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303421 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3422 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3423 return -EOPNOTSUPP;
3424 params.inactivity_timeout = nla_get_u16(
3425 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3426 }
3427
Johannes Berg53cabad2012-11-14 15:17:28 +01003428 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3429 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3430 return -EINVAL;
3431 params.p2p_ctwindow =
3432 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3433 if (params.p2p_ctwindow > 127)
3434 return -EINVAL;
3435 if (params.p2p_ctwindow != 0 &&
3436 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3437 return -EINVAL;
3438 }
3439
3440 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3441 u8 tmp;
3442
3443 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3444 return -EINVAL;
3445 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3446 if (tmp > 1)
3447 return -EINVAL;
3448 params.p2p_opp_ps = tmp;
3449 if (params.p2p_opp_ps != 0 &&
3450 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3451 return -EINVAL;
3452 }
3453
Johannes Bergaa430da2012-05-16 23:50:18 +02003454 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003455 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3456 if (err)
3457 return err;
3458 } else if (wdev->preset_chandef.chan) {
3459 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003460 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003461 return -EINVAL;
3462
Arik Nemtsov923b3522015-07-08 15:41:44 +03003463 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3464 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003465 return -EINVAL;
3466
Eliad Peller18998c32014-09-10 14:07:34 +03003467 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3468 params.smps_mode =
3469 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3470 switch (params.smps_mode) {
3471 case NL80211_SMPS_OFF:
3472 break;
3473 case NL80211_SMPS_STATIC:
3474 if (!(rdev->wiphy.features &
3475 NL80211_FEATURE_STATIC_SMPS))
3476 return -EINVAL;
3477 break;
3478 case NL80211_SMPS_DYNAMIC:
3479 if (!(rdev->wiphy.features &
3480 NL80211_FEATURE_DYNAMIC_SMPS))
3481 return -EINVAL;
3482 break;
3483 default:
3484 return -EINVAL;
3485 }
3486 } else {
3487 params.smps_mode = NL80211_SMPS_OFF;
3488 }
3489
Ola Olsson4baf6be2015-10-29 07:04:58 +01003490 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3491 params.acl = parse_acl_data(&rdev->wiphy, info);
3492 if (IS_ERR(params.acl))
3493 return PTR_ERR(params.acl);
3494 }
3495
Lior David34d50512016-01-28 10:58:25 +02003496 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02003497 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
Lior David34d50512016-01-28 10:58:25 +02003498 return -EOPNOTSUPP;
3499
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003500 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003501 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003502 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003503 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003504 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003505 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003506 wdev->ssid_len = params.ssid_len;
3507 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003508 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003509 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303510
3511 kfree(params.acl);
3512
Johannes Berg56d18932011-05-09 18:41:15 +02003513 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003514}
3515
Johannes Berg88600202012-02-13 15:17:18 +01003516static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3517{
3518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3519 struct net_device *dev = info->user_ptr[1];
3520 struct wireless_dev *wdev = dev->ieee80211_ptr;
3521 struct cfg80211_beacon_data params;
3522 int err;
3523
3524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3526 return -EOPNOTSUPP;
3527
3528 if (!rdev->ops->change_beacon)
3529 return -EOPNOTSUPP;
3530
3531 if (!wdev->beacon_interval)
3532 return -EINVAL;
3533
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003534 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003535 if (err)
3536 return err;
3537
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003538 wdev_lock(wdev);
3539 err = rdev_change_beacon(rdev, dev, &params);
3540 wdev_unlock(wdev);
3541
3542 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003543}
3544
3545static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003546{
Johannes Berg4c476992010-10-04 21:36:35 +02003547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3548 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003549
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003550 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003551}
3552
Johannes Berg5727ef12007-12-19 02:03:34 +01003553static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3554 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3555 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3556 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003557 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003558 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003559 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003560};
3561
Johannes Bergeccb8e82009-05-11 21:57:56 +03003562static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003563 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003564 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003565{
3566 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003567 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003568 int flag;
3569
Johannes Bergeccb8e82009-05-11 21:57:56 +03003570 /*
3571 * Try parsing the new attribute first so userspace
3572 * can specify both for older kernels.
3573 */
3574 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3575 if (nla) {
3576 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003577
Johannes Bergeccb8e82009-05-11 21:57:56 +03003578 sta_flags = nla_data(nla);
3579 params->sta_flags_mask = sta_flags->mask;
3580 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003581 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003582 if ((params->sta_flags_mask |
3583 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3584 return -EINVAL;
3585 return 0;
3586 }
3587
3588 /* if present, parse the old attribute */
3589
3590 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003591 if (!nla)
3592 return 0;
3593
3594 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3595 nla, sta_flags_policy))
3596 return -EINVAL;
3597
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003598 /*
3599 * Only allow certain flags for interface types so that
3600 * other attributes are silently ignored. Remember that
3601 * this is backward compatibility code with old userspace
3602 * and shouldn't be hit in other cases anyway.
3603 */
3604 switch (iftype) {
3605 case NL80211_IFTYPE_AP:
3606 case NL80211_IFTYPE_AP_VLAN:
3607 case NL80211_IFTYPE_P2P_GO:
3608 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3609 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3610 BIT(NL80211_STA_FLAG_WME) |
3611 BIT(NL80211_STA_FLAG_MFP);
3612 break;
3613 case NL80211_IFTYPE_P2P_CLIENT:
3614 case NL80211_IFTYPE_STATION:
3615 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3616 BIT(NL80211_STA_FLAG_TDLS_PEER);
3617 break;
3618 case NL80211_IFTYPE_MESH_POINT:
3619 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3620 BIT(NL80211_STA_FLAG_MFP) |
3621 BIT(NL80211_STA_FLAG_AUTHORIZED);
3622 default:
3623 return -EINVAL;
3624 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003625
Johannes Berg3383b5a2012-05-10 20:14:43 +02003626 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3627 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003628 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003629
Johannes Berg3383b5a2012-05-10 20:14:43 +02003630 /* no longer support new API additions in old API */
3631 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3632 return -EINVAL;
3633 }
3634 }
3635
Johannes Berg5727ef12007-12-19 02:03:34 +01003636 return 0;
3637}
3638
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003639static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3640 int attr)
3641{
3642 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003643 u32 bitrate;
3644 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003645 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003646
3647 rate = nla_nest_start(msg, attr);
3648 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003649 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003650
3651 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3652 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003653 /* report 16-bit bitrate only if we can */
3654 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003655 if (bitrate > 0 &&
3656 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3657 return false;
3658 if (bitrate_compat > 0 &&
3659 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3660 return false;
3661
Johannes Bergb51f3be2015-01-15 16:14:02 +01003662 switch (info->bw) {
3663 case RATE_INFO_BW_5:
3664 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3665 break;
3666 case RATE_INFO_BW_10:
3667 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3668 break;
3669 default:
3670 WARN_ON(1);
3671 /* fall through */
3672 case RATE_INFO_BW_20:
3673 rate_flg = 0;
3674 break;
3675 case RATE_INFO_BW_40:
3676 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3677 break;
3678 case RATE_INFO_BW_80:
3679 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3680 break;
3681 case RATE_INFO_BW_160:
3682 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3683 break;
3684 }
3685
3686 if (rate_flg && nla_put_flag(msg, rate_flg))
3687 return false;
3688
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003689 if (info->flags & RATE_INFO_FLAGS_MCS) {
3690 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3691 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003692 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3693 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3694 return false;
3695 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3696 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3697 return false;
3698 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3699 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003700 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3701 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3702 return false;
3703 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003704
3705 nla_nest_end(msg, rate);
3706 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003707}
3708
Felix Fietkau119363c2013-04-22 16:29:30 +02003709static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3710 int id)
3711{
3712 void *attr;
3713 int i = 0;
3714
3715 if (!mask)
3716 return true;
3717
3718 attr = nla_nest_start(msg, id);
3719 if (!attr)
3720 return false;
3721
3722 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3723 if (!(mask & BIT(i)))
3724 continue;
3725
3726 if (nla_put_u8(msg, i, signal[i]))
3727 return false;
3728 }
3729
3730 nla_nest_end(msg, attr);
3731
3732 return true;
3733}
3734
Johannes Bergcf5ead82014-11-14 17:14:00 +01003735static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3736 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003737 struct cfg80211_registered_device *rdev,
3738 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003739 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003740{
3741 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003742 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003743
Johannes Bergcf5ead82014-11-14 17:14:00 +01003744 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003745 if (!hdr)
3746 return -1;
3747
David S. Miller9360ffd2012-03-29 04:41:26 -04003748 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3750 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3751 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003752
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003753 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3754 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003755 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003756
3757#define PUT_SINFO(attr, memb, type) do { \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303758 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003759 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3760 sinfo->memb)) \
3761 goto nla_put_failure; \
3762 } while (0)
3763
3764 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3765 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3766
3767 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3768 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003769 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003770 (u32)sinfo->rx_bytes))
3771 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003772
3773 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3774 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003775 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3776 (u32)sinfo->tx_bytes))
3777 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003778
3779 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3780 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3781 PUT_SINFO(LLID, llid, u16);
3782 PUT_SINFO(PLID, plid, u16);
3783 PUT_SINFO(PLINK_STATE, plink_state, u8);
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303784 PUT_SINFO(RX_DURATION, rx_duration, u64);
Johannes Berg319090b2014-11-17 14:08:11 +01003785
John W. Linville66266b32012-03-15 13:25:41 -04003786 switch (rdev->wiphy.signal_type) {
3787 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003788 PUT_SINFO(SIGNAL, signal, u8);
3789 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003790 break;
3791 default:
3792 break;
3793 }
Johannes Berg319090b2014-11-17 14:08:11 +01003794 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003795 if (!nl80211_put_signal(msg, sinfo->chains,
3796 sinfo->chain_signal,
3797 NL80211_STA_INFO_CHAIN_SIGNAL))
3798 goto nla_put_failure;
3799 }
Johannes Berg319090b2014-11-17 14:08:11 +01003800 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003801 if (!nl80211_put_signal(msg, sinfo->chains,
3802 sinfo->chain_signal_avg,
3803 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3804 goto nla_put_failure;
3805 }
Johannes Berg319090b2014-11-17 14:08:11 +01003806 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003807 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3808 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003809 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003810 }
Johannes Berg319090b2014-11-17 14:08:11 +01003811 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003812 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3813 NL80211_STA_INFO_RX_BITRATE))
3814 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003815 }
Johannes Berg319090b2014-11-17 14:08:11 +01003816
3817 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3818 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3819 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3820 PUT_SINFO(TX_FAILED, tx_failed, u32);
3821 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3822 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3823 PUT_SINFO(LOCAL_PM, local_pm, u32);
3824 PUT_SINFO(PEER_PM, peer_pm, u32);
3825 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3826
3827 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003828 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3829 if (!bss_param)
3830 goto nla_put_failure;
3831
David S. Miller9360ffd2012-03-29 04:41:26 -04003832 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3833 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3834 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3835 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3836 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3837 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3838 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3839 sinfo->bss_param.dtim_period) ||
3840 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3841 sinfo->bss_param.beacon_interval))
3842 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003843
3844 nla_nest_end(msg, bss_param);
3845 }
Johannes Berg319090b2014-11-17 14:08:11 +01003846 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003847 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3848 sizeof(struct nl80211_sta_flag_update),
3849 &sinfo->sta_flags))
3850 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003851
3852 PUT_SINFO(T_OFFSET, t_offset, u64);
3853 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003854 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3855 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003856
3857#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003858
3859 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3860 struct nlattr *tidsattr;
3861 int tid;
3862
3863 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3864 if (!tidsattr)
3865 goto nla_put_failure;
3866
3867 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3868 struct cfg80211_tid_stats *tidstats;
3869 struct nlattr *tidattr;
3870
3871 tidstats = &sinfo->pertid[tid];
3872
3873 if (!tidstats->filled)
3874 continue;
3875
3876 tidattr = nla_nest_start(msg, tid + 1);
3877 if (!tidattr)
3878 goto nla_put_failure;
3879
3880#define PUT_TIDVAL(attr, memb, type) do { \
3881 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3882 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3883 tidstats->memb)) \
3884 goto nla_put_failure; \
3885 } while (0)
3886
3887 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3888 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3889 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3890 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3891
3892#undef PUT_TIDVAL
3893 nla_nest_end(msg, tidattr);
3894 }
3895
3896 nla_nest_end(msg, tidsattr);
3897 }
3898
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003899 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003900
Johannes Berg319090b2014-11-17 14:08:11 +01003901 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003902 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3903 sinfo->assoc_req_ies))
3904 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003905
Johannes Berg053c0952015-01-16 22:09:00 +01003906 genlmsg_end(msg, hdr);
3907 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003908
3909 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003910 genlmsg_cancel(msg, hdr);
3911 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003912}
3913
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003914static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003915 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003916{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003917 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003918 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003919 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003920 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003921 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003922 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003923
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003924 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003925 if (err)
3926 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003927
Johannes Berg97990a02013-04-19 01:02:55 +02003928 if (!wdev->netdev) {
3929 err = -EINVAL;
3930 goto out_err;
3931 }
3932
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003933 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003934 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003935 goto out_err;
3936 }
3937
Johannes Bergbba95fe2008-07-29 13:22:51 +02003938 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003939 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003940 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003941 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003942 if (err == -ENOENT)
3943 break;
3944 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003945 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003946
Johannes Bergcf5ead82014-11-14 17:14:00 +01003947 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003948 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003949 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003950 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003951 &sinfo) < 0)
3952 goto out;
3953
3954 sta_idx++;
3955 }
3956
3957
3958 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003959 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003960 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003961 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003962 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003963
3964 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003965}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003966
Johannes Berg5727ef12007-12-19 02:03:34 +01003967static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3968{
Johannes Berg4c476992010-10-04 21:36:35 +02003969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3970 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003971 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003972 struct sk_buff *msg;
3973 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003974 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003975
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003976 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003977
3978 if (!info->attrs[NL80211_ATTR_MAC])
3979 return -EINVAL;
3980
3981 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3982
Johannes Berg4c476992010-10-04 21:36:35 +02003983 if (!rdev->ops->get_station)
3984 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003985
Hila Gonene35e4d22012-06-27 17:19:42 +03003986 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003987 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003988 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003989
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003990 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003991 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003992 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003993
Johannes Bergcf5ead82014-11-14 17:14:00 +01003994 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3995 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003996 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003997 nlmsg_free(msg);
3998 return -ENOBUFS;
3999 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004000
Johannes Berg4c476992010-10-04 21:36:35 +02004001 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004002}
4003
Johannes Berg77ee7c82013-02-15 00:48:33 +01004004int cfg80211_check_station_change(struct wiphy *wiphy,
4005 struct station_parameters *params,
4006 enum cfg80211_station_type statype)
4007{
Ayala Bekere4208422015-10-23 11:20:06 +03004008 if (params->listen_interval != -1 &&
4009 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004010 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004011
Ayala Beker17b94242016-03-17 15:41:38 +02004012 if (params->support_p2p_ps != -1 &&
4013 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4014 return -EINVAL;
4015
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004016 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004017 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4018 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004019 return -EINVAL;
4020
4021 /* When you run into this, adjust the code below for the new flag */
4022 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4023
4024 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004025 case CFG80211_STA_MESH_PEER_KERNEL:
4026 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004027 /*
4028 * No ignoring the TDLS flag here -- the userspace mesh
4029 * code doesn't have the bug of including TDLS in the
4030 * mask everywhere.
4031 */
4032 if (params->sta_flags_mask &
4033 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4034 BIT(NL80211_STA_FLAG_MFP) |
4035 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4036 return -EINVAL;
4037 break;
4038 case CFG80211_STA_TDLS_PEER_SETUP:
4039 case CFG80211_STA_TDLS_PEER_ACTIVE:
4040 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4041 return -EINVAL;
4042 /* ignore since it can't change */
4043 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4044 break;
4045 default:
4046 /* disallow mesh-specific things */
4047 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4048 return -EINVAL;
4049 if (params->local_pm)
4050 return -EINVAL;
4051 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4052 return -EINVAL;
4053 }
4054
4055 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4056 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4057 /* TDLS can't be set, ... */
4058 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4059 return -EINVAL;
4060 /*
4061 * ... but don't bother the driver with it. This works around
4062 * a hostapd/wpa_supplicant issue -- it always includes the
4063 * TLDS_PEER flag in the mask even for AP mode.
4064 */
4065 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4066 }
4067
Ayala Beker47edb112015-09-21 15:49:53 +03004068 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4069 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004070 /* reject other things that can't change */
4071 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4072 return -EINVAL;
4073 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4074 return -EINVAL;
4075 if (params->supported_rates)
4076 return -EINVAL;
4077 if (params->ext_capab || params->ht_capa || params->vht_capa)
4078 return -EINVAL;
4079 }
4080
Ayala Beker47edb112015-09-21 15:49:53 +03004081 if (statype != CFG80211_STA_AP_CLIENT &&
4082 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004083 if (params->vlan)
4084 return -EINVAL;
4085 }
4086
4087 switch (statype) {
4088 case CFG80211_STA_AP_MLME_CLIENT:
4089 /* Use this only for authorizing/unauthorizing a station */
4090 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4091 return -EOPNOTSUPP;
4092 break;
4093 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004094 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004095 /* accept only the listed bits */
4096 if (params->sta_flags_mask &
4097 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4098 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4099 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4100 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4101 BIT(NL80211_STA_FLAG_WME) |
4102 BIT(NL80211_STA_FLAG_MFP)))
4103 return -EINVAL;
4104
4105 /* but authenticated/associated only if driver handles it */
4106 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4107 params->sta_flags_mask &
4108 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4109 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4110 return -EINVAL;
4111 break;
4112 case CFG80211_STA_IBSS:
4113 case CFG80211_STA_AP_STA:
4114 /* reject any changes other than AUTHORIZED */
4115 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4116 return -EINVAL;
4117 break;
4118 case CFG80211_STA_TDLS_PEER_SETUP:
4119 /* reject any changes other than AUTHORIZED or WME */
4120 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4121 BIT(NL80211_STA_FLAG_WME)))
4122 return -EINVAL;
4123 /* force (at least) rates when authorizing */
4124 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4125 !params->supported_rates)
4126 return -EINVAL;
4127 break;
4128 case CFG80211_STA_TDLS_PEER_ACTIVE:
4129 /* reject any changes */
4130 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004131 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004132 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4133 return -EINVAL;
4134 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004135 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004136 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4137 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004138 return -EINVAL;
4139 break;
4140 }
4141
4142 return 0;
4143}
4144EXPORT_SYMBOL(cfg80211_check_station_change);
4145
Johannes Berg5727ef12007-12-19 02:03:34 +01004146/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004147 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004148 */
Johannes Berg80b99892011-11-18 16:23:01 +01004149static struct net_device *get_vlan(struct genl_info *info,
4150 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004151{
Johannes Berg463d0182009-07-14 00:33:35 +02004152 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004153 struct net_device *v;
4154 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004155
Johannes Berg80b99892011-11-18 16:23:01 +01004156 if (!vlanattr)
4157 return NULL;
4158
4159 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4160 if (!v)
4161 return ERR_PTR(-ENODEV);
4162
4163 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4164 ret = -EINVAL;
4165 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004166 }
Johannes Berg80b99892011-11-18 16:23:01 +01004167
Johannes Berg77ee7c82013-02-15 00:48:33 +01004168 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4169 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4170 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4171 ret = -EINVAL;
4172 goto error;
4173 }
4174
Johannes Berg80b99892011-11-18 16:23:01 +01004175 if (!netif_running(v)) {
4176 ret = -ENETDOWN;
4177 goto error;
4178 }
4179
4180 return v;
4181 error:
4182 dev_put(v);
4183 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004184}
4185
Johannes Berg94e860f2014-01-20 23:58:15 +01004186static const struct nla_policy
4187nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004188 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4189 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4190};
4191
Johannes Bergff276692013-02-15 00:09:01 +01004192static int nl80211_parse_sta_wme(struct genl_info *info,
4193 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004194{
Jouni Malinendf881292013-02-14 21:10:54 +02004195 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4196 struct nlattr *nla;
4197 int err;
4198
Jouni Malinendf881292013-02-14 21:10:54 +02004199 /* parse WME attributes if present */
4200 if (!info->attrs[NL80211_ATTR_STA_WME])
4201 return 0;
4202
4203 nla = info->attrs[NL80211_ATTR_STA_WME];
4204 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4205 nl80211_sta_wme_policy);
4206 if (err)
4207 return err;
4208
4209 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4210 params->uapsd_queues = nla_get_u8(
4211 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4212 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4213 return -EINVAL;
4214
4215 if (tb[NL80211_STA_WME_MAX_SP])
4216 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4217
4218 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4219 return -EINVAL;
4220
4221 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4222
4223 return 0;
4224}
4225
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304226static int nl80211_parse_sta_channel_info(struct genl_info *info,
4227 struct station_parameters *params)
4228{
4229 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4230 params->supported_channels =
4231 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4232 params->supported_channels_len =
4233 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4234 /*
4235 * Need to include at least one (first channel, number of
4236 * channels) tuple for each subband, and must have proper
4237 * tuples for the rest of the data as well.
4238 */
4239 if (params->supported_channels_len < 2)
4240 return -EINVAL;
4241 if (params->supported_channels_len % 2)
4242 return -EINVAL;
4243 }
4244
4245 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4246 params->supported_oper_classes =
4247 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4248 params->supported_oper_classes_len =
4249 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4250 /*
4251 * The value of the Length field of the Supported Operating
4252 * Classes element is between 2 and 253.
4253 */
4254 if (params->supported_oper_classes_len < 2 ||
4255 params->supported_oper_classes_len > 253)
4256 return -EINVAL;
4257 }
4258 return 0;
4259}
4260
Johannes Bergff276692013-02-15 00:09:01 +01004261static int nl80211_set_station_tdls(struct genl_info *info,
4262 struct station_parameters *params)
4263{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304264 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004265 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004266 if (info->attrs[NL80211_ATTR_PEER_AID])
4267 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004268 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4269 params->ht_capa =
4270 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4271 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4272 params->vht_capa =
4273 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4274
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304275 err = nl80211_parse_sta_channel_info(info, params);
4276 if (err)
4277 return err;
4278
Johannes Bergff276692013-02-15 00:09:01 +01004279 return nl80211_parse_sta_wme(info, params);
4280}
4281
Johannes Berg5727ef12007-12-19 02:03:34 +01004282static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4283{
Johannes Berg4c476992010-10-04 21:36:35 +02004284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004285 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004286 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004287 u8 *mac_addr;
4288 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004289
4290 memset(&params, 0, sizeof(params));
4291
Johannes Berg77ee7c82013-02-15 00:48:33 +01004292 if (!rdev->ops->change_station)
4293 return -EOPNOTSUPP;
4294
Ayala Bekere4208422015-10-23 11:20:06 +03004295 /*
4296 * AID and listen_interval properties can be set only for unassociated
4297 * station. Include these parameters here and will check them in
4298 * cfg80211_check_station_change().
4299 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004300 if (info->attrs[NL80211_ATTR_STA_AID])
4301 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004302
4303 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4304 params.listen_interval =
4305 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4306 else
4307 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004308
Ayala Beker17b94242016-03-17 15:41:38 +02004309 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4310 u8 tmp;
4311
4312 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4313 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4314 return -EINVAL;
4315
4316 params.support_p2p_ps = tmp;
4317 } else {
4318 params.support_p2p_ps = -1;
4319 }
4320
Johannes Berg5727ef12007-12-19 02:03:34 +01004321 if (!info->attrs[NL80211_ATTR_MAC])
4322 return -EINVAL;
4323
4324 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4325
4326 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4327 params.supported_rates =
4328 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4329 params.supported_rates_len =
4330 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4331 }
4332
Jouni Malinen9d62a982013-02-14 21:10:13 +02004333 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4334 params.capability =
4335 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4336 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4337 }
4338
4339 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4340 params.ext_capab =
4341 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4342 params.ext_capab_len =
4343 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4344 }
4345
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004346 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004347 return -EINVAL;
4348
Johannes Bergf8bacc22013-02-14 23:27:01 +01004349 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004350 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004351 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4352 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4353 return -EINVAL;
4354 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004355
Johannes Bergf8bacc22013-02-14 23:27:01 +01004356 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004357 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004358 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4359 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4360 return -EINVAL;
4361 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4362 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004363
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004364 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4365 enum nl80211_mesh_power_mode pm = nla_get_u32(
4366 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4367
4368 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4369 pm > NL80211_MESH_POWER_MAX)
4370 return -EINVAL;
4371
4372 params.local_pm = pm;
4373 }
4374
Johannes Berg77ee7c82013-02-15 00:48:33 +01004375 /* Include parameters for TDLS peer (will check later) */
4376 err = nl80211_set_station_tdls(info, &params);
4377 if (err)
4378 return err;
4379
4380 params.vlan = get_vlan(info, rdev);
4381 if (IS_ERR(params.vlan))
4382 return PTR_ERR(params.vlan);
4383
Johannes Berga97f4422009-06-18 17:23:43 +02004384 switch (dev->ieee80211_ptr->iftype) {
4385 case NL80211_IFTYPE_AP:
4386 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004387 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004388 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004389 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004390 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004391 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004392 break;
4393 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004394 err = -EOPNOTSUPP;
4395 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004396 }
4397
Johannes Berg77ee7c82013-02-15 00:48:33 +01004398 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004399 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004400
Johannes Berg77ee7c82013-02-15 00:48:33 +01004401 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004402 if (params.vlan)
4403 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004404
Johannes Berg5727ef12007-12-19 02:03:34 +01004405 return err;
4406}
4407
4408static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4409{
Johannes Berg4c476992010-10-04 21:36:35 +02004410 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004411 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004412 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004413 struct station_parameters params;
4414 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004415 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4416 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004417
4418 memset(&params, 0, sizeof(params));
4419
Johannes Berg984c3112013-02-14 23:43:25 +01004420 if (!rdev->ops->add_station)
4421 return -EOPNOTSUPP;
4422
Johannes Berg5727ef12007-12-19 02:03:34 +01004423 if (!info->attrs[NL80211_ATTR_MAC])
4424 return -EINVAL;
4425
Johannes Berg5727ef12007-12-19 02:03:34 +01004426 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4427 return -EINVAL;
4428
4429 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4430 return -EINVAL;
4431
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004432 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4433 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004434 return -EINVAL;
4435
Johannes Berg5727ef12007-12-19 02:03:34 +01004436 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4437 params.supported_rates =
4438 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4439 params.supported_rates_len =
4440 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4441 params.listen_interval =
4442 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004443
Ayala Beker17b94242016-03-17 15:41:38 +02004444 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4445 u8 tmp;
4446
4447 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4448 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4449 return -EINVAL;
4450
4451 params.support_p2p_ps = tmp;
4452 } else {
4453 /*
4454 * if not specified, assume it's supported for P2P GO interface,
4455 * and is NOT supported for AP interface
4456 */
4457 params.support_p2p_ps =
4458 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4459 }
4460
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004461 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004462 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004463 else
4464 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004465 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4466 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004467
Jouni Malinen9d62a982013-02-14 21:10:13 +02004468 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4469 params.capability =
4470 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4471 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4472 }
4473
4474 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4475 params.ext_capab =
4476 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4477 params.ext_capab_len =
4478 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4479 }
4480
Jouni Malinen36aedc902008-08-25 11:58:58 +03004481 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4482 params.ht_capa =
4483 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004484
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004485 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4486 params.vht_capa =
4487 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4488
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004489 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4490 params.opmode_notif_used = true;
4491 params.opmode_notif =
4492 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4493 }
4494
Johannes Bergf8bacc22013-02-14 23:27:01 +01004495 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004496 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004497 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4498 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4499 return -EINVAL;
4500 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004501
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304502 err = nl80211_parse_sta_channel_info(info, &params);
4503 if (err)
4504 return err;
4505
Johannes Bergff276692013-02-15 00:09:01 +01004506 err = nl80211_parse_sta_wme(info, &params);
4507 if (err)
4508 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004509
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004510 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004511 return -EINVAL;
4512
Johannes Berg496fcc22015-03-12 08:53:27 +02004513 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4514 * as userspace might just pass through the capabilities from the IEs
4515 * directly, rather than enforcing this restriction and returning an
4516 * error in this case.
4517 */
4518 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4519 params.ht_capa = NULL;
4520 params.vht_capa = NULL;
4521 }
4522
Johannes Berg77ee7c82013-02-15 00:48:33 +01004523 /* When you run into this, adjust the code below for the new flag */
4524 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4525
Johannes Bergbdd90d52011-12-14 12:20:27 +01004526 switch (dev->ieee80211_ptr->iftype) {
4527 case NL80211_IFTYPE_AP:
4528 case NL80211_IFTYPE_AP_VLAN:
4529 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004530 /* ignore WME attributes if iface/sta is not capable */
4531 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4532 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4533 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004534
Johannes Bergbdd90d52011-12-14 12:20:27 +01004535 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004536 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4537 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004538 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004539 /* but don't bother the driver with it */
4540 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004541
Johannes Bergd582cff2012-10-26 17:53:44 +02004542 /* allow authenticated/associated only if driver handles it */
4543 if (!(rdev->wiphy.features &
4544 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004545 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004546 return -EINVAL;
4547
Johannes Bergbda95eb2015-11-26 16:26:13 +01004548 /* Older userspace, or userspace wanting to be compatible with
4549 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4550 * and assoc flags in the mask, but assumes the station will be
4551 * added as associated anyway since this was the required driver
4552 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4553 * introduced.
4554 * In order to not bother drivers with this quirk in the API
4555 * set the flags in both the mask and set for new stations in
4556 * this case.
4557 */
4558 if (!(params.sta_flags_mask & auth_assoc)) {
4559 params.sta_flags_mask |= auth_assoc;
4560 params.sta_flags_set |= auth_assoc;
4561 }
4562
Johannes Bergbdd90d52011-12-14 12:20:27 +01004563 /* must be last in here for error handling */
4564 params.vlan = get_vlan(info, rdev);
4565 if (IS_ERR(params.vlan))
4566 return PTR_ERR(params.vlan);
4567 break;
4568 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004569 /* ignore uAPSD data */
4570 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4571
Johannes Bergd582cff2012-10-26 17:53:44 +02004572 /* associated is disallowed */
4573 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4574 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004575 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004576 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4577 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004578 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004579 break;
4580 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004581 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004582 /* ignore uAPSD data */
4583 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4584
Johannes Berg77ee7c82013-02-15 00:48:33 +01004585 /* these are disallowed */
4586 if (params.sta_flags_mask &
4587 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4588 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004589 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004590 /* Only TDLS peers can be added */
4591 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4592 return -EINVAL;
4593 /* Can only add if TDLS ... */
4594 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4595 return -EOPNOTSUPP;
4596 /* ... with external setup is supported */
4597 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4598 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004599 /*
4600 * Older wpa_supplicant versions always mark the TDLS peer
4601 * as authorized, but it shouldn't yet be.
4602 */
4603 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004604 break;
4605 default:
4606 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004607 }
4608
Johannes Bergbdd90d52011-12-14 12:20:27 +01004609 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004610
Hila Gonene35e4d22012-06-27 17:19:42 +03004611 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004612
Johannes Berg5727ef12007-12-19 02:03:34 +01004613 if (params.vlan)
4614 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004615 return err;
4616}
4617
4618static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4619{
Johannes Berg4c476992010-10-04 21:36:35 +02004620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4621 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004622 struct station_del_parameters params;
4623
4624 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004625
4626 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004627 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004628
Johannes Berge80cf852009-05-11 14:43:13 +02004629 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004630 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004631 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004632 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4633 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004634
Johannes Berg4c476992010-10-04 21:36:35 +02004635 if (!rdev->ops->del_station)
4636 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004637
Jouni Malinen98856862014-10-20 13:20:45 +03004638 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4639 params.subtype =
4640 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4641 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4642 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4643 return -EINVAL;
4644 } else {
4645 /* Default to Deauthentication frame */
4646 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4647 }
4648
4649 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4650 params.reason_code =
4651 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4652 if (params.reason_code == 0)
4653 return -EINVAL; /* 0 is reserved */
4654 } else {
4655 /* Default to reason code 2 */
4656 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4657 }
4658
Jouni Malinen89c771e2014-10-10 20:52:40 +03004659 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004660}
4661
Eric W. Biederman15e47302012-09-07 20:12:54 +00004662static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004663 int flags, struct net_device *dev,
4664 u8 *dst, u8 *next_hop,
4665 struct mpath_info *pinfo)
4666{
4667 void *hdr;
4668 struct nlattr *pinfoattr;
4669
Henning Rogge1ef4c852014-11-04 16:14:58 +01004670 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004671 if (!hdr)
4672 return -1;
4673
David S. Miller9360ffd2012-03-29 04:41:26 -04004674 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4675 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4676 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4677 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4678 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004679
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004680 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4681 if (!pinfoattr)
4682 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004683 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4684 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4685 pinfo->frame_qlen))
4686 goto nla_put_failure;
4687 if (((pinfo->filled & MPATH_INFO_SN) &&
4688 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4689 ((pinfo->filled & MPATH_INFO_METRIC) &&
4690 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4691 pinfo->metric)) ||
4692 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4693 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4694 pinfo->exptime)) ||
4695 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4696 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4697 pinfo->flags)) ||
4698 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4699 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4700 pinfo->discovery_timeout)) ||
4701 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4702 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4703 pinfo->discovery_retries)))
4704 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004705
4706 nla_nest_end(msg, pinfoattr);
4707
Johannes Berg053c0952015-01-16 22:09:00 +01004708 genlmsg_end(msg, hdr);
4709 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004710
4711 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004712 genlmsg_cancel(msg, hdr);
4713 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004714}
4715
4716static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004717 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004718{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004719 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004720 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004721 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004722 u8 dst[ETH_ALEN];
4723 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004724 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004725 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004726
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004727 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004728 if (err)
4729 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004730
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004731 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004732 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004733 goto out_err;
4734 }
4735
Johannes Berg97990a02013-04-19 01:02:55 +02004736 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004737 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004738 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004739 }
4740
Johannes Bergbba95fe2008-07-29 13:22:51 +02004741 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004742 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004743 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004744 if (err == -ENOENT)
4745 break;
4746 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004747 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004748
Eric W. Biederman15e47302012-09-07 20:12:54 +00004749 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004750 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004751 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004752 &pinfo) < 0)
4753 goto out;
4754
4755 path_idx++;
4756 }
4757
4758
4759 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004760 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004761 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004762 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004763 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004764 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004765}
4766
4767static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4768{
Johannes Berg4c476992010-10-04 21:36:35 +02004769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004770 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004771 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004772 struct mpath_info pinfo;
4773 struct sk_buff *msg;
4774 u8 *dst = NULL;
4775 u8 next_hop[ETH_ALEN];
4776
4777 memset(&pinfo, 0, sizeof(pinfo));
4778
4779 if (!info->attrs[NL80211_ATTR_MAC])
4780 return -EINVAL;
4781
4782 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4783
Johannes Berg4c476992010-10-04 21:36:35 +02004784 if (!rdev->ops->get_mpath)
4785 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004786
Johannes Berg4c476992010-10-04 21:36:35 +02004787 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4788 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004789
Hila Gonene35e4d22012-06-27 17:19:42 +03004790 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004791 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004792 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004793
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004795 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004796 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004797
Eric W. Biederman15e47302012-09-07 20:12:54 +00004798 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004799 dev, dst, next_hop, &pinfo) < 0) {
4800 nlmsg_free(msg);
4801 return -ENOBUFS;
4802 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004803
Johannes Berg4c476992010-10-04 21:36:35 +02004804 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004805}
4806
4807static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4808{
Johannes Berg4c476992010-10-04 21:36:35 +02004809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4810 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004811 u8 *dst = NULL;
4812 u8 *next_hop = NULL;
4813
4814 if (!info->attrs[NL80211_ATTR_MAC])
4815 return -EINVAL;
4816
4817 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4818 return -EINVAL;
4819
4820 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4821 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4822
Johannes Berg4c476992010-10-04 21:36:35 +02004823 if (!rdev->ops->change_mpath)
4824 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004825
Johannes Berg4c476992010-10-04 21:36:35 +02004826 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4827 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004828
Hila Gonene35e4d22012-06-27 17:19:42 +03004829 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004830}
Johannes Berg4c476992010-10-04 21:36:35 +02004831
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004832static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4833{
Johannes Berg4c476992010-10-04 21:36:35 +02004834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4835 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004836 u8 *dst = NULL;
4837 u8 *next_hop = NULL;
4838
4839 if (!info->attrs[NL80211_ATTR_MAC])
4840 return -EINVAL;
4841
4842 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4843 return -EINVAL;
4844
4845 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4846 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4847
Johannes Berg4c476992010-10-04 21:36:35 +02004848 if (!rdev->ops->add_mpath)
4849 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004850
Johannes Berg4c476992010-10-04 21:36:35 +02004851 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4852 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004853
Hila Gonene35e4d22012-06-27 17:19:42 +03004854 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004855}
4856
4857static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4858{
Johannes Berg4c476992010-10-04 21:36:35 +02004859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4860 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004861 u8 *dst = NULL;
4862
4863 if (info->attrs[NL80211_ATTR_MAC])
4864 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4865
Johannes Berg4c476992010-10-04 21:36:35 +02004866 if (!rdev->ops->del_mpath)
4867 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004868
Hila Gonene35e4d22012-06-27 17:19:42 +03004869 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004870}
4871
Henning Rogge66be7d22014-09-12 08:58:49 +02004872static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4873{
4874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4875 int err;
4876 struct net_device *dev = info->user_ptr[1];
4877 struct mpath_info pinfo;
4878 struct sk_buff *msg;
4879 u8 *dst = NULL;
4880 u8 mpp[ETH_ALEN];
4881
4882 memset(&pinfo, 0, sizeof(pinfo));
4883
4884 if (!info->attrs[NL80211_ATTR_MAC])
4885 return -EINVAL;
4886
4887 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4888
4889 if (!rdev->ops->get_mpp)
4890 return -EOPNOTSUPP;
4891
4892 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4893 return -EOPNOTSUPP;
4894
4895 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4896 if (err)
4897 return err;
4898
4899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4900 if (!msg)
4901 return -ENOMEM;
4902
4903 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4904 dev, dst, mpp, &pinfo) < 0) {
4905 nlmsg_free(msg);
4906 return -ENOBUFS;
4907 }
4908
4909 return genlmsg_reply(msg, info);
4910}
4911
4912static int nl80211_dump_mpp(struct sk_buff *skb,
4913 struct netlink_callback *cb)
4914{
4915 struct mpath_info pinfo;
4916 struct cfg80211_registered_device *rdev;
4917 struct wireless_dev *wdev;
4918 u8 dst[ETH_ALEN];
4919 u8 mpp[ETH_ALEN];
4920 int path_idx = cb->args[2];
4921 int err;
4922
4923 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4924 if (err)
4925 return err;
4926
4927 if (!rdev->ops->dump_mpp) {
4928 err = -EOPNOTSUPP;
4929 goto out_err;
4930 }
4931
4932 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4933 err = -EOPNOTSUPP;
4934 goto out_err;
4935 }
4936
4937 while (1) {
4938 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4939 mpp, &pinfo);
4940 if (err == -ENOENT)
4941 break;
4942 if (err)
4943 goto out_err;
4944
4945 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4946 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4947 wdev->netdev, dst, mpp,
4948 &pinfo) < 0)
4949 goto out;
4950
4951 path_idx++;
4952 }
4953
4954 out:
4955 cb->args[2] = path_idx;
4956 err = skb->len;
4957 out_err:
4958 nl80211_finish_wdev_dump(rdev);
4959 return err;
4960}
4961
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004962static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4963{
Johannes Berg4c476992010-10-04 21:36:35 +02004964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4965 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004966 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004967 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004968 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004969
4970 memset(&params, 0, sizeof(params));
4971 /* default to not changing parameters */
4972 params.use_cts_prot = -1;
4973 params.use_short_preamble = -1;
4974 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004975 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004976 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004977 params.p2p_ctwindow = -1;
4978 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004979
4980 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4981 params.use_cts_prot =
4982 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4983 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4984 params.use_short_preamble =
4985 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4986 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4987 params.use_short_slot_time =
4988 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004989 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4990 params.basic_rates =
4991 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4992 params.basic_rates_len =
4993 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4994 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004995 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4996 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004997 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4998 params.ht_opmode =
4999 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005000
Johannes Berg53cabad2012-11-14 15:17:28 +01005001 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5002 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5003 return -EINVAL;
5004 params.p2p_ctwindow =
5005 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5006 if (params.p2p_ctwindow < 0)
5007 return -EINVAL;
5008 if (params.p2p_ctwindow != 0 &&
5009 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5010 return -EINVAL;
5011 }
5012
5013 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5014 u8 tmp;
5015
5016 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5017 return -EINVAL;
5018 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5019 if (tmp > 1)
5020 return -EINVAL;
5021 params.p2p_opp_ps = tmp;
5022 if (params.p2p_opp_ps &&
5023 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5024 return -EINVAL;
5025 }
5026
Johannes Berg4c476992010-10-04 21:36:35 +02005027 if (!rdev->ops->change_bss)
5028 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005029
Johannes Berg074ac8d2010-09-16 14:58:22 +02005030 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005031 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5032 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005033
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005034 wdev_lock(wdev);
5035 err = rdev_change_bss(rdev, dev, &params);
5036 wdev_unlock(wdev);
5037
5038 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005039}
5040
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005041static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5042{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005043 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005044 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005045 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005046 u32 owner_nlportid;
5047
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005048
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005049 /*
5050 * You should only get this when cfg80211 hasn't yet initialized
5051 * completely when built-in to the kernel right between the time
5052 * window between nl80211_init() and regulatory_init(), if that is
5053 * even possible.
5054 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005055 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005056 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005057
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005058 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5059 user_reg_hint_type =
5060 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5061 else
5062 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5063
5064 switch (user_reg_hint_type) {
5065 case NL80211_USER_REG_HINT_USER:
5066 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005067 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5068 return -EINVAL;
5069
5070 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5071 return regulatory_hint_user(data, user_reg_hint_type);
5072 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005073 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5074 owner_nlportid = info->snd_portid;
5075 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5076 } else {
5077 owner_nlportid = 0;
5078 is_indoor = true;
5079 }
5080
5081 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005082 default:
5083 return -EINVAL;
5084 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005085}
5086
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005087static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005088 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005089{
Johannes Berg4c476992010-10-04 21:36:35 +02005090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005091 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005092 struct wireless_dev *wdev = dev->ieee80211_ptr;
5093 struct mesh_config cur_params;
5094 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005095 void *hdr;
5096 struct nlattr *pinfoattr;
5097 struct sk_buff *msg;
5098
Johannes Berg29cbe682010-12-03 09:20:44 +01005099 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5100 return -EOPNOTSUPP;
5101
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005102 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005103 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005104
Johannes Berg29cbe682010-12-03 09:20:44 +01005105 wdev_lock(wdev);
5106 /* If not connected, get default parameters */
5107 if (!wdev->mesh_id_len)
5108 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5109 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005110 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005111 wdev_unlock(wdev);
5112
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005113 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005114 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005115
5116 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005117 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005118 if (!msg)
5119 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005120 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005121 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005122 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005123 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005124 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005125 if (!pinfoattr)
5126 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005127 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5128 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5129 cur_params.dot11MeshRetryTimeout) ||
5130 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5131 cur_params.dot11MeshConfirmTimeout) ||
5132 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5133 cur_params.dot11MeshHoldingTimeout) ||
5134 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5135 cur_params.dot11MeshMaxPeerLinks) ||
5136 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5137 cur_params.dot11MeshMaxRetries) ||
5138 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5139 cur_params.dot11MeshTTL) ||
5140 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5141 cur_params.element_ttl) ||
5142 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5143 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005144 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5145 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005146 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5147 cur_params.dot11MeshHWMPmaxPREQretries) ||
5148 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5149 cur_params.path_refresh_time) ||
5150 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5151 cur_params.min_discovery_timeout) ||
5152 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5153 cur_params.dot11MeshHWMPactivePathTimeout) ||
5154 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5155 cur_params.dot11MeshHWMPpreqMinInterval) ||
5156 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5157 cur_params.dot11MeshHWMPperrMinInterval) ||
5158 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5159 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5160 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5161 cur_params.dot11MeshHWMPRootMode) ||
5162 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5163 cur_params.dot11MeshHWMPRannInterval) ||
5164 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5165 cur_params.dot11MeshGateAnnouncementProtocol) ||
5166 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5167 cur_params.dot11MeshForwarding) ||
5168 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005169 cur_params.rssi_threshold) ||
5170 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005171 cur_params.ht_opmode) ||
5172 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5173 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5174 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005175 cur_params.dot11MeshHWMProotInterval) ||
5176 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005177 cur_params.dot11MeshHWMPconfirmationInterval) ||
5178 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5179 cur_params.power_mode) ||
5180 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005181 cur_params.dot11MeshAwakeWindowDuration) ||
5182 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5183 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005184 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005185 nla_nest_end(msg, pinfoattr);
5186 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005187 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005188
Johannes Berg3b858752009-03-12 09:55:09 +01005189 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005190 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005191 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005192 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005193 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005194}
5195
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005196static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005197 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5198 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5199 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5200 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5201 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5202 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005203 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005204 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005205 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005206 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5207 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5208 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5209 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5210 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005211 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005212 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005213 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005214 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005215 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005216 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005217 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5218 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005219 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5220 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005221 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005222 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5223 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005224 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005225};
5226
Javier Cardonac80d5452010-12-16 17:37:49 -08005227static const struct nla_policy
5228 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005229 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005230 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5231 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005232 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005233 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005234 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005235 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005236 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005237 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005238};
5239
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005240static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005241 struct mesh_config *cfg,
5242 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005243{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005244 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005245 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005246
Marco Porschea54fba2013-01-07 16:04:48 +01005247#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5248do { \
5249 if (tb[attr]) { \
5250 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5251 return -EINVAL; \
5252 cfg->param = fn(tb[attr]); \
5253 mask |= (1 << (attr - 1)); \
5254 } \
5255} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005256
5257
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005258 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005259 return -EINVAL;
5260 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005261 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005262 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005263 return -EINVAL;
5264
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005265 /* This makes sure that there aren't more than 32 mesh config
5266 * parameters (otherwise our bitfield scheme would not work.) */
5267 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5268
5269 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005270 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005271 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5272 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005273 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005274 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5275 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005276 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005277 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5278 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005279 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005280 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5281 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005282 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005283 mask, NL80211_MESHCONF_MAX_RETRIES,
5284 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005285 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005286 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005287 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005288 mask, NL80211_MESHCONF_ELEMENT_TTL,
5289 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005290 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005291 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5292 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005293 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5294 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005295 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5296 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005297 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005298 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5299 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005300 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005301 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5302 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005303 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005304 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5305 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005306 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5307 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005308 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5309 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005310 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005311 1, 65535, mask,
5312 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005313 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005314 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005315 1, 65535, mask,
5316 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005317 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005318 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005319 dot11MeshHWMPnetDiameterTraversalTime,
5320 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005321 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5322 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005323 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5324 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5325 nla_get_u8);
5326 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5327 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005328 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005329 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005330 dot11MeshGateAnnouncementProtocol, 0, 1,
5331 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005332 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005333 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005334 mask, NL80211_MESHCONF_FORWARDING,
5335 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005336 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005337 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005338 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005340 mask, NL80211_MESHCONF_HT_OPMODE,
5341 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005342 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005343 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005344 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5345 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005346 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005347 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5348 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005349 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005350 dot11MeshHWMPconfirmationInterval,
5351 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005352 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5353 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005354 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5355 NL80211_MESH_POWER_ACTIVE,
5356 NL80211_MESH_POWER_MAX,
5357 mask, NL80211_MESHCONF_POWER_MODE,
5358 nla_get_u32);
5359 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5360 0, 65535, mask,
5361 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005362 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005363 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5364 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005365 if (mask_out)
5366 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005367
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005368 return 0;
5369
5370#undef FILL_IN_MESH_PARAM_IF_SET
5371}
5372
Javier Cardonac80d5452010-12-16 17:37:49 -08005373static int nl80211_parse_mesh_setup(struct genl_info *info,
5374 struct mesh_setup *setup)
5375{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005376 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005377 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5378
5379 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5380 return -EINVAL;
5381 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5382 info->attrs[NL80211_ATTR_MESH_SETUP],
5383 nl80211_mesh_setup_params_policy))
5384 return -EINVAL;
5385
Javier Cardonad299a1f2012-03-31 11:31:33 -07005386 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5387 setup->sync_method =
5388 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5389 IEEE80211_SYNC_METHOD_VENDOR :
5390 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5391
Javier Cardonac80d5452010-12-16 17:37:49 -08005392 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5393 setup->path_sel_proto =
5394 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5395 IEEE80211_PATH_PROTOCOL_VENDOR :
5396 IEEE80211_PATH_PROTOCOL_HWMP;
5397
5398 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5399 setup->path_metric =
5400 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5401 IEEE80211_PATH_METRIC_VENDOR :
5402 IEEE80211_PATH_METRIC_AIRTIME;
5403
Javier Cardona581a8b02011-04-07 15:08:27 -07005404
5405 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005406 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005407 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005408 if (!is_valid_ie_attr(ieattr))
5409 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005410 setup->ie = nla_data(ieattr);
5411 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005412 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005413 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5414 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5415 return -EINVAL;
5416 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005417 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5418 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005419 if (setup->is_secure)
5420 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005421
Colleen Twitty6e16d902013-05-08 11:45:59 -07005422 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5423 if (!setup->user_mpm)
5424 return -EINVAL;
5425 setup->auth_id =
5426 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5427 }
5428
Javier Cardonac80d5452010-12-16 17:37:49 -08005429 return 0;
5430}
5431
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005432static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005433 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005434{
5435 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5436 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005437 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005438 struct mesh_config cfg;
5439 u32 mask;
5440 int err;
5441
Johannes Berg29cbe682010-12-03 09:20:44 +01005442 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5443 return -EOPNOTSUPP;
5444
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005445 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005446 return -EOPNOTSUPP;
5447
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005448 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005449 if (err)
5450 return err;
5451
Johannes Berg29cbe682010-12-03 09:20:44 +01005452 wdev_lock(wdev);
5453 if (!wdev->mesh_id_len)
5454 err = -ENOLINK;
5455
5456 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005457 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005458
5459 wdev_unlock(wdev);
5460
5461 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005462}
5463
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005464static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5465 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005466{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005467 struct nlattr *nl_reg_rules;
5468 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005469
Johannes Berg458f4f92012-12-06 15:47:38 +01005470 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5471 (regdom->dfs_region &&
5472 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005473 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005474
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005475 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5476 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005477 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005478
Johannes Berg458f4f92012-12-06 15:47:38 +01005479 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005480 struct nlattr *nl_reg_rule;
5481 const struct ieee80211_reg_rule *reg_rule;
5482 const struct ieee80211_freq_range *freq_range;
5483 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005484 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005485
Johannes Berg458f4f92012-12-06 15:47:38 +01005486 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005487 freq_range = &reg_rule->freq_range;
5488 power_rule = &reg_rule->power_rule;
5489
5490 nl_reg_rule = nla_nest_start(msg, i);
5491 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005492 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005493
Janusz Dziedzic97524822014-01-30 09:52:20 +01005494 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5495 if (!max_bandwidth_khz)
5496 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5497 reg_rule);
5498
David S. Miller9360ffd2012-03-29 04:41:26 -04005499 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5500 reg_rule->flags) ||
5501 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5502 freq_range->start_freq_khz) ||
5503 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5504 freq_range->end_freq_khz) ||
5505 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005506 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005507 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5508 power_rule->max_antenna_gain) ||
5509 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005510 power_rule->max_eirp) ||
5511 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5512 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005513 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005514
5515 nla_nest_end(msg, nl_reg_rule);
5516 }
5517
5518 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005519 return 0;
5520
5521nla_put_failure:
5522 return -EMSGSIZE;
5523}
5524
5525static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5526{
5527 const struct ieee80211_regdomain *regdom = NULL;
5528 struct cfg80211_registered_device *rdev;
5529 struct wiphy *wiphy = NULL;
5530 struct sk_buff *msg;
5531 void *hdr;
5532
5533 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5534 if (!msg)
5535 return -ENOBUFS;
5536
5537 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5538 NL80211_CMD_GET_REG);
5539 if (!hdr)
5540 goto put_failure;
5541
5542 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005543 bool self_managed;
5544
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005545 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5546 if (IS_ERR(rdev)) {
5547 nlmsg_free(msg);
5548 return PTR_ERR(rdev);
5549 }
5550
5551 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005552 self_managed = wiphy->regulatory_flags &
5553 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005554 regdom = get_wiphy_regdom(wiphy);
5555
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005556 /* a self-managed-reg device must have a private regdom */
5557 if (WARN_ON(!regdom && self_managed)) {
5558 nlmsg_free(msg);
5559 return -EINVAL;
5560 }
5561
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005562 if (regdom &&
5563 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5564 goto nla_put_failure;
5565 }
5566
5567 if (!wiphy && reg_last_request_cell_base() &&
5568 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5569 NL80211_USER_REG_HINT_CELL_BASE))
5570 goto nla_put_failure;
5571
5572 rcu_read_lock();
5573
5574 if (!regdom)
5575 regdom = rcu_dereference(cfg80211_regdomain);
5576
5577 if (nl80211_put_regdom(regdom, msg))
5578 goto nla_put_failure_rcu;
5579
5580 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005581
5582 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005583 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005584
Johannes Berg458f4f92012-12-06 15:47:38 +01005585nla_put_failure_rcu:
5586 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005587nla_put_failure:
5588 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005589put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005590 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005591 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005592}
5593
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005594static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5595 u32 seq, int flags, struct wiphy *wiphy,
5596 const struct ieee80211_regdomain *regdom)
5597{
5598 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5599 NL80211_CMD_GET_REG);
5600
5601 if (!hdr)
5602 return -1;
5603
5604 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5605
5606 if (nl80211_put_regdom(regdom, msg))
5607 goto nla_put_failure;
5608
5609 if (!wiphy && reg_last_request_cell_base() &&
5610 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5611 NL80211_USER_REG_HINT_CELL_BASE))
5612 goto nla_put_failure;
5613
5614 if (wiphy &&
5615 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5616 goto nla_put_failure;
5617
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005618 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5619 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5620 goto nla_put_failure;
5621
Johannes Berg053c0952015-01-16 22:09:00 +01005622 genlmsg_end(msg, hdr);
5623 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005624
5625nla_put_failure:
5626 genlmsg_cancel(msg, hdr);
5627 return -EMSGSIZE;
5628}
5629
5630static int nl80211_get_reg_dump(struct sk_buff *skb,
5631 struct netlink_callback *cb)
5632{
5633 const struct ieee80211_regdomain *regdom = NULL;
5634 struct cfg80211_registered_device *rdev;
5635 int err, reg_idx, start = cb->args[2];
5636
5637 rtnl_lock();
5638
5639 if (cfg80211_regdomain && start == 0) {
5640 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5641 NLM_F_MULTI, NULL,
5642 rtnl_dereference(cfg80211_regdomain));
5643 if (err < 0)
5644 goto out_err;
5645 }
5646
5647 /* the global regdom is idx 0 */
5648 reg_idx = 1;
5649 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5650 regdom = get_wiphy_regdom(&rdev->wiphy);
5651 if (!regdom)
5652 continue;
5653
5654 if (++reg_idx <= start)
5655 continue;
5656
5657 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5658 NLM_F_MULTI, &rdev->wiphy, regdom);
5659 if (err < 0) {
5660 reg_idx--;
5661 break;
5662 }
5663 }
5664
5665 cb->args[2] = reg_idx;
5666 err = skb->len;
5667out_err:
5668 rtnl_unlock();
5669 return err;
5670}
5671
Johannes Bergb6863032015-10-15 09:25:18 +02005672#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5673static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5674 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5675 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5676 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5677 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5678 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5679 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5680 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5681};
5682
5683static int parse_reg_rule(struct nlattr *tb[],
5684 struct ieee80211_reg_rule *reg_rule)
5685{
5686 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5687 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5688
5689 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5690 return -EINVAL;
5691 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5692 return -EINVAL;
5693 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5694 return -EINVAL;
5695 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5696 return -EINVAL;
5697 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5698 return -EINVAL;
5699
5700 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5701
5702 freq_range->start_freq_khz =
5703 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5704 freq_range->end_freq_khz =
5705 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5706 freq_range->max_bandwidth_khz =
5707 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5708
5709 power_rule->max_eirp =
5710 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5711
5712 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5713 power_rule->max_antenna_gain =
5714 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5715
5716 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5717 reg_rule->dfs_cac_ms =
5718 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5719
5720 return 0;
5721}
5722
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005723static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5724{
5725 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5726 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005727 char *alpha2;
5728 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005729 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005730 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005731 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005732
5733 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5734 return -EINVAL;
5735
5736 if (!info->attrs[NL80211_ATTR_REG_RULES])
5737 return -EINVAL;
5738
5739 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5740
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005741 if (info->attrs[NL80211_ATTR_DFS_REGION])
5742 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5743
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005744 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005745 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005746 num_rules++;
5747 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005748 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005749 }
5750
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005751 if (!reg_is_valid_request(alpha2))
5752 return -EINVAL;
5753
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005754 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005755 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005756
5757 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005758 if (!rd)
5759 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005760
5761 rd->n_reg_rules = num_rules;
5762 rd->alpha2[0] = alpha2[0];
5763 rd->alpha2[1] = alpha2[1];
5764
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005765 /*
5766 * Disable DFS master mode if the DFS region was
5767 * not supported or known on this kernel.
5768 */
5769 if (reg_supported_dfs_region(dfs_region))
5770 rd->dfs_region = dfs_region;
5771
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005772 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005773 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005774 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5775 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5776 reg_rule_policy);
5777 if (r)
5778 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005779 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5780 if (r)
5781 goto bad_reg;
5782
5783 rule_idx++;
5784
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005785 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5786 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005787 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005788 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005789 }
5790
Ilan peerc37722b2015-03-30 15:15:49 +03005791 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005792 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005793 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005794
Johannes Bergd2372b32008-10-24 20:32:20 +02005795 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005796 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005797 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005798}
Johannes Bergb6863032015-10-15 09:25:18 +02005799#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005800
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005801static int validate_scan_freqs(struct nlattr *freqs)
5802{
5803 struct nlattr *attr1, *attr2;
5804 int n_channels = 0, tmp1, tmp2;
5805
5806 nla_for_each_nested(attr1, freqs, tmp1) {
5807 n_channels++;
5808 /*
5809 * Some hardware has a limited channel list for
5810 * scanning, and it is pretty much nonsensical
5811 * to scan for a channel twice, so disallow that
5812 * and don't require drivers to check that the
5813 * channel list they get isn't longer than what
5814 * they can scan, as long as they can scan all
5815 * the channels they registered at once.
5816 */
5817 nla_for_each_nested(attr2, freqs, tmp2)
5818 if (attr1 != attr2 &&
5819 nla_get_u32(attr1) == nla_get_u32(attr2))
5820 return 0;
5821 }
5822
5823 return n_channels;
5824}
5825
Johannes Berg57fbcce2016-04-12 15:56:15 +02005826static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005827{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005828 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005829}
5830
5831static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5832 struct cfg80211_bss_selection *bss_select)
5833{
5834 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5835 struct nlattr *nest;
5836 int err;
5837 bool found = false;
5838 int i;
5839
5840 /* only process one nested attribute */
5841 nest = nla_data(nla);
5842 if (!nla_ok(nest, nla_len(nest)))
5843 return -EINVAL;
5844
5845 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5846 nla_len(nest), nl80211_bss_select_policy);
5847 if (err)
5848 return err;
5849
5850 /* only one attribute may be given */
5851 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
5852 if (attr[i]) {
5853 if (found)
5854 return -EINVAL;
5855 found = true;
5856 }
5857 }
5858
5859 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
5860
5861 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
5862 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
5863
5864 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
5865 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
5866 bss_select->param.band_pref =
5867 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
5868 if (!is_band_valid(wiphy, bss_select->param.band_pref))
5869 return -EINVAL;
5870 }
5871
5872 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
5873 struct nl80211_bss_select_rssi_adjust *adj_param;
5874
5875 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
5876 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
5877 bss_select->param.adjust.band = adj_param->band;
5878 bss_select->param.adjust.delta = adj_param->delta;
5879 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
5880 return -EINVAL;
5881 }
5882
5883 /* user-space did not provide behaviour attribute */
5884 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
5885 return -EINVAL;
5886
5887 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
5888 return -EINVAL;
5889
5890 return 0;
5891}
5892
Johannes Bergad2b26a2014-06-12 21:39:05 +02005893static int nl80211_parse_random_mac(struct nlattr **attrs,
5894 u8 *mac_addr, u8 *mac_addr_mask)
5895{
5896 int i;
5897
5898 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005899 eth_zero_addr(mac_addr);
5900 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005901 mac_addr[0] = 0x2;
5902 mac_addr_mask[0] = 0x3;
5903
5904 return 0;
5905 }
5906
5907 /* need both or none */
5908 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5909 return -EINVAL;
5910
5911 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5912 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5913
5914 /* don't allow or configure an mcast address */
5915 if (!is_multicast_ether_addr(mac_addr_mask) ||
5916 is_multicast_ether_addr(mac_addr))
5917 return -EINVAL;
5918
5919 /*
5920 * allow users to pass a MAC address that has bits set outside
5921 * of the mask, but don't bother drivers with having to deal
5922 * with such bits
5923 */
5924 for (i = 0; i < ETH_ALEN; i++)
5925 mac_addr[i] &= mac_addr_mask[i];
5926
5927 return 0;
5928}
5929
Johannes Berg2a519312009-02-10 21:25:55 +01005930static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5931{
Johannes Berg4c476992010-10-04 21:36:35 +02005932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005933 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005934 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005935 struct nlattr *attr;
5936 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005937 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005938 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005939
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005940 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5941 return -EINVAL;
5942
Johannes Berg79c97e92009-07-07 03:56:12 +02005943 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005944
Johannes Berg4c476992010-10-04 21:36:35 +02005945 if (!rdev->ops->scan)
5946 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005947
Johannes Bergf9d15d12014-01-22 11:14:19 +02005948 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005949 err = -EBUSY;
5950 goto unlock;
5951 }
Johannes Berg2a519312009-02-10 21:25:55 +01005952
5953 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005954 n_channels = validate_scan_freqs(
5955 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005956 if (!n_channels) {
5957 err = -EINVAL;
5958 goto unlock;
5959 }
Johannes Berg2a519312009-02-10 21:25:55 +01005960 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005961 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005962 }
5963
5964 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5965 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5966 n_ssids++;
5967
Johannes Bergf9f47522013-03-19 15:04:07 +01005968 if (n_ssids > wiphy->max_scan_ssids) {
5969 err = -EINVAL;
5970 goto unlock;
5971 }
Johannes Berg2a519312009-02-10 21:25:55 +01005972
Jouni Malinen70692ad2009-02-16 19:39:13 +02005973 if (info->attrs[NL80211_ATTR_IE])
5974 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5975 else
5976 ie_len = 0;
5977
Johannes Bergf9f47522013-03-19 15:04:07 +01005978 if (ie_len > wiphy->max_scan_ie_len) {
5979 err = -EINVAL;
5980 goto unlock;
5981 }
Johannes Berg18a83652009-03-31 12:12:05 +02005982
Johannes Berg2a519312009-02-10 21:25:55 +01005983 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005984 + sizeof(*request->ssids) * n_ssids
5985 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005986 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005987 if (!request) {
5988 err = -ENOMEM;
5989 goto unlock;
5990 }
Johannes Berg2a519312009-02-10 21:25:55 +01005991
Johannes Berg2a519312009-02-10 21:25:55 +01005992 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005993 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005994 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005995 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005996 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005997 request->ie = (void *)(request->ssids + n_ssids);
5998 else
5999 request->ie = (void *)(request->channels + n_channels);
6000 }
Johannes Berg2a519312009-02-10 21:25:55 +01006001
Johannes Berg584991d2009-11-02 13:32:03 +01006002 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006003 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6004 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006005 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006006 struct ieee80211_channel *chan;
6007
6008 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6009
6010 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006011 err = -EINVAL;
6012 goto out_free;
6013 }
Johannes Berg584991d2009-11-02 13:32:03 +01006014
6015 /* ignore disabled channels */
6016 if (chan->flags & IEEE80211_CHAN_DISABLED)
6017 continue;
6018
6019 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006020 i++;
6021 }
6022 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006023 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006024
Johannes Berg2a519312009-02-10 21:25:55 +01006025 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006026 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006027 int j;
6028 if (!wiphy->bands[band])
6029 continue;
6030 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006031 struct ieee80211_channel *chan;
6032
6033 chan = &wiphy->bands[band]->channels[j];
6034
6035 if (chan->flags & IEEE80211_CHAN_DISABLED)
6036 continue;
6037
6038 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006039 i++;
6040 }
6041 }
6042 }
6043
Johannes Berg584991d2009-11-02 13:32:03 +01006044 if (!i) {
6045 err = -EINVAL;
6046 goto out_free;
6047 }
6048
6049 request->n_channels = i;
6050
Johannes Berg2a519312009-02-10 21:25:55 +01006051 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006052 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006053 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006054 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006055 err = -EINVAL;
6056 goto out_free;
6057 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006058 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006059 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006060 i++;
6061 }
6062 }
6063
Jouni Malinen70692ad2009-02-16 19:39:13 +02006064 if (info->attrs[NL80211_ATTR_IE]) {
6065 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006066 memcpy((void *)request->ie,
6067 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006068 request->ie_len);
6069 }
6070
Johannes Berg57fbcce2016-04-12 15:56:15 +02006071 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006072 if (wiphy->bands[i])
6073 request->rates[i] =
6074 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006075
6076 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6077 nla_for_each_nested(attr,
6078 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6079 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006080 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006081
Johannes Berg57fbcce2016-04-12 15:56:15 +02006082 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006083 err = -EINVAL;
6084 goto out_free;
6085 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006086
6087 if (!wiphy->bands[band])
6088 continue;
6089
Johannes Berg34850ab2011-07-18 18:08:35 +02006090 err = ieee80211_get_ratemask(wiphy->bands[band],
6091 nla_data(attr),
6092 nla_len(attr),
6093 &request->rates[band]);
6094 if (err)
6095 goto out_free;
6096 }
6097 }
6098
Sam Leffler46856bb2012-10-11 21:03:32 -07006099 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006100 request->flags = nla_get_u32(
6101 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006102 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6103 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006104 err = -EOPNOTSUPP;
6105 goto out_free;
6106 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006107
6108 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6109 if (!(wiphy->features &
6110 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6111 err = -EOPNOTSUPP;
6112 goto out_free;
6113 }
6114
6115 if (wdev->current_bss) {
6116 err = -EOPNOTSUPP;
6117 goto out_free;
6118 }
6119
6120 err = nl80211_parse_random_mac(info->attrs,
6121 request->mac_addr,
6122 request->mac_addr_mask);
6123 if (err)
6124 goto out_free;
6125 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006126 }
Sam Lefflered4737712012-10-11 21:03:31 -07006127
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306128 request->no_cck =
6129 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6130
Jouni Malinen818965d2016-02-26 22:12:47 +02006131 if (info->attrs[NL80211_ATTR_MAC])
6132 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6133 ETH_ALEN);
6134 else
6135 eth_broadcast_addr(request->bssid);
6136
Johannes Bergfd014282012-06-18 19:17:03 +02006137 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006138 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006139 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006140
Johannes Berg79c97e92009-07-07 03:56:12 +02006141 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006142 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006143
Johannes Berg463d0182009-07-14 00:33:35 +02006144 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006145 nl80211_send_scan_start(rdev, wdev);
6146 if (wdev->netdev)
6147 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006148 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006149 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006150 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006151 kfree(request);
6152 }
Johannes Berg3b858752009-03-12 09:55:09 +01006153
Johannes Bergf9f47522013-03-19 15:04:07 +01006154 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006155 return err;
6156}
6157
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306158static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6159{
6160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6161 struct wireless_dev *wdev = info->user_ptr[1];
6162
6163 if (!rdev->ops->abort_scan)
6164 return -EOPNOTSUPP;
6165
6166 if (rdev->scan_msg)
6167 return 0;
6168
6169 if (!rdev->scan_req)
6170 return -ENOENT;
6171
6172 rdev_abort_scan(rdev, wdev);
6173 return 0;
6174}
6175
Avraham Stern3b06d272015-10-12 09:51:34 +03006176static int
6177nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6178 struct cfg80211_sched_scan_request *request,
6179 struct nlattr **attrs)
6180{
6181 int tmp, err, i = 0;
6182 struct nlattr *attr;
6183
6184 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6185 u32 interval;
6186
6187 /*
6188 * If scan plans are not specified,
6189 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6190 * case one scan plan will be set with the specified scan
6191 * interval and infinite number of iterations.
6192 */
6193 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6194 return -EINVAL;
6195
6196 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6197 if (!interval)
6198 return -EINVAL;
6199
6200 request->scan_plans[0].interval =
6201 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6202 if (!request->scan_plans[0].interval)
6203 return -EINVAL;
6204
6205 if (request->scan_plans[0].interval >
6206 wiphy->max_sched_scan_plan_interval)
6207 request->scan_plans[0].interval =
6208 wiphy->max_sched_scan_plan_interval;
6209
6210 return 0;
6211 }
6212
6213 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6214 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6215
6216 if (WARN_ON(i >= n_plans))
6217 return -EINVAL;
6218
6219 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6220 nla_data(attr), nla_len(attr),
6221 nl80211_plan_policy);
6222 if (err)
6223 return err;
6224
6225 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6226 return -EINVAL;
6227
6228 request->scan_plans[i].interval =
6229 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6230 if (!request->scan_plans[i].interval ||
6231 request->scan_plans[i].interval >
6232 wiphy->max_sched_scan_plan_interval)
6233 return -EINVAL;
6234
6235 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6236 request->scan_plans[i].iterations =
6237 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6238 if (!request->scan_plans[i].iterations ||
6239 (request->scan_plans[i].iterations >
6240 wiphy->max_sched_scan_plan_iterations))
6241 return -EINVAL;
6242 } else if (i < n_plans - 1) {
6243 /*
6244 * All scan plans but the last one must specify
6245 * a finite number of iterations
6246 */
6247 return -EINVAL;
6248 }
6249
6250 i++;
6251 }
6252
6253 /*
6254 * The last scan plan must not specify the number of
6255 * iterations, it is supposed to run infinitely
6256 */
6257 if (request->scan_plans[n_plans - 1].iterations)
6258 return -EINVAL;
6259
6260 return 0;
6261}
6262
Luciano Coelho256da022014-11-10 16:13:46 +02006263static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006264nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006265 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006266{
6267 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006268 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006269 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006270 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006271 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006272 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006273 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006274
Luciano Coelho256da022014-11-10 16:13:46 +02006275 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6276 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006277
Luciano Coelho256da022014-11-10 16:13:46 +02006278 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006279 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006280 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006281 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006282 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006283 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006284 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006285 }
6286
Luciano Coelho256da022014-11-10 16:13:46 +02006287 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6288 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006289 tmp)
6290 n_ssids++;
6291
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006292 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006293 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006294
Johannes Bergea73cbc2014-01-24 10:53:53 +01006295 /*
6296 * First, count the number of 'real' matchsets. Due to an issue with
6297 * the old implementation, matchsets containing only the RSSI attribute
6298 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6299 * RSSI for all matchsets, rather than their own matchset for reporting
6300 * all APs with a strong RSSI. This is needed to be compatible with
6301 * older userspace that treated a matchset with only the RSSI as the
6302 * global RSSI for all other matchsets - if there are other matchsets.
6303 */
Luciano Coelho256da022014-11-10 16:13:46 +02006304 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006305 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006306 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006307 tmp) {
6308 struct nlattr *rssi;
6309
6310 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6311 nla_data(attr), nla_len(attr),
6312 nl80211_match_policy);
6313 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006314 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006315 /* add other standalone attributes here */
6316 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6317 n_match_sets++;
6318 continue;
6319 }
6320 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6321 if (rssi)
6322 default_match_rssi = nla_get_s32(rssi);
6323 }
6324 }
6325
6326 /* However, if there's no other matchset, add the RSSI one */
6327 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6328 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006329
6330 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006331 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006332
Luciano Coelho256da022014-11-10 16:13:46 +02006333 if (attrs[NL80211_ATTR_IE])
6334 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006335 else
6336 ie_len = 0;
6337
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006338 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006339 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006340
Avraham Stern3b06d272015-10-12 09:51:34 +03006341 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6342 /*
6343 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6344 * each scan plan already specifies its own interval
6345 */
6346 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6347 return ERR_PTR(-EINVAL);
6348
6349 nla_for_each_nested(attr,
6350 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6351 n_plans++;
6352 } else {
6353 /*
6354 * The scan interval attribute is kept for backward
6355 * compatibility. If no scan plans are specified and sched scan
6356 * interval is specified, one scan plan will be set with this
6357 * scan interval and infinite number of iterations.
6358 */
6359 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6360 return ERR_PTR(-EINVAL);
6361
6362 n_plans = 1;
6363 }
6364
6365 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6366 return ERR_PTR(-EINVAL);
6367
Luciano Coelho807f8a82011-05-11 17:09:35 +03006368 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006369 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006370 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006371 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006372 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006373 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006374 if (!request)
6375 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006376
6377 if (n_ssids)
6378 request->ssids = (void *)&request->channels[n_channels];
6379 request->n_ssids = n_ssids;
6380 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006381 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006382 request->ie = (void *)(request->ssids + n_ssids);
6383 else
6384 request->ie = (void *)(request->channels + n_channels);
6385 }
6386
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006387 if (n_match_sets) {
6388 if (request->ie)
6389 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006390 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006391 request->match_sets =
6392 (void *)(request->ssids + n_ssids);
6393 else
6394 request->match_sets =
6395 (void *)(request->channels + n_channels);
6396 }
6397 request->n_match_sets = n_match_sets;
6398
Avraham Stern3b06d272015-10-12 09:51:34 +03006399 if (n_match_sets)
6400 request->scan_plans = (void *)(request->match_sets +
6401 n_match_sets);
6402 else if (request->ie)
6403 request->scan_plans = (void *)(request->ie + ie_len);
6404 else if (n_ssids)
6405 request->scan_plans = (void *)(request->ssids + n_ssids);
6406 else
6407 request->scan_plans = (void *)(request->channels + n_channels);
6408
6409 request->n_scan_plans = n_plans;
6410
Luciano Coelho807f8a82011-05-11 17:09:35 +03006411 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006412 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006413 /* user specified, bail out if channel not found */
6414 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006415 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006416 tmp) {
6417 struct ieee80211_channel *chan;
6418
6419 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6420
6421 if (!chan) {
6422 err = -EINVAL;
6423 goto out_free;
6424 }
6425
6426 /* ignore disabled channels */
6427 if (chan->flags & IEEE80211_CHAN_DISABLED)
6428 continue;
6429
6430 request->channels[i] = chan;
6431 i++;
6432 }
6433 } else {
6434 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006435 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006436 int j;
6437 if (!wiphy->bands[band])
6438 continue;
6439 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6440 struct ieee80211_channel *chan;
6441
6442 chan = &wiphy->bands[band]->channels[j];
6443
6444 if (chan->flags & IEEE80211_CHAN_DISABLED)
6445 continue;
6446
6447 request->channels[i] = chan;
6448 i++;
6449 }
6450 }
6451 }
6452
6453 if (!i) {
6454 err = -EINVAL;
6455 goto out_free;
6456 }
6457
6458 request->n_channels = i;
6459
6460 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006461 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006462 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006463 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006464 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006465 err = -EINVAL;
6466 goto out_free;
6467 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006468 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006469 memcpy(request->ssids[i].ssid, nla_data(attr),
6470 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006471 i++;
6472 }
6473 }
6474
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006475 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006476 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006477 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006478 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006479 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006480 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006481
Johannes Bergae811e22014-01-24 10:17:47 +01006482 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6483 nla_data(attr), nla_len(attr),
6484 nl80211_match_policy);
6485 if (err)
6486 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006487 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006488 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006489 if (WARN_ON(i >= n_match_sets)) {
6490 /* this indicates a programming error,
6491 * the loop above should have verified
6492 * things properly
6493 */
6494 err = -EINVAL;
6495 goto out_free;
6496 }
6497
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006498 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6499 err = -EINVAL;
6500 goto out_free;
6501 }
6502 memcpy(request->match_sets[i].ssid.ssid,
6503 nla_data(ssid), nla_len(ssid));
6504 request->match_sets[i].ssid.ssid_len =
6505 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006506 /* special attribute - old implemenation w/a */
6507 request->match_sets[i].rssi_thold =
6508 default_match_rssi;
6509 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6510 if (rssi)
6511 request->match_sets[i].rssi_thold =
6512 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006513 }
6514 i++;
6515 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006516
6517 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006518 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006519 request->match_sets[0].rssi_thold = default_match_rssi;
6520
6521 request->min_rssi_thold = INT_MAX;
6522 for (i = 0; i < n_match_sets; i++)
6523 request->min_rssi_thold =
6524 min(request->match_sets[i].rssi_thold,
6525 request->min_rssi_thold);
6526 } else {
6527 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006528 }
6529
Johannes Berg9900e482014-02-04 21:01:25 +01006530 if (ie_len) {
6531 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006532 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006533 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006534 request->ie_len);
6535 }
6536
Luciano Coelho256da022014-11-10 16:13:46 +02006537 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006538 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006539 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006540 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6541 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006542 err = -EOPNOTSUPP;
6543 goto out_free;
6544 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006545
6546 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6547 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6548
6549 if (!wdev) /* must be net-detect */
6550 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6551
6552 if (!(wiphy->features & flg)) {
6553 err = -EOPNOTSUPP;
6554 goto out_free;
6555 }
6556
6557 if (wdev && wdev->current_bss) {
6558 err = -EOPNOTSUPP;
6559 goto out_free;
6560 }
6561
6562 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6563 request->mac_addr_mask);
6564 if (err)
6565 goto out_free;
6566 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006567 }
Sam Lefflered4737712012-10-11 21:03:31 -07006568
Luciano Coelho9c748932015-01-16 16:04:09 +02006569 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6570 request->delay =
6571 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6572
Avraham Stern3b06d272015-10-12 09:51:34 +03006573 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6574 if (err)
6575 goto out_free;
6576
Sam Leffler15d60302012-10-11 21:03:34 -07006577 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006578
Luciano Coelho256da022014-11-10 16:13:46 +02006579 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006580
6581out_free:
6582 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006583 return ERR_PTR(err);
6584}
6585
6586static int nl80211_start_sched_scan(struct sk_buff *skb,
6587 struct genl_info *info)
6588{
6589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6590 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006591 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006592 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006593 int err;
6594
6595 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6596 !rdev->ops->sched_scan_start)
6597 return -EOPNOTSUPP;
6598
6599 if (rdev->sched_scan_req)
6600 return -EINPROGRESS;
6601
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006602 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6603 info->attrs);
6604
6605 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006606 if (err)
6607 goto out_err;
6608
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006609 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006610 if (err)
6611 goto out_free;
6612
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006613 sched_scan_req->dev = dev;
6614 sched_scan_req->wiphy = &rdev->wiphy;
6615
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006616 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6617 sched_scan_req->owner_nlportid = info->snd_portid;
6618
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006619 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006620
6621 nl80211_send_sched_scan(rdev, dev,
6622 NL80211_CMD_START_SCHED_SCAN);
6623 return 0;
6624
6625out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006626 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006627out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006628 return err;
6629}
6630
6631static int nl80211_stop_sched_scan(struct sk_buff *skb,
6632 struct genl_info *info)
6633{
6634 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6635
6636 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6637 !rdev->ops->sched_scan_stop)
6638 return -EOPNOTSUPP;
6639
Johannes Berg5fe231e2013-05-08 21:45:15 +02006640 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006641}
6642
Simon Wunderlich04f39042013-02-08 18:16:19 +01006643static int nl80211_start_radar_detection(struct sk_buff *skb,
6644 struct genl_info *info)
6645{
6646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6647 struct net_device *dev = info->user_ptr[1];
6648 struct wireless_dev *wdev = dev->ieee80211_ptr;
6649 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006650 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006651 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006652 int err;
6653
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006654 dfs_region = reg_get_dfs_region(wdev->wiphy);
6655 if (dfs_region == NL80211_DFS_UNSET)
6656 return -EINVAL;
6657
Simon Wunderlich04f39042013-02-08 18:16:19 +01006658 err = nl80211_parse_chandef(rdev, info, &chandef);
6659 if (err)
6660 return err;
6661
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006662 if (netif_carrier_ok(dev))
6663 return -EBUSY;
6664
Simon Wunderlich04f39042013-02-08 18:16:19 +01006665 if (wdev->cac_started)
6666 return -EBUSY;
6667
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006668 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006669 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006670 if (err < 0)
6671 return err;
6672
6673 if (err == 0)
6674 return -EINVAL;
6675
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006676 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006677 return -EINVAL;
6678
6679 if (!rdev->ops->start_radar_detection)
6680 return -EOPNOTSUPP;
6681
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006682 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6683 if (WARN_ON(!cac_time_ms))
6684 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6685
Ilan Peera1056b12015-10-22 22:27:46 +03006686 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006687 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006688 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006689 wdev->cac_started = true;
6690 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006691 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006692 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006693 return err;
6694}
6695
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006696static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6697{
6698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6699 struct net_device *dev = info->user_ptr[1];
6700 struct wireless_dev *wdev = dev->ieee80211_ptr;
6701 struct cfg80211_csa_settings params;
6702 /* csa_attrs is defined static to avoid waste of stack size - this
6703 * function is called under RTNL lock, so this should not be a problem.
6704 */
6705 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006706 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006707 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006708 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006709 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006710
6711 if (!rdev->ops->channel_switch ||
6712 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6713 return -EOPNOTSUPP;
6714
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006715 switch (dev->ieee80211_ptr->iftype) {
6716 case NL80211_IFTYPE_AP:
6717 case NL80211_IFTYPE_P2P_GO:
6718 need_new_beacon = true;
6719
6720 /* useless if AP is not running */
6721 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006722 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006723 break;
6724 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006725 if (!wdev->ssid_len)
6726 return -ENOTCONN;
6727 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006728 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006729 if (!wdev->mesh_id_len)
6730 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006731 break;
6732 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006733 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006734 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006735
6736 memset(&params, 0, sizeof(params));
6737
6738 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6739 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6740 return -EINVAL;
6741
6742 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006743 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006744 return -EINVAL;
6745
Luciano Coelho252e07c2014-10-08 09:48:34 +03006746 /* Even though the attribute is u32, the specification says
6747 * u8, so let's make sure we don't overflow.
6748 */
6749 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6750 if (cs_count > 255)
6751 return -EINVAL;
6752
6753 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006754
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006755 if (!need_new_beacon)
6756 goto skip_beacons;
6757
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006758 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6759 if (err)
6760 return err;
6761
6762 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6763 info->attrs[NL80211_ATTR_CSA_IES],
6764 nl80211_policy);
6765 if (err)
6766 return err;
6767
6768 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6769 if (err)
6770 return err;
6771
6772 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6773 return -EINVAL;
6774
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006775 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6776 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006777 return -EINVAL;
6778
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006779 params.n_counter_offsets_beacon = len / sizeof(u16);
6780 if (rdev->wiphy.max_num_csa_counters &&
6781 (params.n_counter_offsets_beacon >
6782 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006783 return -EINVAL;
6784
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006785 params.counter_offsets_beacon =
6786 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6787
6788 /* sanity checks - counters should fit and be the same */
6789 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6790 u16 offset = params.counter_offsets_beacon[i];
6791
6792 if (offset >= params.beacon_csa.tail_len)
6793 return -EINVAL;
6794
6795 if (params.beacon_csa.tail[offset] != params.count)
6796 return -EINVAL;
6797 }
6798
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006799 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006800 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6801 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006802 return -EINVAL;
6803
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006804 params.n_counter_offsets_presp = len / sizeof(u16);
6805 if (rdev->wiphy.max_num_csa_counters &&
6806 (params.n_counter_offsets_beacon >
6807 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006808 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006809
6810 params.counter_offsets_presp =
6811 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6812
6813 /* sanity checks - counters should fit and be the same */
6814 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6815 u16 offset = params.counter_offsets_presp[i];
6816
6817 if (offset >= params.beacon_csa.probe_resp_len)
6818 return -EINVAL;
6819
6820 if (params.beacon_csa.probe_resp[offset] !=
6821 params.count)
6822 return -EINVAL;
6823 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006824 }
6825
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006826skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006827 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6828 if (err)
6829 return err;
6830
Arik Nemtsov923b3522015-07-08 15:41:44 +03006831 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6832 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006833 return -EINVAL;
6834
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006835 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6836 &params.chandef,
6837 wdev->iftype);
6838 if (err < 0)
6839 return err;
6840
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006841 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006842 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006843
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006844 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6845 params.block_tx = true;
6846
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006847 wdev_lock(wdev);
6848 err = rdev_channel_switch(rdev, dev, &params);
6849 wdev_unlock(wdev);
6850
6851 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006852}
6853
Johannes Berg9720bb32011-06-21 09:45:33 +02006854static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6855 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006856 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006857 struct wireless_dev *wdev,
6858 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006859{
Johannes Berg48ab9052009-07-10 18:42:31 +02006860 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006861 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006862 void *hdr;
6863 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006864
6865 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006866
Eric W. Biederman15e47302012-09-07 20:12:54 +00006867 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006868 NL80211_CMD_NEW_SCAN_RESULTS);
6869 if (!hdr)
6870 return -1;
6871
Johannes Berg9720bb32011-06-21 09:45:33 +02006872 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6873
Johannes Berg97990a02013-04-19 01:02:55 +02006874 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6875 goto nla_put_failure;
6876 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006877 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6878 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006879 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
6880 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02006881 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006882
6883 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6884 if (!bss)
6885 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006886 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006887 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006888 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006889
6890 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006891 /* indicate whether we have probe response data or not */
6892 if (rcu_access_pointer(res->proberesp_ies) &&
6893 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6894 goto fail_unlock_rcu;
6895
6896 /* this pointer prefers to be pointed to probe response data
6897 * but is always valid
6898 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006899 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006900 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006901 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
6902 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006903 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006904 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6905 ies->len, ies->data))
6906 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006907 }
Johannes Berg0e227082014-08-12 20:34:30 +02006908
6909 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006910 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006911 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006912 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
6913 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006914 goto fail_unlock_rcu;
6915 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6916 ies->len, ies->data))
6917 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006918 }
6919 rcu_read_unlock();
6920
David S. Miller9360ffd2012-03-29 04:41:26 -04006921 if (res->beacon_interval &&
6922 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6923 goto nla_put_failure;
6924 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6925 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006926 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006927 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6928 jiffies_to_msecs(jiffies - intbss->ts)))
6929 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006930
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006931 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006932 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6933 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006934 goto nla_put_failure;
6935
Johannes Berg77965c92009-02-18 18:45:06 +01006936 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006937 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006938 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6939 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006940 break;
6941 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006942 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6943 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006944 break;
6945 default:
6946 break;
6947 }
6948
Johannes Berg48ab9052009-07-10 18:42:31 +02006949 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006950 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006951 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006952 if (intbss == wdev->current_bss &&
6953 nla_put_u32(msg, NL80211_BSS_STATUS,
6954 NL80211_BSS_STATUS_ASSOCIATED))
6955 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006956 break;
6957 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006958 if (intbss == wdev->current_bss &&
6959 nla_put_u32(msg, NL80211_BSS_STATUS,
6960 NL80211_BSS_STATUS_IBSS_JOINED))
6961 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006962 break;
6963 default:
6964 break;
6965 }
6966
Johannes Berg2a519312009-02-10 21:25:55 +01006967 nla_nest_end(msg, bss);
6968
Johannes Berg053c0952015-01-16 22:09:00 +01006969 genlmsg_end(msg, hdr);
6970 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006971
Johannes Berg8cef2c92013-02-05 16:54:31 +01006972 fail_unlock_rcu:
6973 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006974 nla_put_failure:
6975 genlmsg_cancel(msg, hdr);
6976 return -EMSGSIZE;
6977}
6978
Johannes Berg97990a02013-04-19 01:02:55 +02006979static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006980{
Johannes Berg48ab9052009-07-10 18:42:31 +02006981 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006982 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006983 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006984 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006985 int err;
6986
Johannes Berg97990a02013-04-19 01:02:55 +02006987 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006988 if (err)
6989 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006990
Johannes Berg48ab9052009-07-10 18:42:31 +02006991 wdev_lock(wdev);
6992 spin_lock_bh(&rdev->bss_lock);
6993 cfg80211_bss_expire(rdev);
6994
Johannes Berg9720bb32011-06-21 09:45:33 +02006995 cb->seq = rdev->bss_generation;
6996
Johannes Berg48ab9052009-07-10 18:42:31 +02006997 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006998 if (++idx <= start)
6999 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007000 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007001 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007002 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007003 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007004 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007005 }
7006 }
7007
Johannes Berg48ab9052009-07-10 18:42:31 +02007008 spin_unlock_bh(&rdev->bss_lock);
7009 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007010
Johannes Berg97990a02013-04-19 01:02:55 +02007011 cb->args[2] = idx;
7012 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007013
Johannes Berg67748892010-10-04 21:14:06 +02007014 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007015}
7016
Eric W. Biederman15e47302012-09-07 20:12:54 +00007017static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007018 int flags, struct net_device *dev,
7019 bool allow_radio_stats,
7020 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007021{
7022 void *hdr;
7023 struct nlattr *infoattr;
7024
Johannes Berg11f78ac2014-11-14 16:43:50 +01007025 /* skip radio stats if userspace didn't request them */
7026 if (!survey->channel && !allow_radio_stats)
7027 return 0;
7028
Eric W. Biederman15e47302012-09-07 20:12:54 +00007029 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007030 NL80211_CMD_NEW_SURVEY_RESULTS);
7031 if (!hdr)
7032 return -ENOMEM;
7033
David S. Miller9360ffd2012-03-29 04:41:26 -04007034 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7035 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007036
7037 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7038 if (!infoattr)
7039 goto nla_put_failure;
7040
Johannes Berg11f78ac2014-11-14 16:43:50 +01007041 if (survey->channel &&
7042 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007043 survey->channel->center_freq))
7044 goto nla_put_failure;
7045
7046 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7047 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7048 goto nla_put_failure;
7049 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7050 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7051 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007052 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007053 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7054 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007055 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007056 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007057 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7058 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007059 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007060 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007061 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7062 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007063 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007064 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007065 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7066 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007067 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007068 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007069 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7070 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007071 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007072 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007073 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7074 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007075 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007076
7077 nla_nest_end(msg, infoattr);
7078
Johannes Berg053c0952015-01-16 22:09:00 +01007079 genlmsg_end(msg, hdr);
7080 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007081
7082 nla_put_failure:
7083 genlmsg_cancel(msg, hdr);
7084 return -EMSGSIZE;
7085}
7086
Johannes Berg11f78ac2014-11-14 16:43:50 +01007087static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007088{
7089 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007090 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007091 struct wireless_dev *wdev;
7092 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007093 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007094 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007095
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007096 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007097 if (res)
7098 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007099
Johannes Berg11f78ac2014-11-14 16:43:50 +01007100 /* prepare_wdev_dump parsed the attributes */
7101 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7102
Johannes Berg97990a02013-04-19 01:02:55 +02007103 if (!wdev->netdev) {
7104 res = -EINVAL;
7105 goto out_err;
7106 }
7107
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007108 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007109 res = -EOPNOTSUPP;
7110 goto out_err;
7111 }
7112
7113 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007114 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007115 if (res == -ENOENT)
7116 break;
7117 if (res)
7118 goto out_err;
7119
Johannes Berg11f78ac2014-11-14 16:43:50 +01007120 /* don't send disabled channels, but do send non-channel data */
7121 if (survey.channel &&
7122 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007123 survey_idx++;
7124 continue;
7125 }
7126
Holger Schurig61fa7132009-11-11 12:25:40 +01007127 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007128 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007129 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007130 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007131 goto out;
7132 survey_idx++;
7133 }
7134
7135 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007136 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007137 res = skb->len;
7138 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007139 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007140 return res;
7141}
7142
Samuel Ortizb23aa672009-07-01 21:26:54 +02007143static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7144{
7145 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7146 NL80211_WPA_VERSION_2));
7147}
7148
Jouni Malinen636a5d32009-03-19 13:39:22 +02007149static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7150{
Johannes Berg4c476992010-10-04 21:36:35 +02007151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7152 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007153 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007154 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7155 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007156 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007157 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007158 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007159
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007160 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7161 return -EINVAL;
7162
7163 if (!info->attrs[NL80211_ATTR_MAC])
7164 return -EINVAL;
7165
Jouni Malinen17780922009-03-27 20:52:47 +02007166 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7167 return -EINVAL;
7168
Johannes Berg19957bb2009-07-02 17:20:43 +02007169 if (!info->attrs[NL80211_ATTR_SSID])
7170 return -EINVAL;
7171
7172 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7173 return -EINVAL;
7174
Johannes Bergfffd0932009-07-08 14:22:54 +02007175 err = nl80211_parse_key(info, &key);
7176 if (err)
7177 return err;
7178
7179 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007180 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7181 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007182 if (!key.p.key || !key.p.key_len)
7183 return -EINVAL;
7184 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7185 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7186 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7187 key.p.key_len != WLAN_KEY_LEN_WEP104))
7188 return -EINVAL;
7189 if (key.idx > 4)
7190 return -EINVAL;
7191 } else {
7192 key.p.key_len = 0;
7193 key.p.key = NULL;
7194 }
7195
Johannes Bergafea0b72010-08-10 09:46:42 +02007196 if (key.idx >= 0) {
7197 int i;
7198 bool ok = false;
7199 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7200 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7201 ok = true;
7202 break;
7203 }
7204 }
Johannes Berg4c476992010-10-04 21:36:35 +02007205 if (!ok)
7206 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007207 }
7208
Johannes Berg4c476992010-10-04 21:36:35 +02007209 if (!rdev->ops->auth)
7210 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007211
Johannes Berg074ac8d2010-09-16 14:58:22 +02007212 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007213 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7214 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007215
Johannes Berg19957bb2009-07-02 17:20:43 +02007216 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007217 chan = nl80211_get_valid_chan(&rdev->wiphy,
7218 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7219 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007220 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007221
Johannes Berg19957bb2009-07-02 17:20:43 +02007222 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7223 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7224
7225 if (info->attrs[NL80211_ATTR_IE]) {
7226 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7227 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7228 }
7229
7230 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007231 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007232 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007233
Jouni Malinene39e5b52012-09-30 19:29:39 +03007234 if (auth_type == NL80211_AUTHTYPE_SAE &&
7235 !info->attrs[NL80211_ATTR_SAE_DATA])
7236 return -EINVAL;
7237
7238 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7239 if (auth_type != NL80211_AUTHTYPE_SAE)
7240 return -EINVAL;
7241 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7242 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7243 /* need to include at least Auth Transaction and Status Code */
7244 if (sae_data_len < 4)
7245 return -EINVAL;
7246 }
7247
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007248 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7249
Johannes Berg95de8172012-01-20 13:55:25 +01007250 /*
7251 * Since we no longer track auth state, ignore
7252 * requests to only change local state.
7253 */
7254 if (local_state_change)
7255 return 0;
7256
Johannes Berg91bf9b22013-05-15 17:44:01 +02007257 wdev_lock(dev->ieee80211_ptr);
7258 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7259 ssid, ssid_len, ie, ie_len,
7260 key.p.key, key.p.key_len, key.idx,
7261 sae_data, sae_data_len);
7262 wdev_unlock(dev->ieee80211_ptr);
7263 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007264}
7265
Johannes Bergc0692b82010-08-27 14:26:53 +03007266static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7267 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007268 struct cfg80211_crypto_settings *settings,
7269 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007270{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007271 memset(settings, 0, sizeof(*settings));
7272
Samuel Ortizb23aa672009-07-01 21:26:54 +02007273 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7274
Johannes Bergc0692b82010-08-27 14:26:53 +03007275 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7276 u16 proto;
7277 proto = nla_get_u16(
7278 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7279 settings->control_port_ethertype = cpu_to_be16(proto);
7280 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7281 proto != ETH_P_PAE)
7282 return -EINVAL;
7283 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7284 settings->control_port_no_encrypt = true;
7285 } else
7286 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7287
Samuel Ortizb23aa672009-07-01 21:26:54 +02007288 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7289 void *data;
7290 int len, i;
7291
7292 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7293 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7294 settings->n_ciphers_pairwise = len / sizeof(u32);
7295
7296 if (len % sizeof(u32))
7297 return -EINVAL;
7298
Johannes Berg3dc27d22009-07-02 21:36:37 +02007299 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007300 return -EINVAL;
7301
7302 memcpy(settings->ciphers_pairwise, data, len);
7303
7304 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007305 if (!cfg80211_supported_cipher_suite(
7306 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007307 settings->ciphers_pairwise[i]))
7308 return -EINVAL;
7309 }
7310
7311 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7312 settings->cipher_group =
7313 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007314 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7315 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007316 return -EINVAL;
7317 }
7318
7319 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7320 settings->wpa_versions =
7321 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7322 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7323 return -EINVAL;
7324 }
7325
7326 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7327 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007328 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007329
7330 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7331 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7332 settings->n_akm_suites = len / sizeof(u32);
7333
7334 if (len % sizeof(u32))
7335 return -EINVAL;
7336
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007337 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7338 return -EINVAL;
7339
Samuel Ortizb23aa672009-07-01 21:26:54 +02007340 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007341 }
7342
7343 return 0;
7344}
7345
Jouni Malinen636a5d32009-03-19 13:39:22 +02007346static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7347{
Johannes Berg4c476992010-10-04 21:36:35 +02007348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7349 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007350 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007351 struct cfg80211_assoc_request req = {};
7352 const u8 *bssid, *ssid;
7353 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007354
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007355 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7356 return -EINVAL;
7357
7358 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007359 !info->attrs[NL80211_ATTR_SSID] ||
7360 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007361 return -EINVAL;
7362
Johannes Berg4c476992010-10-04 21:36:35 +02007363 if (!rdev->ops->assoc)
7364 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007365
Johannes Berg074ac8d2010-09-16 14:58:22 +02007366 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007367 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7368 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007369
Johannes Berg19957bb2009-07-02 17:20:43 +02007370 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007371
Jouni Malinen664834d2014-01-15 00:01:44 +02007372 chan = nl80211_get_valid_chan(&rdev->wiphy,
7373 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7374 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007375 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007376
Johannes Berg19957bb2009-07-02 17:20:43 +02007377 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7378 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007379
7380 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007381 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7382 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007383 }
7384
Jouni Malinendc6382c2009-05-06 22:09:37 +03007385 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007386 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007387 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007388 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007389 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007390 else if (mfp != NL80211_MFP_NO)
7391 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007392 }
7393
Johannes Berg3e5d7642009-07-07 14:37:26 +02007394 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007395 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007396
Ben Greear7e7c8922011-11-18 11:31:59 -08007397 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007398 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007399
7400 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007401 memcpy(&req.ht_capa_mask,
7402 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7403 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007404
7405 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007406 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007407 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007408 memcpy(&req.ht_capa,
7409 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7410 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007411 }
7412
Johannes Bergee2aca32013-02-21 17:36:01 +01007413 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007414 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007415
7416 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007417 memcpy(&req.vht_capa_mask,
7418 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7419 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007420
7421 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007422 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007423 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007424 memcpy(&req.vht_capa,
7425 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7426 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007427 }
7428
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007429 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007430 if (!((rdev->wiphy.features &
7431 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7432 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7433 !wiphy_ext_feature_isset(&rdev->wiphy,
7434 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007435 return -EINVAL;
7436 req.flags |= ASSOC_REQ_USE_RRM;
7437 }
7438
Johannes Bergf62fab72013-02-21 20:09:09 +01007439 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007440 if (!err) {
7441 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007442 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7443 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007444 wdev_unlock(dev->ieee80211_ptr);
7445 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007446
Jouni Malinen636a5d32009-03-19 13:39:22 +02007447 return err;
7448}
7449
7450static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7451{
Johannes Berg4c476992010-10-04 21:36:35 +02007452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7453 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007454 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007455 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007456 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007457 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007458
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007459 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7460 return -EINVAL;
7461
7462 if (!info->attrs[NL80211_ATTR_MAC])
7463 return -EINVAL;
7464
7465 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7466 return -EINVAL;
7467
Johannes Berg4c476992010-10-04 21:36:35 +02007468 if (!rdev->ops->deauth)
7469 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007470
Johannes Berg074ac8d2010-09-16 14:58:22 +02007471 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007472 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7473 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007474
Johannes Berg19957bb2009-07-02 17:20:43 +02007475 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007476
Johannes Berg19957bb2009-07-02 17:20:43 +02007477 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7478 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007479 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007480 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007481 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007482
7483 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007484 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7485 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007486 }
7487
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007488 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7489
Johannes Berg91bf9b22013-05-15 17:44:01 +02007490 wdev_lock(dev->ieee80211_ptr);
7491 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7492 local_state_change);
7493 wdev_unlock(dev->ieee80211_ptr);
7494 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007495}
7496
7497static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7498{
Johannes Berg4c476992010-10-04 21:36:35 +02007499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7500 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007501 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007502 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007503 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007504 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007505
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007506 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7507 return -EINVAL;
7508
7509 if (!info->attrs[NL80211_ATTR_MAC])
7510 return -EINVAL;
7511
7512 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7513 return -EINVAL;
7514
Johannes Berg4c476992010-10-04 21:36:35 +02007515 if (!rdev->ops->disassoc)
7516 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007517
Johannes Berg074ac8d2010-09-16 14:58:22 +02007518 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007519 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7520 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007521
Johannes Berg19957bb2009-07-02 17:20:43 +02007522 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007523
Johannes Berg19957bb2009-07-02 17:20:43 +02007524 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7525 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007526 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007527 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007528 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007529
7530 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007531 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7532 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007533 }
7534
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007535 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7536
Johannes Berg91bf9b22013-05-15 17:44:01 +02007537 wdev_lock(dev->ieee80211_ptr);
7538 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7539 local_state_change);
7540 wdev_unlock(dev->ieee80211_ptr);
7541 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007542}
7543
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007544static bool
7545nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007546 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007547 int rateval)
7548{
7549 struct wiphy *wiphy = &rdev->wiphy;
7550 bool found = false;
7551 int band, i;
7552
Johannes Berg57fbcce2016-04-12 15:56:15 +02007553 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007554 struct ieee80211_supported_band *sband;
7555
7556 sband = wiphy->bands[band];
7557 if (!sband)
7558 continue;
7559
7560 for (i = 0; i < sband->n_bitrates; i++) {
7561 if (sband->bitrates[i].bitrate == rateval) {
7562 mcast_rate[band] = i + 1;
7563 found = true;
7564 break;
7565 }
7566 }
7567 }
7568
7569 return found;
7570}
7571
Johannes Berg04a773a2009-04-19 21:24:32 +02007572static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7573{
Johannes Berg4c476992010-10-04 21:36:35 +02007574 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7575 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007576 struct cfg80211_ibss_params ibss;
7577 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007578 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007579 int err;
7580
Johannes Berg8e30bc52009-04-22 17:45:38 +02007581 memset(&ibss, 0, sizeof(ibss));
7582
Johannes Berg04a773a2009-04-19 21:24:32 +02007583 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7584 return -EINVAL;
7585
Johannes Berg683b6d32012-11-08 21:25:48 +01007586 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007587 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7588 return -EINVAL;
7589
Johannes Berg8e30bc52009-04-22 17:45:38 +02007590 ibss.beacon_interval = 100;
7591
7592 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7593 ibss.beacon_interval =
7594 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7595 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7596 return -EINVAL;
7597 }
7598
Johannes Berg4c476992010-10-04 21:36:35 +02007599 if (!rdev->ops->join_ibss)
7600 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007601
Johannes Berg4c476992010-10-04 21:36:35 +02007602 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7603 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007604
Johannes Berg79c97e92009-07-07 03:56:12 +02007605 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007606
Johannes Berg39193492011-09-16 13:45:25 +02007607 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007608 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007609
7610 if (!is_valid_ether_addr(ibss.bssid))
7611 return -EINVAL;
7612 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007613 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7614 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7615
7616 if (info->attrs[NL80211_ATTR_IE]) {
7617 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7618 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7619 }
7620
Johannes Berg683b6d32012-11-08 21:25:48 +01007621 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7622 if (err)
7623 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007624
Ilan Peer174e0cd2014-02-23 09:13:01 +02007625 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7626 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007627 return -EINVAL;
7628
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007629 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007630 case NL80211_CHAN_WIDTH_5:
7631 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007632 case NL80211_CHAN_WIDTH_20_NOHT:
7633 break;
7634 case NL80211_CHAN_WIDTH_20:
7635 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007636 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7637 return -EINVAL;
7638 break;
7639 case NL80211_CHAN_WIDTH_80:
7640 case NL80211_CHAN_WIDTH_80P80:
7641 case NL80211_CHAN_WIDTH_160:
7642 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7643 return -EINVAL;
7644 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7645 NL80211_EXT_FEATURE_VHT_IBSS))
7646 return -EINVAL;
7647 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007648 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007649 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007650 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007651
Johannes Berg04a773a2009-04-19 21:24:32 +02007652 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007653 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007654
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007655 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7656 u8 *rates =
7657 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7658 int n_rates =
7659 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7660 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007661 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007662
Johannes Berg34850ab2011-07-18 18:08:35 +02007663 err = ieee80211_get_ratemask(sband, rates, n_rates,
7664 &ibss.basic_rates);
7665 if (err)
7666 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007667 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007668
Simon Wunderlich803768f2013-06-28 10:39:58 +02007669 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7670 memcpy(&ibss.ht_capa_mask,
7671 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7672 sizeof(ibss.ht_capa_mask));
7673
7674 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7675 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7676 return -EINVAL;
7677 memcpy(&ibss.ht_capa,
7678 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7679 sizeof(ibss.ht_capa));
7680 }
7681
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007682 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7683 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7684 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7685 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007686
Johannes Berg4c476992010-10-04 21:36:35 +02007687 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307688 bool no_ht = false;
7689
Johannes Berg4c476992010-10-04 21:36:35 +02007690 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307691 info->attrs[NL80211_ATTR_KEYS],
7692 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007693 if (IS_ERR(connkeys))
7694 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307695
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007696 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7697 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007698 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307699 return -EINVAL;
7700 }
Johannes Berg4c476992010-10-04 21:36:35 +02007701 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007702
Antonio Quartulli267335d2012-01-31 20:25:47 +01007703 ibss.control_port =
7704 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7705
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007706 ibss.userspace_handles_dfs =
7707 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7708
Johannes Berg4c476992010-10-04 21:36:35 +02007709 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007710 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007711 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007712 return err;
7713}
7714
7715static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7716{
Johannes Berg4c476992010-10-04 21:36:35 +02007717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7718 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007719
Johannes Berg4c476992010-10-04 21:36:35 +02007720 if (!rdev->ops->leave_ibss)
7721 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007722
Johannes Berg4c476992010-10-04 21:36:35 +02007723 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7724 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007725
Johannes Berg4c476992010-10-04 21:36:35 +02007726 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007727}
7728
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007729static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7730{
7731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7732 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007733 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007734 u32 nla_rate;
7735 int err;
7736
7737 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007738 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7739 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007740 return -EOPNOTSUPP;
7741
7742 if (!rdev->ops->set_mcast_rate)
7743 return -EOPNOTSUPP;
7744
7745 memset(mcast_rate, 0, sizeof(mcast_rate));
7746
7747 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7748 return -EINVAL;
7749
7750 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7751 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7752 return -EINVAL;
7753
Ilan Peera1056b12015-10-22 22:27:46 +03007754 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007755
7756 return err;
7757}
7758
Johannes Bergad7e7182013-11-13 13:37:47 +01007759static struct sk_buff *
7760__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007761 struct wireless_dev *wdev, int approxlen,
7762 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007763 enum nl80211_attrs attr,
7764 const struct nl80211_vendor_cmd_info *info,
7765 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007766{
7767 struct sk_buff *skb;
7768 void *hdr;
7769 struct nlattr *data;
7770
7771 skb = nlmsg_new(approxlen + 100, gfp);
7772 if (!skb)
7773 return NULL;
7774
7775 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7776 if (!hdr) {
7777 kfree_skb(skb);
7778 return NULL;
7779 }
7780
7781 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7782 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007783
7784 if (info) {
7785 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7786 info->vendor_id))
7787 goto nla_put_failure;
7788 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7789 info->subcmd))
7790 goto nla_put_failure;
7791 }
7792
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007793 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007794 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7795 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007796 goto nla_put_failure;
7797 if (wdev->netdev &&
7798 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7799 wdev->netdev->ifindex))
7800 goto nla_put_failure;
7801 }
7802
Johannes Bergad7e7182013-11-13 13:37:47 +01007803 data = nla_nest_start(skb, attr);
7804
7805 ((void **)skb->cb)[0] = rdev;
7806 ((void **)skb->cb)[1] = hdr;
7807 ((void **)skb->cb)[2] = data;
7808
7809 return skb;
7810
7811 nla_put_failure:
7812 kfree_skb(skb);
7813 return NULL;
7814}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007815
Johannes Berge03ad6e2014-01-01 17:22:30 +01007816struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007817 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007818 enum nl80211_commands cmd,
7819 enum nl80211_attrs attr,
7820 int vendor_event_idx,
7821 int approxlen, gfp_t gfp)
7822{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007823 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007824 const struct nl80211_vendor_cmd_info *info;
7825
7826 switch (cmd) {
7827 case NL80211_CMD_TESTMODE:
7828 if (WARN_ON(vendor_event_idx != -1))
7829 return NULL;
7830 info = NULL;
7831 break;
7832 case NL80211_CMD_VENDOR:
7833 if (WARN_ON(vendor_event_idx < 0 ||
7834 vendor_event_idx >= wiphy->n_vendor_events))
7835 return NULL;
7836 info = &wiphy->vendor_events[vendor_event_idx];
7837 break;
7838 default:
7839 WARN_ON(1);
7840 return NULL;
7841 }
7842
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007843 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007844 cmd, attr, info, gfp);
7845}
7846EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7847
7848void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7849{
7850 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7851 void *hdr = ((void **)skb->cb)[1];
7852 struct nlattr *data = ((void **)skb->cb)[2];
7853 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7854
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007855 /* clear CB data for netlink core to own from now on */
7856 memset(skb->cb, 0, sizeof(skb->cb));
7857
Johannes Berge03ad6e2014-01-01 17:22:30 +01007858 nla_nest_end(skb, data);
7859 genlmsg_end(skb, hdr);
7860
7861 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7862 mcgrp = NL80211_MCGRP_VENDOR;
7863
7864 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7865 mcgrp, gfp);
7866}
7867EXPORT_SYMBOL(__cfg80211_send_event_skb);
7868
Johannes Bergaff89a92009-07-01 21:26:51 +02007869#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007870static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7871{
Johannes Berg4c476992010-10-04 21:36:35 +02007872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007873 struct wireless_dev *wdev =
7874 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007875 int err;
7876
David Spinadelfc73f112013-07-31 18:04:15 +03007877 if (!rdev->ops->testmode_cmd)
7878 return -EOPNOTSUPP;
7879
7880 if (IS_ERR(wdev)) {
7881 err = PTR_ERR(wdev);
7882 if (err != -EINVAL)
7883 return err;
7884 wdev = NULL;
7885 } else if (wdev->wiphy != &rdev->wiphy) {
7886 return -EINVAL;
7887 }
7888
Johannes Bergaff89a92009-07-01 21:26:51 +02007889 if (!info->attrs[NL80211_ATTR_TESTDATA])
7890 return -EINVAL;
7891
Johannes Bergad7e7182013-11-13 13:37:47 +01007892 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007893 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007894 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7895 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007896 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007897
Johannes Bergaff89a92009-07-01 21:26:51 +02007898 return err;
7899}
7900
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007901static int nl80211_testmode_dump(struct sk_buff *skb,
7902 struct netlink_callback *cb)
7903{
Johannes Berg00918d32011-12-13 17:22:05 +01007904 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007905 int err;
7906 long phy_idx;
7907 void *data = NULL;
7908 int data_len = 0;
7909
Johannes Berg5fe231e2013-05-08 21:45:15 +02007910 rtnl_lock();
7911
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007912 if (cb->args[0]) {
7913 /*
7914 * 0 is a valid index, but not valid for args[0],
7915 * so we need to offset by 1.
7916 */
7917 phy_idx = cb->args[0] - 1;
7918 } else {
7919 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7920 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7921 nl80211_policy);
7922 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007923 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007924
Johannes Berg2bd7e352012-06-15 14:23:16 +02007925 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7926 nl80211_fam.attrbuf);
7927 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007928 err = PTR_ERR(rdev);
7929 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007930 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007931 phy_idx = rdev->wiphy_idx;
7932 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007933
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007934 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7935 cb->args[1] =
7936 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7937 }
7938
7939 if (cb->args[1]) {
7940 data = nla_data((void *)cb->args[1]);
7941 data_len = nla_len((void *)cb->args[1]);
7942 }
7943
Johannes Berg00918d32011-12-13 17:22:05 +01007944 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7945 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007946 err = -ENOENT;
7947 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007948 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007949
Johannes Berg00918d32011-12-13 17:22:05 +01007950 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007951 err = -EOPNOTSUPP;
7952 goto out_err;
7953 }
7954
7955 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007956 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007957 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7958 NL80211_CMD_TESTMODE);
7959 struct nlattr *tmdata;
7960
Dan Carpentercb35fba2013-08-14 14:50:01 +03007961 if (!hdr)
7962 break;
7963
David S. Miller9360ffd2012-03-29 04:41:26 -04007964 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007965 genlmsg_cancel(skb, hdr);
7966 break;
7967 }
7968
7969 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7970 if (!tmdata) {
7971 genlmsg_cancel(skb, hdr);
7972 break;
7973 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007974 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007975 nla_nest_end(skb, tmdata);
7976
7977 if (err == -ENOBUFS || err == -ENOENT) {
7978 genlmsg_cancel(skb, hdr);
7979 break;
7980 } else if (err) {
7981 genlmsg_cancel(skb, hdr);
7982 goto out_err;
7983 }
7984
7985 genlmsg_end(skb, hdr);
7986 }
7987
7988 err = skb->len;
7989 /* see above */
7990 cb->args[0] = phy_idx + 1;
7991 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007992 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007993 return err;
7994}
Johannes Bergaff89a92009-07-01 21:26:51 +02007995#endif
7996
Samuel Ortizb23aa672009-07-01 21:26:54 +02007997static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7998{
Johannes Berg4c476992010-10-04 21:36:35 +02007999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8000 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008001 struct cfg80211_connect_params connect;
8002 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008003 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008004 int err;
8005
8006 memset(&connect, 0, sizeof(connect));
8007
8008 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8009 return -EINVAL;
8010
8011 if (!info->attrs[NL80211_ATTR_SSID] ||
8012 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8013 return -EINVAL;
8014
8015 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8016 connect.auth_type =
8017 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008018 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8019 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008020 return -EINVAL;
8021 } else
8022 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8023
8024 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8025
Johannes Bergc0692b82010-08-27 14:26:53 +03008026 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008027 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008028 if (err)
8029 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008030
Johannes Berg074ac8d2010-09-16 14:58:22 +02008031 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008032 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8033 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008034
Johannes Berg79c97e92009-07-07 03:56:12 +02008035 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008036
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308037 connect.bg_scan_period = -1;
8038 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8039 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8040 connect.bg_scan_period =
8041 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8042 }
8043
Samuel Ortizb23aa672009-07-01 21:26:54 +02008044 if (info->attrs[NL80211_ATTR_MAC])
8045 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008046 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8047 connect.bssid_hint =
8048 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008049 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8050 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8051
8052 if (info->attrs[NL80211_ATTR_IE]) {
8053 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8054 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8055 }
8056
Jouni Malinencee00a92013-01-15 17:15:57 +02008057 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8058 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8059 if (connect.mfp != NL80211_MFP_REQUIRED &&
8060 connect.mfp != NL80211_MFP_NO)
8061 return -EINVAL;
8062 } else {
8063 connect.mfp = NL80211_MFP_NO;
8064 }
8065
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008066 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8067 connect.prev_bssid =
8068 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8069
Samuel Ortizb23aa672009-07-01 21:26:54 +02008070 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008071 connect.channel = nl80211_get_valid_chan(
8072 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8073 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008074 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008075 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008076 connect.channel_hint = nl80211_get_valid_chan(
8077 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8078 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008079 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008080 }
8081
Johannes Bergfffd0932009-07-08 14:22:54 +02008082 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8083 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308084 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008085 if (IS_ERR(connkeys))
8086 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008087 }
8088
Ben Greear7e7c8922011-11-18 11:31:59 -08008089 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8090 connect.flags |= ASSOC_REQ_DISABLE_HT;
8091
8092 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8093 memcpy(&connect.ht_capa_mask,
8094 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8095 sizeof(connect.ht_capa_mask));
8096
8097 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008098 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008099 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008100 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008101 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008102 memcpy(&connect.ht_capa,
8103 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8104 sizeof(connect.ht_capa));
8105 }
8106
Johannes Bergee2aca32013-02-21 17:36:01 +01008107 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8108 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8109
8110 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8111 memcpy(&connect.vht_capa_mask,
8112 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8113 sizeof(connect.vht_capa_mask));
8114
8115 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8116 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008117 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008118 return -EINVAL;
8119 }
8120 memcpy(&connect.vht_capa,
8121 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8122 sizeof(connect.vht_capa));
8123 }
8124
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008125 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008126 if (!((rdev->wiphy.features &
8127 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8128 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8129 !wiphy_ext_feature_isset(&rdev->wiphy,
8130 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008131 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008132 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008133 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008134 connect.flags |= ASSOC_REQ_USE_RRM;
8135 }
8136
Lior David34d50512016-01-28 10:58:25 +02008137 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008138 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008139 kzfree(connkeys);
8140 return -EOPNOTSUPP;
8141 }
8142
Arend van Spriel38de03d2016-03-02 20:37:18 +01008143 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8144 /* bss selection makes no sense if bssid is set */
8145 if (connect.bssid) {
8146 kzfree(connkeys);
8147 return -EINVAL;
8148 }
8149
8150 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8151 wiphy, &connect.bss_select);
8152 if (err) {
8153 kzfree(connkeys);
8154 return err;
8155 }
8156 }
8157
Johannes Berg83739b02013-05-15 17:44:01 +02008158 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008159 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8160 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008161 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008162 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008163 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008164 return err;
8165}
8166
8167static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8168{
Johannes Berg4c476992010-10-04 21:36:35 +02008169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8170 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008171 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008172 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008173
8174 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8175 reason = WLAN_REASON_DEAUTH_LEAVING;
8176 else
8177 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8178
8179 if (reason == 0)
8180 return -EINVAL;
8181
Johannes Berg074ac8d2010-09-16 14:58:22 +02008182 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8184 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008185
Johannes Berg83739b02013-05-15 17:44:01 +02008186 wdev_lock(dev->ieee80211_ptr);
8187 ret = cfg80211_disconnect(rdev, dev, reason, true);
8188 wdev_unlock(dev->ieee80211_ptr);
8189 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008190}
8191
Johannes Berg463d0182009-07-14 00:33:35 +02008192static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8193{
Johannes Berg4c476992010-10-04 21:36:35 +02008194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008195 struct net *net;
8196 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008197
Vadim Kochan4b681c82015-01-12 16:34:05 +02008198 if (info->attrs[NL80211_ATTR_PID]) {
8199 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8200
8201 net = get_net_ns_by_pid(pid);
8202 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8203 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8204
8205 net = get_net_ns_by_fd(fd);
8206 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008207 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008208 }
Johannes Berg463d0182009-07-14 00:33:35 +02008209
Johannes Berg4c476992010-10-04 21:36:35 +02008210 if (IS_ERR(net))
8211 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008212
8213 err = 0;
8214
8215 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008216 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8217 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008218
Johannes Berg463d0182009-07-14 00:33:35 +02008219 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008220 return err;
8221}
8222
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008223static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8224{
Johannes Berg4c476992010-10-04 21:36:35 +02008225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008226 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8227 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008228 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008229 struct cfg80211_pmksa pmksa;
8230
8231 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8232
8233 if (!info->attrs[NL80211_ATTR_MAC])
8234 return -EINVAL;
8235
8236 if (!info->attrs[NL80211_ATTR_PMKID])
8237 return -EINVAL;
8238
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008239 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8240 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8241
Johannes Berg074ac8d2010-09-16 14:58:22 +02008242 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008243 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8244 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008245
8246 switch (info->genlhdr->cmd) {
8247 case NL80211_CMD_SET_PMKSA:
8248 rdev_ops = rdev->ops->set_pmksa;
8249 break;
8250 case NL80211_CMD_DEL_PMKSA:
8251 rdev_ops = rdev->ops->del_pmksa;
8252 break;
8253 default:
8254 WARN_ON(1);
8255 break;
8256 }
8257
Johannes Berg4c476992010-10-04 21:36:35 +02008258 if (!rdev_ops)
8259 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008260
Johannes Berg4c476992010-10-04 21:36:35 +02008261 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008262}
8263
8264static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8265{
Johannes Berg4c476992010-10-04 21:36:35 +02008266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8267 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008268
Johannes Berg074ac8d2010-09-16 14:58:22 +02008269 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008270 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8271 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008272
Johannes Berg4c476992010-10-04 21:36:35 +02008273 if (!rdev->ops->flush_pmksa)
8274 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008275
Hila Gonene35e4d22012-06-27 17:19:42 +03008276 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008277}
8278
Arik Nemtsov109086c2011-09-28 14:12:50 +03008279static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8280{
8281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8282 struct net_device *dev = info->user_ptr[1];
8283 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308284 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008285 u16 status_code;
8286 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008287 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008288
8289 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8290 !rdev->ops->tdls_mgmt)
8291 return -EOPNOTSUPP;
8292
8293 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8294 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8295 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8296 !info->attrs[NL80211_ATTR_IE] ||
8297 !info->attrs[NL80211_ATTR_MAC])
8298 return -EINVAL;
8299
8300 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8301 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8302 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8303 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008304 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308305 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8306 peer_capability =
8307 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008308
Hila Gonene35e4d22012-06-27 17:19:42 +03008309 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308310 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008311 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008312 nla_data(info->attrs[NL80211_ATTR_IE]),
8313 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008314}
8315
8316static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8317{
8318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8319 struct net_device *dev = info->user_ptr[1];
8320 enum nl80211_tdls_operation operation;
8321 u8 *peer;
8322
8323 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8324 !rdev->ops->tdls_oper)
8325 return -EOPNOTSUPP;
8326
8327 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8328 !info->attrs[NL80211_ATTR_MAC])
8329 return -EINVAL;
8330
8331 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8332 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8333
Hila Gonene35e4d22012-06-27 17:19:42 +03008334 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008335}
8336
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008337static int nl80211_remain_on_channel(struct sk_buff *skb,
8338 struct genl_info *info)
8339{
Johannes Berg4c476992010-10-04 21:36:35 +02008340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008341 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008342 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008343 struct sk_buff *msg;
8344 void *hdr;
8345 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008346 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008347 int err;
8348
8349 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8350 !info->attrs[NL80211_ATTR_DURATION])
8351 return -EINVAL;
8352
8353 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8354
Johannes Berg7c4ef712011-11-18 15:33:48 +01008355 if (!rdev->ops->remain_on_channel ||
8356 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008357 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008358
Johannes Bergebf348f2012-06-01 12:50:54 +02008359 /*
8360 * We should be on that channel for at least a minimum amount of
8361 * time (10ms) but no longer than the driver supports.
8362 */
8363 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8364 duration > rdev->wiphy.max_remain_on_channel_duration)
8365 return -EINVAL;
8366
Johannes Berg683b6d32012-11-08 21:25:48 +01008367 err = nl80211_parse_chandef(rdev, info, &chandef);
8368 if (err)
8369 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008370
8371 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008372 if (!msg)
8373 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008374
Eric W. Biederman15e47302012-09-07 20:12:54 +00008375 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008376 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008377 if (!hdr) {
8378 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008379 goto free_msg;
8380 }
8381
Johannes Berg683b6d32012-11-08 21:25:48 +01008382 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8383 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008384
8385 if (err)
8386 goto free_msg;
8387
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008388 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8389 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008390 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008391
8392 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008393
8394 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008395
8396 nla_put_failure:
8397 err = -ENOBUFS;
8398 free_msg:
8399 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008400 return err;
8401}
8402
8403static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8404 struct genl_info *info)
8405{
Johannes Berg4c476992010-10-04 21:36:35 +02008406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008407 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008408 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008409
8410 if (!info->attrs[NL80211_ATTR_COOKIE])
8411 return -EINVAL;
8412
Johannes Berg4c476992010-10-04 21:36:35 +02008413 if (!rdev->ops->cancel_remain_on_channel)
8414 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008415
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008416 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8417
Hila Gonene35e4d22012-06-27 17:19:42 +03008418 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008419}
8420
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008421static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8422 u8 *rates, u8 rates_len)
8423{
8424 u8 i;
8425 u32 mask = 0;
8426
8427 for (i = 0; i < rates_len; i++) {
8428 int rate = (rates[i] & 0x7f) * 5;
8429 int ridx;
8430 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8431 struct ieee80211_rate *srate =
8432 &sband->bitrates[ridx];
8433 if (rate == srate->bitrate) {
8434 mask |= 1 << ridx;
8435 break;
8436 }
8437 }
8438 if (ridx == sband->n_bitrates)
8439 return 0; /* rate not found */
8440 }
8441
8442 return mask;
8443}
8444
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008445static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8446 u8 *rates, u8 rates_len,
8447 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8448{
8449 u8 i;
8450
8451 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8452
8453 for (i = 0; i < rates_len; i++) {
8454 int ridx, rbit;
8455
8456 ridx = rates[i] / 8;
8457 rbit = BIT(rates[i] % 8);
8458
8459 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008460 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008461 return false;
8462
8463 /* check availability */
8464 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8465 mcs[ridx] |= rbit;
8466 else
8467 return false;
8468 }
8469
8470 return true;
8471}
8472
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008473static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8474{
8475 u16 mcs_mask = 0;
8476
8477 switch (vht_mcs_map) {
8478 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8479 break;
8480 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8481 mcs_mask = 0x00FF;
8482 break;
8483 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8484 mcs_mask = 0x01FF;
8485 break;
8486 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8487 mcs_mask = 0x03FF;
8488 break;
8489 default:
8490 break;
8491 }
8492
8493 return mcs_mask;
8494}
8495
8496static void vht_build_mcs_mask(u16 vht_mcs_map,
8497 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8498{
8499 u8 nss;
8500
8501 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8502 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8503 vht_mcs_map >>= 2;
8504 }
8505}
8506
8507static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8508 struct nl80211_txrate_vht *txrate,
8509 u16 mcs[NL80211_VHT_NSS_MAX])
8510{
8511 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8512 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8513 u8 i;
8514
8515 if (!sband->vht_cap.vht_supported)
8516 return false;
8517
8518 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8519
8520 /* Build vht_mcs_mask from VHT capabilities */
8521 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8522
8523 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8524 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8525 mcs[i] = txrate->mcs[i];
8526 else
8527 return false;
8528 }
8529
8530 return true;
8531}
8532
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008533static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008534 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8535 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008536 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8537 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008538 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008539 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008540};
8541
8542static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8543 struct genl_info *info)
8544{
8545 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008547 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008548 int rem, i;
8549 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008550 struct nlattr *tx_rates;
8551 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008552 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008553
Johannes Berg4c476992010-10-04 21:36:35 +02008554 if (!rdev->ops->set_bitrate_mask)
8555 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008556
8557 memset(&mask, 0, sizeof(mask));
8558 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008559 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008560 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008561
8562 if (!sband)
8563 continue;
8564
8565 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008566 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008567 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008568 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008569
8570 if (!sband->vht_cap.vht_supported)
8571 continue;
8572
8573 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8574 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008575 }
8576
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008577 /* if no rates are given set it back to the defaults */
8578 if (!info->attrs[NL80211_ATTR_TX_RATES])
8579 goto out;
8580
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008581 /*
8582 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008583 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008584 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008585 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008586 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008587 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008588 int err;
8589
Johannes Berg57fbcce2016-04-12 15:56:15 +02008590 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008591 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008592 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008593 if (sband == NULL)
8594 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008595 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8596 nla_len(tx_rates), nl80211_txattr_policy);
8597 if (err)
8598 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008599 if (tb[NL80211_TXRATE_LEGACY]) {
8600 mask.control[band].legacy = rateset_to_mask(
8601 sband,
8602 nla_data(tb[NL80211_TXRATE_LEGACY]),
8603 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308604 if ((mask.control[band].legacy == 0) &&
8605 nla_len(tb[NL80211_TXRATE_LEGACY]))
8606 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008607 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008608 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008609 if (!ht_rateset_to_mask(
8610 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008611 nla_data(tb[NL80211_TXRATE_HT]),
8612 nla_len(tb[NL80211_TXRATE_HT]),
8613 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008614 return -EINVAL;
8615 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008616 if (tb[NL80211_TXRATE_VHT]) {
8617 if (!vht_set_mcs_mask(
8618 sband,
8619 nla_data(tb[NL80211_TXRATE_VHT]),
8620 mask.control[band].vht_mcs))
8621 return -EINVAL;
8622 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008623 if (tb[NL80211_TXRATE_GI]) {
8624 mask.control[band].gi =
8625 nla_get_u8(tb[NL80211_TXRATE_GI]);
8626 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8627 return -EINVAL;
8628 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008629
8630 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008631 /* don't allow empty legacy rates if HT or VHT
8632 * are not even supported.
8633 */
8634 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8635 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008636 return -EINVAL;
8637
8638 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008639 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008640 goto out;
8641
8642 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8643 if (mask.control[band].vht_mcs[i])
8644 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008645
8646 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008647 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008648 }
8649 }
8650
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008651out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008652 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008653}
8654
Johannes Berg2e161f72010-08-12 15:38:38 +02008655static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008656{
Johannes Berg4c476992010-10-04 21:36:35 +02008657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008658 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008659 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008660
8661 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8662 return -EINVAL;
8663
Johannes Berg2e161f72010-08-12 15:38:38 +02008664 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8665 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008666
Johannes Berg71bbc992012-06-15 15:30:18 +02008667 switch (wdev->iftype) {
8668 case NL80211_IFTYPE_STATION:
8669 case NL80211_IFTYPE_ADHOC:
8670 case NL80211_IFTYPE_P2P_CLIENT:
8671 case NL80211_IFTYPE_AP:
8672 case NL80211_IFTYPE_AP_VLAN:
8673 case NL80211_IFTYPE_MESH_POINT:
8674 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008675 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008676 break;
8677 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008678 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008679 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008680
8681 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008682 if (!rdev->ops->mgmt_tx)
8683 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008684
Eric W. Biederman15e47302012-09-07 20:12:54 +00008685 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008686 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8687 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008688}
8689
Johannes Berg2e161f72010-08-12 15:38:38 +02008690static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008691{
Johannes Berg4c476992010-10-04 21:36:35 +02008692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008693 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008694 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008695 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008696 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008697 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008698 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008699 struct cfg80211_mgmt_tx_params params = {
8700 .dont_wait_for_ack =
8701 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8702 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008703
Johannes Berg683b6d32012-11-08 21:25:48 +01008704 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008705 return -EINVAL;
8706
Johannes Berg4c476992010-10-04 21:36:35 +02008707 if (!rdev->ops->mgmt_tx)
8708 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008709
Johannes Berg71bbc992012-06-15 15:30:18 +02008710 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008711 case NL80211_IFTYPE_P2P_DEVICE:
8712 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8713 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008714 case NL80211_IFTYPE_STATION:
8715 case NL80211_IFTYPE_ADHOC:
8716 case NL80211_IFTYPE_P2P_CLIENT:
8717 case NL80211_IFTYPE_AP:
8718 case NL80211_IFTYPE_AP_VLAN:
8719 case NL80211_IFTYPE_MESH_POINT:
8720 case NL80211_IFTYPE_P2P_GO:
8721 break;
8722 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008723 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008724 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008725
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008726 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008727 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008728 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008729 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008730
8731 /*
8732 * We should wait on the channel for at least a minimum amount
8733 * of time (10ms) but no longer than the driver supports.
8734 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008735 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8736 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008737 return -EINVAL;
8738
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008739 }
8740
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008741 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008742
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008743 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008744 return -EINVAL;
8745
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008746 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308747
Antonio Quartulliea141b752013-06-11 14:20:03 +02008748 /* get the channel if any has been specified, otherwise pass NULL to
8749 * the driver. The latter will use the current one
8750 */
8751 chandef.chan = NULL;
8752 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8753 err = nl80211_parse_chandef(rdev, info, &chandef);
8754 if (err)
8755 return err;
8756 }
8757
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008758 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008759 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008760
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008761 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8762 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8763
8764 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8765 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8766 int i;
8767
8768 if (len % sizeof(u16))
8769 return -EINVAL;
8770
8771 params.n_csa_offsets = len / sizeof(u16);
8772 params.csa_offsets =
8773 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8774
8775 /* check that all the offsets fit the frame */
8776 for (i = 0; i < params.n_csa_offsets; i++) {
8777 if (params.csa_offsets[i] >= params.len)
8778 return -EINVAL;
8779 }
8780 }
8781
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008782 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008783 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8784 if (!msg)
8785 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008786
Eric W. Biederman15e47302012-09-07 20:12:54 +00008787 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008788 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008789 if (!hdr) {
8790 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008791 goto free_msg;
8792 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008793 }
Johannes Berge247bd902011-11-04 11:18:21 +01008794
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008795 params.chan = chandef.chan;
8796 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008797 if (err)
8798 goto free_msg;
8799
Johannes Berge247bd902011-11-04 11:18:21 +01008800 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008801 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8802 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008803 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008804
Johannes Berge247bd902011-11-04 11:18:21 +01008805 genlmsg_end(msg, hdr);
8806 return genlmsg_reply(msg, info);
8807 }
8808
8809 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008810
8811 nla_put_failure:
8812 err = -ENOBUFS;
8813 free_msg:
8814 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008815 return err;
8816}
8817
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008818static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8819{
8820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008821 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008822 u64 cookie;
8823
8824 if (!info->attrs[NL80211_ATTR_COOKIE])
8825 return -EINVAL;
8826
8827 if (!rdev->ops->mgmt_tx_cancel_wait)
8828 return -EOPNOTSUPP;
8829
Johannes Berg71bbc992012-06-15 15:30:18 +02008830 switch (wdev->iftype) {
8831 case NL80211_IFTYPE_STATION:
8832 case NL80211_IFTYPE_ADHOC:
8833 case NL80211_IFTYPE_P2P_CLIENT:
8834 case NL80211_IFTYPE_AP:
8835 case NL80211_IFTYPE_AP_VLAN:
8836 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008837 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008838 break;
8839 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008840 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008841 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008842
8843 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8844
Hila Gonene35e4d22012-06-27 17:19:42 +03008845 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008846}
8847
Kalle Valoffb9eb32010-02-17 17:58:10 +02008848static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8849{
Johannes Berg4c476992010-10-04 21:36:35 +02008850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008851 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008852 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008853 u8 ps_state;
8854 bool state;
8855 int err;
8856
Johannes Berg4c476992010-10-04 21:36:35 +02008857 if (!info->attrs[NL80211_ATTR_PS_STATE])
8858 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008859
8860 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8861
Johannes Berg4c476992010-10-04 21:36:35 +02008862 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8863 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008864
8865 wdev = dev->ieee80211_ptr;
8866
Johannes Berg4c476992010-10-04 21:36:35 +02008867 if (!rdev->ops->set_power_mgmt)
8868 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008869
8870 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8871
8872 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008873 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008874
Hila Gonene35e4d22012-06-27 17:19:42 +03008875 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008876 if (!err)
8877 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008878 return err;
8879}
8880
8881static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8882{
Johannes Berg4c476992010-10-04 21:36:35 +02008883 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008884 enum nl80211_ps_state ps_state;
8885 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008886 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008887 struct sk_buff *msg;
8888 void *hdr;
8889 int err;
8890
Kalle Valoffb9eb32010-02-17 17:58:10 +02008891 wdev = dev->ieee80211_ptr;
8892
Johannes Berg4c476992010-10-04 21:36:35 +02008893 if (!rdev->ops->set_power_mgmt)
8894 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008895
8896 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008897 if (!msg)
8898 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008899
Eric W. Biederman15e47302012-09-07 20:12:54 +00008900 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008901 NL80211_CMD_GET_POWER_SAVE);
8902 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008903 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008904 goto free_msg;
8905 }
8906
8907 if (wdev->ps)
8908 ps_state = NL80211_PS_ENABLED;
8909 else
8910 ps_state = NL80211_PS_DISABLED;
8911
David S. Miller9360ffd2012-03-29 04:41:26 -04008912 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8913 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008914
8915 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008916 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008917
Johannes Berg4c476992010-10-04 21:36:35 +02008918 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008919 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008920 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008921 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008922 return err;
8923}
8924
Johannes Berg94e860f2014-01-20 23:58:15 +01008925static const struct nla_policy
8926nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008927 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8928 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8929 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008930 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8931 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8932 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008933};
8934
Thomas Pedersen84f10702012-07-12 16:17:33 -07008935static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008936 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008937{
8938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008939 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008940 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008941
Johannes Bergd9d8b012012-11-26 12:51:52 +01008942 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008943 return -EINVAL;
8944
Thomas Pedersen84f10702012-07-12 16:17:33 -07008945 if (!rdev->ops->set_cqm_txe_config)
8946 return -EOPNOTSUPP;
8947
8948 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8949 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8950 return -EOPNOTSUPP;
8951
Hila Gonene35e4d22012-06-27 17:19:42 +03008952 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008953}
8954
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008955static int nl80211_set_cqm_rssi(struct genl_info *info,
8956 s32 threshold, u32 hysteresis)
8957{
Johannes Berg4c476992010-10-04 21:36:35 +02008958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008959 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008960 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008961
8962 if (threshold > 0)
8963 return -EINVAL;
8964
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008965 /* disabling - hysteresis should also be zero then */
8966 if (threshold == 0)
8967 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008968
Johannes Berg4c476992010-10-04 21:36:35 +02008969 if (!rdev->ops->set_cqm_rssi_config)
8970 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008971
Johannes Berg074ac8d2010-09-16 14:58:22 +02008972 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008973 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8974 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008975
Hila Gonene35e4d22012-06-27 17:19:42 +03008976 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008977}
8978
8979static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8980{
8981 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8982 struct nlattr *cqm;
8983 int err;
8984
8985 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008986 if (!cqm)
8987 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008988
8989 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8990 nl80211_attr_cqm_policy);
8991 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008992 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008993
8994 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8995 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008996 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8997 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008998
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008999 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9000 }
9001
9002 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9003 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9004 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9005 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9006 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9007 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9008
9009 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9010 }
9011
9012 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009013}
9014
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009015static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9016{
9017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9018 struct net_device *dev = info->user_ptr[1];
9019 struct ocb_setup setup = {};
9020 int err;
9021
9022 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9023 if (err)
9024 return err;
9025
9026 return cfg80211_join_ocb(rdev, dev, &setup);
9027}
9028
9029static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9030{
9031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9032 struct net_device *dev = info->user_ptr[1];
9033
9034 return cfg80211_leave_ocb(rdev, dev);
9035}
9036
Johannes Berg29cbe682010-12-03 09:20:44 +01009037static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9038{
9039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9040 struct net_device *dev = info->user_ptr[1];
9041 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009042 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009043 int err;
9044
9045 /* start with default */
9046 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009047 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009048
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009049 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009050 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009051 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009052 if (err)
9053 return err;
9054 }
9055
9056 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9057 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9058 return -EINVAL;
9059
Javier Cardonac80d5452010-12-16 17:37:49 -08009060 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9061 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9062
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009063 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9064 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9065 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9066 return -EINVAL;
9067
Marco Porsch9bdbf042013-01-07 16:04:51 +01009068 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9069 setup.beacon_interval =
9070 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9071 if (setup.beacon_interval < 10 ||
9072 setup.beacon_interval > 10000)
9073 return -EINVAL;
9074 }
9075
9076 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9077 setup.dtim_period =
9078 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9079 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9080 return -EINVAL;
9081 }
9082
Javier Cardonac80d5452010-12-16 17:37:49 -08009083 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9084 /* parse additional setup parameters if given */
9085 err = nl80211_parse_mesh_setup(info, &setup);
9086 if (err)
9087 return err;
9088 }
9089
Thomas Pedersend37bb182013-03-04 13:06:13 -08009090 if (setup.user_mpm)
9091 cfg.auto_open_plinks = false;
9092
Johannes Bergcc1d2802012-05-16 23:50:20 +02009093 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009094 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9095 if (err)
9096 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009097 } else {
9098 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009099 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009100 }
9101
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009102 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9103 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9104 int n_rates =
9105 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9106 struct ieee80211_supported_band *sband;
9107
9108 if (!setup.chandef.chan)
9109 return -EINVAL;
9110
9111 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9112
9113 err = ieee80211_get_ratemask(sband, rates, n_rates,
9114 &setup.basic_rates);
9115 if (err)
9116 return err;
9117 }
9118
Javier Cardonac80d5452010-12-16 17:37:49 -08009119 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009120}
9121
9122static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9123{
9124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9125 struct net_device *dev = info->user_ptr[1];
9126
9127 return cfg80211_leave_mesh(rdev, dev);
9128}
9129
Johannes Bergdfb89c52012-06-27 09:23:48 +02009130#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009131static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9132 struct cfg80211_registered_device *rdev)
9133{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009134 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009135 struct nlattr *nl_pats, *nl_pat;
9136 int i, pat_len;
9137
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009138 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009139 return 0;
9140
9141 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9142 if (!nl_pats)
9143 return -ENOBUFS;
9144
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009145 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009146 nl_pat = nla_nest_start(msg, i + 1);
9147 if (!nl_pat)
9148 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009149 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009150 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009151 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009152 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9153 wowlan->patterns[i].pattern) ||
9154 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009155 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009156 return -ENOBUFS;
9157 nla_nest_end(msg, nl_pat);
9158 }
9159 nla_nest_end(msg, nl_pats);
9160
9161 return 0;
9162}
9163
Johannes Berg2a0e0472013-01-23 22:57:40 +01009164static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9165 struct cfg80211_wowlan_tcp *tcp)
9166{
9167 struct nlattr *nl_tcp;
9168
9169 if (!tcp)
9170 return 0;
9171
9172 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9173 if (!nl_tcp)
9174 return -ENOBUFS;
9175
Jiri Benc930345e2015-03-29 16:59:25 +02009176 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9177 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009178 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9179 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9180 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9181 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9182 tcp->payload_len, tcp->payload) ||
9183 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9184 tcp->data_interval) ||
9185 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9186 tcp->wake_len, tcp->wake_data) ||
9187 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9188 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9189 return -ENOBUFS;
9190
9191 if (tcp->payload_seq.len &&
9192 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9193 sizeof(tcp->payload_seq), &tcp->payload_seq))
9194 return -ENOBUFS;
9195
9196 if (tcp->payload_tok.len &&
9197 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9198 sizeof(tcp->payload_tok) + tcp->tokens_size,
9199 &tcp->payload_tok))
9200 return -ENOBUFS;
9201
Johannes Berge248ad32013-05-16 10:24:28 +02009202 nla_nest_end(msg, nl_tcp);
9203
Johannes Berg2a0e0472013-01-23 22:57:40 +01009204 return 0;
9205}
9206
Luciano Coelho75453cc2015-01-09 14:06:37 +02009207static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9208 struct cfg80211_sched_scan_request *req)
9209{
Avraham Stern3b06d272015-10-12 09:51:34 +03009210 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009211 int i;
9212
9213 if (!req)
9214 return 0;
9215
9216 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9217 if (!nd)
9218 return -ENOBUFS;
9219
Avraham Stern3b06d272015-10-12 09:51:34 +03009220 if (req->n_scan_plans == 1 &&
9221 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9222 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009223 return -ENOBUFS;
9224
Luciano Coelho21fea562015-03-17 16:36:01 +02009225 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9226 return -ENOBUFS;
9227
Luciano Coelho75453cc2015-01-09 14:06:37 +02009228 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9229 if (!freqs)
9230 return -ENOBUFS;
9231
9232 for (i = 0; i < req->n_channels; i++)
9233 nla_put_u32(msg, i, req->channels[i]->center_freq);
9234
9235 nla_nest_end(msg, freqs);
9236
9237 if (req->n_match_sets) {
9238 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9239 for (i = 0; i < req->n_match_sets; i++) {
9240 match = nla_nest_start(msg, i);
9241 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9242 req->match_sets[i].ssid.ssid_len,
9243 req->match_sets[i].ssid.ssid);
9244 nla_nest_end(msg, match);
9245 }
9246 nla_nest_end(msg, matches);
9247 }
9248
Avraham Stern3b06d272015-10-12 09:51:34 +03009249 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9250 if (!scan_plans)
9251 return -ENOBUFS;
9252
9253 for (i = 0; i < req->n_scan_plans; i++) {
9254 scan_plan = nla_nest_start(msg, i + 1);
9255 if (!scan_plan ||
9256 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9257 req->scan_plans[i].interval) ||
9258 (req->scan_plans[i].iterations &&
9259 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9260 req->scan_plans[i].iterations)))
9261 return -ENOBUFS;
9262 nla_nest_end(msg, scan_plan);
9263 }
9264 nla_nest_end(msg, scan_plans);
9265
Luciano Coelho75453cc2015-01-09 14:06:37 +02009266 nla_nest_end(msg, nd);
9267
9268 return 0;
9269}
9270
Johannes Bergff1b6e62011-05-04 15:37:28 +02009271static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9272{
9273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9274 struct sk_buff *msg;
9275 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009276 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009277
Johannes Berg964dc9e2013-06-03 17:25:34 +02009278 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009279 return -EOPNOTSUPP;
9280
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009281 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009282 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009283 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9284 rdev->wiphy.wowlan_config->tcp->payload_len +
9285 rdev->wiphy.wowlan_config->tcp->wake_len +
9286 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009287 }
9288
9289 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009290 if (!msg)
9291 return -ENOMEM;
9292
Eric W. Biederman15e47302012-09-07 20:12:54 +00009293 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009294 NL80211_CMD_GET_WOWLAN);
9295 if (!hdr)
9296 goto nla_put_failure;
9297
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009298 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009299 struct nlattr *nl_wowlan;
9300
9301 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9302 if (!nl_wowlan)
9303 goto nla_put_failure;
9304
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009305 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009306 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009307 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009308 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009309 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009310 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009311 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009312 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009313 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009314 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009315 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009316 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009317 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009318 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9319 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009320
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009321 if (nl80211_send_wowlan_patterns(msg, rdev))
9322 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009323
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009324 if (nl80211_send_wowlan_tcp(msg,
9325 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009326 goto nla_put_failure;
9327
Luciano Coelho75453cc2015-01-09 14:06:37 +02009328 if (nl80211_send_wowlan_nd(
9329 msg,
9330 rdev->wiphy.wowlan_config->nd_config))
9331 goto nla_put_failure;
9332
Johannes Bergff1b6e62011-05-04 15:37:28 +02009333 nla_nest_end(msg, nl_wowlan);
9334 }
9335
9336 genlmsg_end(msg, hdr);
9337 return genlmsg_reply(msg, info);
9338
9339nla_put_failure:
9340 nlmsg_free(msg);
9341 return -ENOBUFS;
9342}
9343
Johannes Berg2a0e0472013-01-23 22:57:40 +01009344static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9345 struct nlattr *attr,
9346 struct cfg80211_wowlan *trig)
9347{
9348 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9349 struct cfg80211_wowlan_tcp *cfg;
9350 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9351 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9352 u32 size;
9353 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9354 int err, port;
9355
Johannes Berg964dc9e2013-06-03 17:25:34 +02009356 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009357 return -EINVAL;
9358
9359 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9360 nla_data(attr), nla_len(attr),
9361 nl80211_wowlan_tcp_policy);
9362 if (err)
9363 return err;
9364
9365 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9366 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9367 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9368 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9369 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9370 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9371 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9372 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9373 return -EINVAL;
9374
9375 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009376 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009377 return -EINVAL;
9378
9379 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009380 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009381 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009382 return -EINVAL;
9383
9384 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009385 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009386 return -EINVAL;
9387
9388 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9389 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9390 return -EINVAL;
9391
9392 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9393 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9394
9395 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9396 tokens_size = tokln - sizeof(*tok);
9397
9398 if (!tok->len || tokens_size % tok->len)
9399 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009400 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009401 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009402 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009403 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009404 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009405 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009406 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009407 return -EINVAL;
9408 if (tok->offset + tok->len > data_size)
9409 return -EINVAL;
9410 }
9411
9412 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9413 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009414 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009415 return -EINVAL;
9416 if (seq->len == 0 || seq->len > 4)
9417 return -EINVAL;
9418 if (seq->len + seq->offset > data_size)
9419 return -EINVAL;
9420 }
9421
9422 size = sizeof(*cfg);
9423 size += data_size;
9424 size += wake_size + wake_mask_size;
9425 size += tokens_size;
9426
9427 cfg = kzalloc(size, GFP_KERNEL);
9428 if (!cfg)
9429 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009430 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9431 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009432 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9433 ETH_ALEN);
9434 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9435 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9436 else
9437 port = 0;
9438#ifdef CONFIG_INET
9439 /* allocate a socket and port for it and use it */
9440 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9441 IPPROTO_TCP, &cfg->sock, 1);
9442 if (err) {
9443 kfree(cfg);
9444 return err;
9445 }
9446 if (inet_csk_get_port(cfg->sock->sk, port)) {
9447 sock_release(cfg->sock);
9448 kfree(cfg);
9449 return -EADDRINUSE;
9450 }
9451 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9452#else
9453 if (!port) {
9454 kfree(cfg);
9455 return -EINVAL;
9456 }
9457 cfg->src_port = port;
9458#endif
9459
9460 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9461 cfg->payload_len = data_size;
9462 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9463 memcpy((void *)cfg->payload,
9464 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9465 data_size);
9466 if (seq)
9467 cfg->payload_seq = *seq;
9468 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9469 cfg->wake_len = wake_size;
9470 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9471 memcpy((void *)cfg->wake_data,
9472 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9473 wake_size);
9474 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9475 data_size + wake_size;
9476 memcpy((void *)cfg->wake_mask,
9477 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9478 wake_mask_size);
9479 if (tok) {
9480 cfg->tokens_size = tokens_size;
9481 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9482 }
9483
9484 trig->tcp = cfg;
9485
9486 return 0;
9487}
9488
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009489static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9490 const struct wiphy_wowlan_support *wowlan,
9491 struct nlattr *attr,
9492 struct cfg80211_wowlan *trig)
9493{
9494 struct nlattr **tb;
9495 int err;
9496
9497 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9498 if (!tb)
9499 return -ENOMEM;
9500
9501 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9502 err = -EOPNOTSUPP;
9503 goto out;
9504 }
9505
9506 err = nla_parse(tb, NL80211_ATTR_MAX,
9507 nla_data(attr), nla_len(attr),
9508 nl80211_policy);
9509 if (err)
9510 goto out;
9511
Johannes Bergad2b26a2014-06-12 21:39:05 +02009512 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009513 err = PTR_ERR_OR_ZERO(trig->nd_config);
9514 if (err)
9515 trig->nd_config = NULL;
9516
9517out:
9518 kfree(tb);
9519 return err;
9520}
9521
Johannes Bergff1b6e62011-05-04 15:37:28 +02009522static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9523{
9524 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9525 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009526 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009527 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009528 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009529 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009530 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009531 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009532
Johannes Berg964dc9e2013-06-03 17:25:34 +02009533 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009534 return -EOPNOTSUPP;
9535
Johannes Bergae33bd82012-07-12 16:25:02 +02009536 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9537 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009538 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009539 goto set_wakeup;
9540 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009541
9542 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9543 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9544 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9545 nl80211_wowlan_policy);
9546 if (err)
9547 return err;
9548
9549 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9550 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9551 return -EINVAL;
9552 new_triggers.any = true;
9553 }
9554
9555 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9556 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9557 return -EINVAL;
9558 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009559 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009560 }
9561
9562 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9563 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9564 return -EINVAL;
9565 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009566 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009567 }
9568
Johannes Berg77dbbb12011-07-13 10:48:55 +02009569 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9570 return -EINVAL;
9571
9572 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9573 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9574 return -EINVAL;
9575 new_triggers.gtk_rekey_failure = 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_EAP_IDENT_REQUEST]) {
9580 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9581 return -EINVAL;
9582 new_triggers.eap_identity_req = 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_4WAY_HANDSHAKE]) {
9587 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9588 return -EINVAL;
9589 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009590 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009591 }
9592
9593 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9594 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9595 return -EINVAL;
9596 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009597 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009598 }
9599
Johannes Bergff1b6e62011-05-04 15:37:28 +02009600 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9601 struct nlattr *pat;
9602 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009603 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009604 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009605
Johannes Berg98fc4382015-03-01 09:10:13 +02009606 regular = true;
9607
Johannes Bergff1b6e62011-05-04 15:37:28 +02009608 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9609 rem)
9610 n_patterns++;
9611 if (n_patterns > wowlan->n_patterns)
9612 return -EINVAL;
9613
9614 new_triggers.patterns = kcalloc(n_patterns,
9615 sizeof(new_triggers.patterns[0]),
9616 GFP_KERNEL);
9617 if (!new_triggers.patterns)
9618 return -ENOMEM;
9619
9620 new_triggers.n_patterns = n_patterns;
9621 i = 0;
9622
9623 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9624 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009625 u8 *mask_pat;
9626
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009627 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9628 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009629 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009630 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9631 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009632 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009633 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009634 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009635 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009636 goto error;
9637 if (pat_len > wowlan->pattern_max_len ||
9638 pat_len < wowlan->pattern_min_len)
9639 goto error;
9640
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009641 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009642 pkt_offset = 0;
9643 else
9644 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009645 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009646 if (pkt_offset > wowlan->max_pkt_offset)
9647 goto error;
9648 new_triggers.patterns[i].pkt_offset = pkt_offset;
9649
Johannes Berg922bd802014-05-19 17:59:50 +02009650 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9651 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009652 err = -ENOMEM;
9653 goto error;
9654 }
Johannes Berg922bd802014-05-19 17:59:50 +02009655 new_triggers.patterns[i].mask = mask_pat;
9656 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009657 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009658 mask_pat += mask_len;
9659 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009660 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009661 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009662 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009663 pat_len);
9664 i++;
9665 }
9666 }
9667
Johannes Berg2a0e0472013-01-23 22:57:40 +01009668 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009669 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009670 err = nl80211_parse_wowlan_tcp(
9671 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9672 &new_triggers);
9673 if (err)
9674 goto error;
9675 }
9676
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009677 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009678 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009679 err = nl80211_parse_wowlan_nd(
9680 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9681 &new_triggers);
9682 if (err)
9683 goto error;
9684 }
9685
Johannes Berg98fc4382015-03-01 09:10:13 +02009686 /* The 'any' trigger means the device continues operating more or less
9687 * as in its normal operation mode and wakes up the host on most of the
9688 * normal interrupts (like packet RX, ...)
9689 * It therefore makes little sense to combine with the more constrained
9690 * wakeup trigger modes.
9691 */
9692 if (new_triggers.any && regular) {
9693 err = -EINVAL;
9694 goto error;
9695 }
9696
Johannes Bergae33bd82012-07-12 16:25:02 +02009697 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9698 if (!ntrig) {
9699 err = -ENOMEM;
9700 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009701 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009702 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009703 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009704
Johannes Bergae33bd82012-07-12 16:25:02 +02009705 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009706 if (rdev->ops->set_wakeup &&
9707 prev_enabled != !!rdev->wiphy.wowlan_config)
9708 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009709
Johannes Bergff1b6e62011-05-04 15:37:28 +02009710 return 0;
9711 error:
9712 for (i = 0; i < new_triggers.n_patterns; i++)
9713 kfree(new_triggers.patterns[i].mask);
9714 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009715 if (new_triggers.tcp && new_triggers.tcp->sock)
9716 sock_release(new_triggers.tcp->sock);
9717 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009718 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009719 return err;
9720}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009721#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009722
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009723static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9724 struct cfg80211_registered_device *rdev)
9725{
9726 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9727 int i, j, pat_len;
9728 struct cfg80211_coalesce_rules *rule;
9729
9730 if (!rdev->coalesce->n_rules)
9731 return 0;
9732
9733 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9734 if (!nl_rules)
9735 return -ENOBUFS;
9736
9737 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9738 nl_rule = nla_nest_start(msg, i + 1);
9739 if (!nl_rule)
9740 return -ENOBUFS;
9741
9742 rule = &rdev->coalesce->rules[i];
9743 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9744 rule->delay))
9745 return -ENOBUFS;
9746
9747 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9748 rule->condition))
9749 return -ENOBUFS;
9750
9751 nl_pats = nla_nest_start(msg,
9752 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9753 if (!nl_pats)
9754 return -ENOBUFS;
9755
9756 for (j = 0; j < rule->n_patterns; j++) {
9757 nl_pat = nla_nest_start(msg, j + 1);
9758 if (!nl_pat)
9759 return -ENOBUFS;
9760 pat_len = rule->patterns[j].pattern_len;
9761 if (nla_put(msg, NL80211_PKTPAT_MASK,
9762 DIV_ROUND_UP(pat_len, 8),
9763 rule->patterns[j].mask) ||
9764 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9765 rule->patterns[j].pattern) ||
9766 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9767 rule->patterns[j].pkt_offset))
9768 return -ENOBUFS;
9769 nla_nest_end(msg, nl_pat);
9770 }
9771 nla_nest_end(msg, nl_pats);
9772 nla_nest_end(msg, nl_rule);
9773 }
9774 nla_nest_end(msg, nl_rules);
9775
9776 return 0;
9777}
9778
9779static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9780{
9781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9782 struct sk_buff *msg;
9783 void *hdr;
9784
9785 if (!rdev->wiphy.coalesce)
9786 return -EOPNOTSUPP;
9787
9788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9789 if (!msg)
9790 return -ENOMEM;
9791
9792 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9793 NL80211_CMD_GET_COALESCE);
9794 if (!hdr)
9795 goto nla_put_failure;
9796
9797 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9798 goto nla_put_failure;
9799
9800 genlmsg_end(msg, hdr);
9801 return genlmsg_reply(msg, info);
9802
9803nla_put_failure:
9804 nlmsg_free(msg);
9805 return -ENOBUFS;
9806}
9807
9808void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9809{
9810 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9811 int i, j;
9812 struct cfg80211_coalesce_rules *rule;
9813
9814 if (!coalesce)
9815 return;
9816
9817 for (i = 0; i < coalesce->n_rules; i++) {
9818 rule = &coalesce->rules[i];
9819 for (j = 0; j < rule->n_patterns; j++)
9820 kfree(rule->patterns[j].mask);
9821 kfree(rule->patterns);
9822 }
9823 kfree(coalesce->rules);
9824 kfree(coalesce);
9825 rdev->coalesce = NULL;
9826}
9827
9828static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9829 struct nlattr *rule,
9830 struct cfg80211_coalesce_rules *new_rule)
9831{
9832 int err, i;
9833 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9834 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9835 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9836 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9837
9838 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9839 nla_len(rule), nl80211_coalesce_policy);
9840 if (err)
9841 return err;
9842
9843 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9844 new_rule->delay =
9845 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9846 if (new_rule->delay > coalesce->max_delay)
9847 return -EINVAL;
9848
9849 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9850 new_rule->condition =
9851 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9852 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9853 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9854 return -EINVAL;
9855
9856 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9857 return -EINVAL;
9858
9859 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9860 rem)
9861 n_patterns++;
9862 if (n_patterns > coalesce->n_patterns)
9863 return -EINVAL;
9864
9865 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9866 GFP_KERNEL);
9867 if (!new_rule->patterns)
9868 return -ENOMEM;
9869
9870 new_rule->n_patterns = n_patterns;
9871 i = 0;
9872
9873 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9874 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009875 u8 *mask_pat;
9876
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009877 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9878 nla_len(pat), NULL);
9879 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9880 !pat_tb[NL80211_PKTPAT_PATTERN])
9881 return -EINVAL;
9882 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9883 mask_len = DIV_ROUND_UP(pat_len, 8);
9884 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9885 return -EINVAL;
9886 if (pat_len > coalesce->pattern_max_len ||
9887 pat_len < coalesce->pattern_min_len)
9888 return -EINVAL;
9889
9890 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9891 pkt_offset = 0;
9892 else
9893 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9894 if (pkt_offset > coalesce->max_pkt_offset)
9895 return -EINVAL;
9896 new_rule->patterns[i].pkt_offset = pkt_offset;
9897
Johannes Berg922bd802014-05-19 17:59:50 +02009898 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9899 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009900 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009901
9902 new_rule->patterns[i].mask = mask_pat;
9903 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9904 mask_len);
9905
9906 mask_pat += mask_len;
9907 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009908 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009909 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9910 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009911 i++;
9912 }
9913
9914 return 0;
9915}
9916
9917static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9918{
9919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9920 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9921 struct cfg80211_coalesce new_coalesce = {};
9922 struct cfg80211_coalesce *n_coalesce;
9923 int err, rem_rule, n_rules = 0, i, j;
9924 struct nlattr *rule;
9925 struct cfg80211_coalesce_rules *tmp_rule;
9926
9927 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9928 return -EOPNOTSUPP;
9929
9930 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9931 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +03009932 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009933 return 0;
9934 }
9935
9936 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9937 rem_rule)
9938 n_rules++;
9939 if (n_rules > coalesce->n_rules)
9940 return -EINVAL;
9941
9942 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9943 GFP_KERNEL);
9944 if (!new_coalesce.rules)
9945 return -ENOMEM;
9946
9947 new_coalesce.n_rules = n_rules;
9948 i = 0;
9949
9950 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9951 rem_rule) {
9952 err = nl80211_parse_coalesce_rule(rdev, rule,
9953 &new_coalesce.rules[i]);
9954 if (err)
9955 goto error;
9956
9957 i++;
9958 }
9959
Ilan Peera1056b12015-10-22 22:27:46 +03009960 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009961 if (err)
9962 goto error;
9963
9964 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9965 if (!n_coalesce) {
9966 err = -ENOMEM;
9967 goto error;
9968 }
9969 cfg80211_rdev_free_coalesce(rdev);
9970 rdev->coalesce = n_coalesce;
9971
9972 return 0;
9973error:
9974 for (i = 0; i < new_coalesce.n_rules; i++) {
9975 tmp_rule = &new_coalesce.rules[i];
9976 for (j = 0; j < tmp_rule->n_patterns; j++)
9977 kfree(tmp_rule->patterns[j].mask);
9978 kfree(tmp_rule->patterns);
9979 }
9980 kfree(new_coalesce.rules);
9981
9982 return err;
9983}
9984
Johannes Berge5497d72011-07-05 16:35:40 +02009985static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9986{
9987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9988 struct net_device *dev = info->user_ptr[1];
9989 struct wireless_dev *wdev = dev->ieee80211_ptr;
9990 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9991 struct cfg80211_gtk_rekey_data rekey_data;
9992 int err;
9993
9994 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9995 return -EINVAL;
9996
9997 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9998 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9999 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10000 nl80211_rekey_policy);
10001 if (err)
10002 return err;
10003
10004 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10005 return -ERANGE;
10006 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10007 return -ERANGE;
10008 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10009 return -ERANGE;
10010
Johannes Berg78f686c2014-09-10 22:28:06 +030010011 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10012 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10013 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010014
10015 wdev_lock(wdev);
10016 if (!wdev->current_bss) {
10017 err = -ENOTCONN;
10018 goto out;
10019 }
10020
10021 if (!rdev->ops->set_rekey_data) {
10022 err = -EOPNOTSUPP;
10023 goto out;
10024 }
10025
Hila Gonene35e4d22012-06-27 17:19:42 +030010026 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010027 out:
10028 wdev_unlock(wdev);
10029 return err;
10030}
10031
Johannes Berg28946da2011-11-04 11:18:12 +010010032static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10033 struct genl_info *info)
10034{
10035 struct net_device *dev = info->user_ptr[1];
10036 struct wireless_dev *wdev = dev->ieee80211_ptr;
10037
10038 if (wdev->iftype != NL80211_IFTYPE_AP &&
10039 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10040 return -EINVAL;
10041
Eric W. Biederman15e47302012-09-07 20:12:54 +000010042 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010043 return -EBUSY;
10044
Eric W. Biederman15e47302012-09-07 20:12:54 +000010045 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010046 return 0;
10047}
10048
Johannes Berg7f6cf312011-11-04 11:18:15 +010010049static int nl80211_probe_client(struct sk_buff *skb,
10050 struct genl_info *info)
10051{
10052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10053 struct net_device *dev = info->user_ptr[1];
10054 struct wireless_dev *wdev = dev->ieee80211_ptr;
10055 struct sk_buff *msg;
10056 void *hdr;
10057 const u8 *addr;
10058 u64 cookie;
10059 int err;
10060
10061 if (wdev->iftype != NL80211_IFTYPE_AP &&
10062 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10063 return -EOPNOTSUPP;
10064
10065 if (!info->attrs[NL80211_ATTR_MAC])
10066 return -EINVAL;
10067
10068 if (!rdev->ops->probe_client)
10069 return -EOPNOTSUPP;
10070
10071 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10072 if (!msg)
10073 return -ENOMEM;
10074
Eric W. Biederman15e47302012-09-07 20:12:54 +000010075 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010076 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010077 if (!hdr) {
10078 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010079 goto free_msg;
10080 }
10081
10082 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10083
Hila Gonene35e4d22012-06-27 17:19:42 +030010084 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010085 if (err)
10086 goto free_msg;
10087
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010088 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10089 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010090 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010091
10092 genlmsg_end(msg, hdr);
10093
10094 return genlmsg_reply(msg, info);
10095
10096 nla_put_failure:
10097 err = -ENOBUFS;
10098 free_msg:
10099 nlmsg_free(msg);
10100 return err;
10101}
10102
Johannes Berg5e7602302011-11-04 11:18:17 +010010103static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10104{
10105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010106 struct cfg80211_beacon_registration *reg, *nreg;
10107 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010108
10109 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10110 return -EOPNOTSUPP;
10111
Ben Greear37c73b52012-10-26 14:49:25 -070010112 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10113 if (!nreg)
10114 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010115
Ben Greear37c73b52012-10-26 14:49:25 -070010116 /* First, check if already registered. */
10117 spin_lock_bh(&rdev->beacon_registrations_lock);
10118 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10119 if (reg->nlportid == info->snd_portid) {
10120 rv = -EALREADY;
10121 goto out_err;
10122 }
10123 }
10124 /* Add it to the list */
10125 nreg->nlportid = info->snd_portid;
10126 list_add(&nreg->list, &rdev->beacon_registrations);
10127
10128 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010129
10130 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010131out_err:
10132 spin_unlock_bh(&rdev->beacon_registrations_lock);
10133 kfree(nreg);
10134 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010135}
10136
Johannes Berg98104fde2012-06-16 00:19:54 +020010137static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10138{
10139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10140 struct wireless_dev *wdev = info->user_ptr[1];
10141 int err;
10142
10143 if (!rdev->ops->start_p2p_device)
10144 return -EOPNOTSUPP;
10145
10146 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10147 return -EOPNOTSUPP;
10148
10149 if (wdev->p2p_started)
10150 return 0;
10151
Luciano Coelhob6a55012014-02-27 11:07:21 +020010152 if (rfkill_blocked(rdev->rfkill))
10153 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010154
Johannes Bergeeb126e2012-10-23 15:16:50 +020010155 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010156 if (err)
10157 return err;
10158
10159 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010160 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010161
10162 return 0;
10163}
10164
10165static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10166{
10167 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10168 struct wireless_dev *wdev = info->user_ptr[1];
10169
10170 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10171 return -EOPNOTSUPP;
10172
10173 if (!rdev->ops->stop_p2p_device)
10174 return -EOPNOTSUPP;
10175
Johannes Bergf9f47522013-03-19 15:04:07 +010010176 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010177
10178 return 0;
10179}
10180
Johannes Berg3713b4e2013-02-14 16:19:38 +010010181static int nl80211_get_protocol_features(struct sk_buff *skb,
10182 struct genl_info *info)
10183{
10184 void *hdr;
10185 struct sk_buff *msg;
10186
10187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10188 if (!msg)
10189 return -ENOMEM;
10190
10191 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10192 NL80211_CMD_GET_PROTOCOL_FEATURES);
10193 if (!hdr)
10194 goto nla_put_failure;
10195
10196 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10197 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10198 goto nla_put_failure;
10199
10200 genlmsg_end(msg, hdr);
10201 return genlmsg_reply(msg, info);
10202
10203 nla_put_failure:
10204 kfree_skb(msg);
10205 return -ENOBUFS;
10206}
10207
Jouni Malinen355199e2013-02-27 17:14:27 +020010208static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10209{
10210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10211 struct cfg80211_update_ft_ies_params ft_params;
10212 struct net_device *dev = info->user_ptr[1];
10213
10214 if (!rdev->ops->update_ft_ies)
10215 return -EOPNOTSUPP;
10216
10217 if (!info->attrs[NL80211_ATTR_MDID] ||
10218 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10219 return -EINVAL;
10220
10221 memset(&ft_params, 0, sizeof(ft_params));
10222 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10223 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10224 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10225
10226 return rdev_update_ft_ies(rdev, dev, &ft_params);
10227}
10228
Arend van Spriel5de17982013-04-18 15:49:00 +020010229static int nl80211_crit_protocol_start(struct sk_buff *skb,
10230 struct genl_info *info)
10231{
10232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10233 struct wireless_dev *wdev = info->user_ptr[1];
10234 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10235 u16 duration;
10236 int ret;
10237
10238 if (!rdev->ops->crit_proto_start)
10239 return -EOPNOTSUPP;
10240
10241 if (WARN_ON(!rdev->ops->crit_proto_stop))
10242 return -EINVAL;
10243
10244 if (rdev->crit_proto_nlportid)
10245 return -EBUSY;
10246
10247 /* determine protocol if provided */
10248 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10249 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10250
10251 if (proto >= NUM_NL80211_CRIT_PROTO)
10252 return -EINVAL;
10253
10254 /* timeout must be provided */
10255 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10256 return -EINVAL;
10257
10258 duration =
10259 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10260
10261 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10262 return -ERANGE;
10263
10264 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10265 if (!ret)
10266 rdev->crit_proto_nlportid = info->snd_portid;
10267
10268 return ret;
10269}
10270
10271static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10272 struct genl_info *info)
10273{
10274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10275 struct wireless_dev *wdev = info->user_ptr[1];
10276
10277 if (!rdev->ops->crit_proto_stop)
10278 return -EOPNOTSUPP;
10279
10280 if (rdev->crit_proto_nlportid) {
10281 rdev->crit_proto_nlportid = 0;
10282 rdev_crit_proto_stop(rdev, wdev);
10283 }
10284 return 0;
10285}
10286
Johannes Bergad7e7182013-11-13 13:37:47 +010010287static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10288{
10289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10290 struct wireless_dev *wdev =
10291 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10292 int i, err;
10293 u32 vid, subcmd;
10294
10295 if (!rdev->wiphy.vendor_commands)
10296 return -EOPNOTSUPP;
10297
10298 if (IS_ERR(wdev)) {
10299 err = PTR_ERR(wdev);
10300 if (err != -EINVAL)
10301 return err;
10302 wdev = NULL;
10303 } else if (wdev->wiphy != &rdev->wiphy) {
10304 return -EINVAL;
10305 }
10306
10307 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10308 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10309 return -EINVAL;
10310
10311 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10312 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10313 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10314 const struct wiphy_vendor_command *vcmd;
10315 void *data = NULL;
10316 int len = 0;
10317
10318 vcmd = &rdev->wiphy.vendor_commands[i];
10319
10320 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10321 continue;
10322
10323 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10324 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10325 if (!wdev)
10326 return -EINVAL;
10327 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10328 !wdev->netdev)
10329 return -EINVAL;
10330
10331 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10332 if (wdev->netdev &&
10333 !netif_running(wdev->netdev))
10334 return -ENETDOWN;
10335 if (!wdev->netdev && !wdev->p2p_started)
10336 return -ENETDOWN;
10337 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010338
10339 if (!vcmd->doit)
10340 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010341 } else {
10342 wdev = NULL;
10343 }
10344
10345 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10346 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10347 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10348 }
10349
10350 rdev->cur_cmd_info = info;
10351 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10352 data, len);
10353 rdev->cur_cmd_info = NULL;
10354 return err;
10355 }
10356
10357 return -EOPNOTSUPP;
10358}
10359
Johannes Berg7bdbe402015-08-15 22:39:49 +030010360static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10361 struct netlink_callback *cb,
10362 struct cfg80211_registered_device **rdev,
10363 struct wireless_dev **wdev)
10364{
10365 u32 vid, subcmd;
10366 unsigned int i;
10367 int vcmd_idx = -1;
10368 int err;
10369 void *data = NULL;
10370 unsigned int data_len = 0;
10371
10372 rtnl_lock();
10373
10374 if (cb->args[0]) {
10375 /* subtract the 1 again here */
10376 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10377 struct wireless_dev *tmp;
10378
10379 if (!wiphy) {
10380 err = -ENODEV;
10381 goto out_unlock;
10382 }
10383 *rdev = wiphy_to_rdev(wiphy);
10384 *wdev = NULL;
10385
10386 if (cb->args[1]) {
10387 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10388 if (tmp->identifier == cb->args[1] - 1) {
10389 *wdev = tmp;
10390 break;
10391 }
10392 }
10393 }
10394
10395 /* keep rtnl locked in successful case */
10396 return 0;
10397 }
10398
10399 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10400 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10401 nl80211_policy);
10402 if (err)
10403 goto out_unlock;
10404
10405 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10406 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10407 err = -EINVAL;
10408 goto out_unlock;
10409 }
10410
10411 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10412 nl80211_fam.attrbuf);
10413 if (IS_ERR(*wdev))
10414 *wdev = NULL;
10415
10416 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10417 nl80211_fam.attrbuf);
10418 if (IS_ERR(*rdev)) {
10419 err = PTR_ERR(*rdev);
10420 goto out_unlock;
10421 }
10422
10423 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10424 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10425
10426 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10427 const struct wiphy_vendor_command *vcmd;
10428
10429 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10430
10431 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10432 continue;
10433
10434 if (!vcmd->dumpit) {
10435 err = -EOPNOTSUPP;
10436 goto out_unlock;
10437 }
10438
10439 vcmd_idx = i;
10440 break;
10441 }
10442
10443 if (vcmd_idx < 0) {
10444 err = -EOPNOTSUPP;
10445 goto out_unlock;
10446 }
10447
10448 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10449 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10450 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10451 }
10452
10453 /* 0 is the first index - add 1 to parse only once */
10454 cb->args[0] = (*rdev)->wiphy_idx + 1;
10455 /* add 1 to know if it was NULL */
10456 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10457 cb->args[2] = vcmd_idx;
10458 cb->args[3] = (unsigned long)data;
10459 cb->args[4] = data_len;
10460
10461 /* keep rtnl locked in successful case */
10462 return 0;
10463 out_unlock:
10464 rtnl_unlock();
10465 return err;
10466}
10467
10468static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10469 struct netlink_callback *cb)
10470{
10471 struct cfg80211_registered_device *rdev;
10472 struct wireless_dev *wdev;
10473 unsigned int vcmd_idx;
10474 const struct wiphy_vendor_command *vcmd;
10475 void *data;
10476 int data_len;
10477 int err;
10478 struct nlattr *vendor_data;
10479
10480 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10481 if (err)
10482 return err;
10483
10484 vcmd_idx = cb->args[2];
10485 data = (void *)cb->args[3];
10486 data_len = cb->args[4];
10487 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10488
10489 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10490 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10491 if (!wdev)
10492 return -EINVAL;
10493 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10494 !wdev->netdev)
10495 return -EINVAL;
10496
10497 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10498 if (wdev->netdev &&
10499 !netif_running(wdev->netdev))
10500 return -ENETDOWN;
10501 if (!wdev->netdev && !wdev->p2p_started)
10502 return -ENETDOWN;
10503 }
10504 }
10505
10506 while (1) {
10507 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10508 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10509 NL80211_CMD_VENDOR);
10510 if (!hdr)
10511 break;
10512
10513 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010514 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10515 wdev_id(wdev),
10516 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010517 genlmsg_cancel(skb, hdr);
10518 break;
10519 }
10520
10521 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10522 if (!vendor_data) {
10523 genlmsg_cancel(skb, hdr);
10524 break;
10525 }
10526
10527 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10528 (unsigned long *)&cb->args[5]);
10529 nla_nest_end(skb, vendor_data);
10530
10531 if (err == -ENOBUFS || err == -ENOENT) {
10532 genlmsg_cancel(skb, hdr);
10533 break;
10534 } else if (err) {
10535 genlmsg_cancel(skb, hdr);
10536 goto out;
10537 }
10538
10539 genlmsg_end(skb, hdr);
10540 }
10541
10542 err = skb->len;
10543 out:
10544 rtnl_unlock();
10545 return err;
10546}
10547
Johannes Bergad7e7182013-11-13 13:37:47 +010010548struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10549 enum nl80211_commands cmd,
10550 enum nl80211_attrs attr,
10551 int approxlen)
10552{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010553 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010554
10555 if (WARN_ON(!rdev->cur_cmd_info))
10556 return NULL;
10557
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010558 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010559 rdev->cur_cmd_info->snd_portid,
10560 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010561 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010562}
10563EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10564
10565int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10566{
10567 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10568 void *hdr = ((void **)skb->cb)[1];
10569 struct nlattr *data = ((void **)skb->cb)[2];
10570
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010571 /* clear CB data for netlink core to own from now on */
10572 memset(skb->cb, 0, sizeof(skb->cb));
10573
Johannes Bergad7e7182013-11-13 13:37:47 +010010574 if (WARN_ON(!rdev->cur_cmd_info)) {
10575 kfree_skb(skb);
10576 return -EINVAL;
10577 }
10578
10579 nla_nest_end(skb, data);
10580 genlmsg_end(skb, hdr);
10581 return genlmsg_reply(skb, rdev->cur_cmd_info);
10582}
10583EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10584
10585
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010586static int nl80211_set_qos_map(struct sk_buff *skb,
10587 struct genl_info *info)
10588{
10589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10590 struct cfg80211_qos_map *qos_map = NULL;
10591 struct net_device *dev = info->user_ptr[1];
10592 u8 *pos, len, num_des, des_len, des;
10593 int ret;
10594
10595 if (!rdev->ops->set_qos_map)
10596 return -EOPNOTSUPP;
10597
10598 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10599 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10600 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10601
10602 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10603 len > IEEE80211_QOS_MAP_LEN_MAX)
10604 return -EINVAL;
10605
10606 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10607 if (!qos_map)
10608 return -ENOMEM;
10609
10610 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10611 if (num_des) {
10612 des_len = num_des *
10613 sizeof(struct cfg80211_dscp_exception);
10614 memcpy(qos_map->dscp_exception, pos, des_len);
10615 qos_map->num_des = num_des;
10616 for (des = 0; des < num_des; des++) {
10617 if (qos_map->dscp_exception[des].up > 7) {
10618 kfree(qos_map);
10619 return -EINVAL;
10620 }
10621 }
10622 pos += des_len;
10623 }
10624 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10625 }
10626
10627 wdev_lock(dev->ieee80211_ptr);
10628 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10629 if (!ret)
10630 ret = rdev_set_qos_map(rdev, dev, qos_map);
10631 wdev_unlock(dev->ieee80211_ptr);
10632
10633 kfree(qos_map);
10634 return ret;
10635}
10636
Johannes Berg960d01a2014-09-09 22:55:35 +030010637static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10638{
10639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10640 struct net_device *dev = info->user_ptr[1];
10641 struct wireless_dev *wdev = dev->ieee80211_ptr;
10642 const u8 *peer;
10643 u8 tsid, up;
10644 u16 admitted_time = 0;
10645 int err;
10646
Johannes Berg723e73a2014-10-22 09:25:06 +020010647 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010648 return -EOPNOTSUPP;
10649
10650 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10651 !info->attrs[NL80211_ATTR_USER_PRIO])
10652 return -EINVAL;
10653
10654 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10655 if (tsid >= IEEE80211_NUM_TIDS)
10656 return -EINVAL;
10657
10658 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10659 if (up >= IEEE80211_NUM_UPS)
10660 return -EINVAL;
10661
10662 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010663 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010664 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010665 * need more attributes for that (e.g. BA session requirement);
10666 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010667 */
10668 return -EINVAL;
10669 }
10670
10671 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10672
10673 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10674 admitted_time =
10675 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10676 if (!admitted_time)
10677 return -EINVAL;
10678 }
10679
10680 wdev_lock(wdev);
10681 switch (wdev->iftype) {
10682 case NL80211_IFTYPE_STATION:
10683 case NL80211_IFTYPE_P2P_CLIENT:
10684 if (wdev->current_bss)
10685 break;
10686 err = -ENOTCONN;
10687 goto out;
10688 default:
10689 err = -EOPNOTSUPP;
10690 goto out;
10691 }
10692
10693 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10694
10695 out:
10696 wdev_unlock(wdev);
10697 return err;
10698}
10699
10700static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10701{
10702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10703 struct net_device *dev = info->user_ptr[1];
10704 struct wireless_dev *wdev = dev->ieee80211_ptr;
10705 const u8 *peer;
10706 u8 tsid;
10707 int err;
10708
10709 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10710 return -EINVAL;
10711
10712 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10713 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10714
10715 wdev_lock(wdev);
10716 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10717 wdev_unlock(wdev);
10718
10719 return err;
10720}
10721
Arik Nemtsov1057d352014-11-19 12:54:26 +020010722static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10723 struct genl_info *info)
10724{
10725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10726 struct net_device *dev = info->user_ptr[1];
10727 struct wireless_dev *wdev = dev->ieee80211_ptr;
10728 struct cfg80211_chan_def chandef = {};
10729 const u8 *addr;
10730 u8 oper_class;
10731 int err;
10732
10733 if (!rdev->ops->tdls_channel_switch ||
10734 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10735 return -EOPNOTSUPP;
10736
10737 switch (dev->ieee80211_ptr->iftype) {
10738 case NL80211_IFTYPE_STATION:
10739 case NL80211_IFTYPE_P2P_CLIENT:
10740 break;
10741 default:
10742 return -EOPNOTSUPP;
10743 }
10744
10745 if (!info->attrs[NL80211_ATTR_MAC] ||
10746 !info->attrs[NL80211_ATTR_OPER_CLASS])
10747 return -EINVAL;
10748
10749 err = nl80211_parse_chandef(rdev, info, &chandef);
10750 if (err)
10751 return err;
10752
10753 /*
10754 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10755 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10756 * specification is not defined for them.
10757 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010758 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010759 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10760 chandef.width != NL80211_CHAN_WIDTH_20)
10761 return -EINVAL;
10762
10763 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010764 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10765 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010766 return -EINVAL;
10767
10768 /* don't allow switching to DFS channels */
10769 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10770 return -EINVAL;
10771
10772 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10773 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10774
10775 wdev_lock(wdev);
10776 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10777 wdev_unlock(wdev);
10778
10779 return err;
10780}
10781
10782static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10783 struct genl_info *info)
10784{
10785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10786 struct net_device *dev = info->user_ptr[1];
10787 struct wireless_dev *wdev = dev->ieee80211_ptr;
10788 const u8 *addr;
10789
10790 if (!rdev->ops->tdls_channel_switch ||
10791 !rdev->ops->tdls_cancel_channel_switch ||
10792 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10793 return -EOPNOTSUPP;
10794
10795 switch (dev->ieee80211_ptr->iftype) {
10796 case NL80211_IFTYPE_STATION:
10797 case NL80211_IFTYPE_P2P_CLIENT:
10798 break;
10799 default:
10800 return -EOPNOTSUPP;
10801 }
10802
10803 if (!info->attrs[NL80211_ATTR_MAC])
10804 return -EINVAL;
10805
10806 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10807
10808 wdev_lock(wdev);
10809 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10810 wdev_unlock(wdev);
10811
10812 return 0;
10813}
10814
Johannes Berg4c476992010-10-04 21:36:35 +020010815#define NL80211_FLAG_NEED_WIPHY 0x01
10816#define NL80211_FLAG_NEED_NETDEV 0x02
10817#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010818#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10819#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10820 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010821#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010822/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010823#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10824 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010825#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010826
Johannes Bergf84f7712013-11-14 17:14:45 +010010827static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010828 struct genl_info *info)
10829{
10830 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010831 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010832 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010833 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10834
10835 if (rtnl)
10836 rtnl_lock();
10837
10838 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010839 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010840 if (IS_ERR(rdev)) {
10841 if (rtnl)
10842 rtnl_unlock();
10843 return PTR_ERR(rdev);
10844 }
10845 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010846 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10847 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010848 ASSERT_RTNL();
10849
Johannes Berg89a54e42012-06-15 14:33:17 +020010850 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10851 info->attrs);
10852 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010853 if (rtnl)
10854 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010855 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010856 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010857
Johannes Berg89a54e42012-06-15 14:33:17 +020010858 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010859 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010860
Johannes Berg1bf614e2012-06-15 15:23:36 +020010861 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10862 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010863 if (rtnl)
10864 rtnl_unlock();
10865 return -EINVAL;
10866 }
10867
10868 info->user_ptr[1] = dev;
10869 } else {
10870 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010871 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010872
Johannes Berg1bf614e2012-06-15 15:23:36 +020010873 if (dev) {
10874 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10875 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010876 if (rtnl)
10877 rtnl_unlock();
10878 return -ENETDOWN;
10879 }
10880
10881 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010882 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10883 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010884 if (rtnl)
10885 rtnl_unlock();
10886 return -ENETDOWN;
10887 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010888 }
10889
Johannes Berg4c476992010-10-04 21:36:35 +020010890 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010891 }
10892
10893 return 0;
10894}
10895
Johannes Bergf84f7712013-11-14 17:14:45 +010010896static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010897 struct genl_info *info)
10898{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010899 if (info->user_ptr[1]) {
10900 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10901 struct wireless_dev *wdev = info->user_ptr[1];
10902
10903 if (wdev->netdev)
10904 dev_put(wdev->netdev);
10905 } else {
10906 dev_put(info->user_ptr[1]);
10907 }
10908 }
Johannes Berg5393b912014-09-10 15:00:16 +030010909
Johannes Berg4c476992010-10-04 21:36:35 +020010910 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10911 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010912
10913 /* If needed, clear the netlink message payload from the SKB
10914 * as it might contain key data that shouldn't stick around on
10915 * the heap after the SKB is freed. The netlink message header
10916 * is still needed for further processing, so leave it intact.
10917 */
10918 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10919 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10920
10921 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10922 }
Johannes Berg4c476992010-10-04 21:36:35 +020010923}
10924
Johannes Berg4534de82013-11-14 17:14:46 +010010925static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010926 {
10927 .cmd = NL80211_CMD_GET_WIPHY,
10928 .doit = nl80211_get_wiphy,
10929 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010930 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010931 .policy = nl80211_policy,
10932 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010933 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10934 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010935 },
10936 {
10937 .cmd = NL80211_CMD_SET_WIPHY,
10938 .doit = nl80211_set_wiphy,
10939 .policy = nl80211_policy,
10940 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010941 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010942 },
10943 {
10944 .cmd = NL80211_CMD_GET_INTERFACE,
10945 .doit = nl80211_get_interface,
10946 .dumpit = nl80211_dump_interface,
10947 .policy = nl80211_policy,
10948 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010949 .internal_flags = NL80211_FLAG_NEED_WDEV |
10950 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010951 },
10952 {
10953 .cmd = NL80211_CMD_SET_INTERFACE,
10954 .doit = nl80211_set_interface,
10955 .policy = nl80211_policy,
10956 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010957 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10958 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010959 },
10960 {
10961 .cmd = NL80211_CMD_NEW_INTERFACE,
10962 .doit = nl80211_new_interface,
10963 .policy = nl80211_policy,
10964 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010965 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10966 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010967 },
10968 {
10969 .cmd = NL80211_CMD_DEL_INTERFACE,
10970 .doit = nl80211_del_interface,
10971 .policy = nl80211_policy,
10972 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010973 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010974 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010975 },
Johannes Berg41ade002007-12-19 02:03:29 +010010976 {
10977 .cmd = NL80211_CMD_GET_KEY,
10978 .doit = nl80211_get_key,
10979 .policy = nl80211_policy,
10980 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010981 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010982 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010983 },
10984 {
10985 .cmd = NL80211_CMD_SET_KEY,
10986 .doit = nl80211_set_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_NEW_KEY,
10995 .doit = nl80211_new_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 Berg5393b912014-09-10 15:00:16 +030010999 NL80211_FLAG_NEED_RTNL |
11000 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011001 },
11002 {
11003 .cmd = NL80211_CMD_DEL_KEY,
11004 .doit = nl80211_del_key,
11005 .policy = nl80211_policy,
11006 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011008 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011009 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011010 {
11011 .cmd = NL80211_CMD_SET_BEACON,
11012 .policy = nl80211_policy,
11013 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011014 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011016 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011017 },
11018 {
Johannes Berg88600202012-02-13 15:17:18 +010011019 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011020 .policy = nl80211_policy,
11021 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011022 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011024 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011025 },
11026 {
Johannes Berg88600202012-02-13 15:17:18 +010011027 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011028 .policy = nl80211_policy,
11029 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011030 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011032 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011033 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011034 {
11035 .cmd = NL80211_CMD_GET_STATION,
11036 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011037 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011038 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011039 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11040 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011041 },
11042 {
11043 .cmd = NL80211_CMD_SET_STATION,
11044 .doit = nl80211_set_station,
11045 .policy = nl80211_policy,
11046 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011048 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011049 },
11050 {
11051 .cmd = NL80211_CMD_NEW_STATION,
11052 .doit = nl80211_new_station,
11053 .policy = nl80211_policy,
11054 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011056 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011057 },
11058 {
11059 .cmd = NL80211_CMD_DEL_STATION,
11060 .doit = nl80211_del_station,
11061 .policy = nl80211_policy,
11062 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011064 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011065 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011066 {
11067 .cmd = NL80211_CMD_GET_MPATH,
11068 .doit = nl80211_get_mpath,
11069 .dumpit = nl80211_dump_mpath,
11070 .policy = nl80211_policy,
11071 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011073 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011074 },
11075 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011076 .cmd = NL80211_CMD_GET_MPP,
11077 .doit = nl80211_get_mpp,
11078 .dumpit = nl80211_dump_mpp,
11079 .policy = nl80211_policy,
11080 .flags = GENL_ADMIN_PERM,
11081 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11082 NL80211_FLAG_NEED_RTNL,
11083 },
11084 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011085 .cmd = NL80211_CMD_SET_MPATH,
11086 .doit = nl80211_set_mpath,
11087 .policy = nl80211_policy,
11088 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011089 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011090 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011091 },
11092 {
11093 .cmd = NL80211_CMD_NEW_MPATH,
11094 .doit = nl80211_new_mpath,
11095 .policy = nl80211_policy,
11096 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011097 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011098 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011099 },
11100 {
11101 .cmd = NL80211_CMD_DEL_MPATH,
11102 .doit = nl80211_del_mpath,
11103 .policy = nl80211_policy,
11104 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011105 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011106 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011107 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011108 {
11109 .cmd = NL80211_CMD_SET_BSS,
11110 .doit = nl80211_set_bss,
11111 .policy = nl80211_policy,
11112 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011113 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011114 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011115 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011116 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011117 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011118 .doit = nl80211_get_reg_do,
11119 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011120 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011121 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011122 /* can be retrieved by unprivileged users */
11123 },
Johannes Bergb6863032015-10-15 09:25:18 +020011124#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011125 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011126 .cmd = NL80211_CMD_SET_REG,
11127 .doit = nl80211_set_reg,
11128 .policy = nl80211_policy,
11129 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011130 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011131 },
Johannes Bergb6863032015-10-15 09:25:18 +020011132#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011133 {
11134 .cmd = NL80211_CMD_REQ_SET_REG,
11135 .doit = nl80211_req_set_reg,
11136 .policy = nl80211_policy,
11137 .flags = GENL_ADMIN_PERM,
11138 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011139 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011140 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11141 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011142 .policy = nl80211_policy,
11143 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011144 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011145 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011146 },
11147 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011148 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11149 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011150 .policy = nl80211_policy,
11151 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011153 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011154 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011155 {
Johannes Berg2a519312009-02-10 21:25:55 +010011156 .cmd = NL80211_CMD_TRIGGER_SCAN,
11157 .doit = nl80211_trigger_scan,
11158 .policy = nl80211_policy,
11159 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011160 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011161 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011162 },
11163 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011164 .cmd = NL80211_CMD_ABORT_SCAN,
11165 .doit = nl80211_abort_scan,
11166 .policy = nl80211_policy,
11167 .flags = GENL_ADMIN_PERM,
11168 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11169 NL80211_FLAG_NEED_RTNL,
11170 },
11171 {
Johannes Berg2a519312009-02-10 21:25:55 +010011172 .cmd = NL80211_CMD_GET_SCAN,
11173 .policy = nl80211_policy,
11174 .dumpit = nl80211_dump_scan,
11175 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011176 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011177 .cmd = NL80211_CMD_START_SCHED_SCAN,
11178 .doit = nl80211_start_sched_scan,
11179 .policy = nl80211_policy,
11180 .flags = GENL_ADMIN_PERM,
11181 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11182 NL80211_FLAG_NEED_RTNL,
11183 },
11184 {
11185 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11186 .doit = nl80211_stop_sched_scan,
11187 .policy = nl80211_policy,
11188 .flags = GENL_ADMIN_PERM,
11189 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11190 NL80211_FLAG_NEED_RTNL,
11191 },
11192 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011193 .cmd = NL80211_CMD_AUTHENTICATE,
11194 .doit = nl80211_authenticate,
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 Berg5393b912014-09-10 15:00:16 +030011198 NL80211_FLAG_NEED_RTNL |
11199 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011200 },
11201 {
11202 .cmd = NL80211_CMD_ASSOCIATE,
11203 .doit = nl80211_associate,
11204 .policy = nl80211_policy,
11205 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011206 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011207 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011208 },
11209 {
11210 .cmd = NL80211_CMD_DEAUTHENTICATE,
11211 .doit = nl80211_deauthenticate,
11212 .policy = nl80211_policy,
11213 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011214 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011215 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011216 },
11217 {
11218 .cmd = NL80211_CMD_DISASSOCIATE,
11219 .doit = nl80211_disassociate,
11220 .policy = nl80211_policy,
11221 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011222 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011223 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011224 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011225 {
11226 .cmd = NL80211_CMD_JOIN_IBSS,
11227 .doit = nl80211_join_ibss,
11228 .policy = nl80211_policy,
11229 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011231 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011232 },
11233 {
11234 .cmd = NL80211_CMD_LEAVE_IBSS,
11235 .doit = nl80211_leave_ibss,
11236 .policy = nl80211_policy,
11237 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011239 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011240 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011241#ifdef CONFIG_NL80211_TESTMODE
11242 {
11243 .cmd = NL80211_CMD_TESTMODE,
11244 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011245 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011246 .policy = nl80211_policy,
11247 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011248 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11249 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011250 },
11251#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011252 {
11253 .cmd = NL80211_CMD_CONNECT,
11254 .doit = nl80211_connect,
11255 .policy = nl80211_policy,
11256 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011258 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011259 },
11260 {
11261 .cmd = NL80211_CMD_DISCONNECT,
11262 .doit = nl80211_disconnect,
11263 .policy = nl80211_policy,
11264 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011265 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011266 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011267 },
Johannes Berg463d0182009-07-14 00:33:35 +020011268 {
11269 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11270 .doit = nl80211_wiphy_netns,
11271 .policy = nl80211_policy,
11272 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011273 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11274 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011275 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011276 {
11277 .cmd = NL80211_CMD_GET_SURVEY,
11278 .policy = nl80211_policy,
11279 .dumpit = nl80211_dump_survey,
11280 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011281 {
11282 .cmd = NL80211_CMD_SET_PMKSA,
11283 .doit = nl80211_setdel_pmksa,
11284 .policy = nl80211_policy,
11285 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011286 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011287 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011288 },
11289 {
11290 .cmd = NL80211_CMD_DEL_PMKSA,
11291 .doit = nl80211_setdel_pmksa,
11292 .policy = nl80211_policy,
11293 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011294 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011295 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011296 },
11297 {
11298 .cmd = NL80211_CMD_FLUSH_PMKSA,
11299 .doit = nl80211_flush_pmksa,
11300 .policy = nl80211_policy,
11301 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011302 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011303 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011304 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011305 {
11306 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11307 .doit = nl80211_remain_on_channel,
11308 .policy = nl80211_policy,
11309 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011310 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011311 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011312 },
11313 {
11314 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11315 .doit = nl80211_cancel_remain_on_channel,
11316 .policy = nl80211_policy,
11317 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011318 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011319 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011320 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011321 {
11322 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11323 .doit = nl80211_set_tx_bitrate_mask,
11324 .policy = nl80211_policy,
11325 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011326 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11327 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011328 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011329 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011330 .cmd = NL80211_CMD_REGISTER_FRAME,
11331 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011332 .policy = nl80211_policy,
11333 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011334 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011335 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011336 },
11337 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011338 .cmd = NL80211_CMD_FRAME,
11339 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011340 .policy = nl80211_policy,
11341 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011342 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011343 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011344 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011345 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011346 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11347 .doit = nl80211_tx_mgmt_cancel_wait,
11348 .policy = nl80211_policy,
11349 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011350 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011351 NL80211_FLAG_NEED_RTNL,
11352 },
11353 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011354 .cmd = NL80211_CMD_SET_POWER_SAVE,
11355 .doit = nl80211_set_power_save,
11356 .policy = nl80211_policy,
11357 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011358 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11359 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011360 },
11361 {
11362 .cmd = NL80211_CMD_GET_POWER_SAVE,
11363 .doit = nl80211_get_power_save,
11364 .policy = nl80211_policy,
11365 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011366 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11367 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011368 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011369 {
11370 .cmd = NL80211_CMD_SET_CQM,
11371 .doit = nl80211_set_cqm,
11372 .policy = nl80211_policy,
11373 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011374 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11375 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011376 },
Johannes Bergf444de02010-05-05 15:25:02 +020011377 {
11378 .cmd = NL80211_CMD_SET_CHANNEL,
11379 .doit = nl80211_set_channel,
11380 .policy = nl80211_policy,
11381 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011382 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11383 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011384 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011385 {
11386 .cmd = NL80211_CMD_SET_WDS_PEER,
11387 .doit = nl80211_set_wds_peer,
11388 .policy = nl80211_policy,
11389 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011390 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11391 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011392 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011393 {
11394 .cmd = NL80211_CMD_JOIN_MESH,
11395 .doit = nl80211_join_mesh,
11396 .policy = nl80211_policy,
11397 .flags = GENL_ADMIN_PERM,
11398 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11399 NL80211_FLAG_NEED_RTNL,
11400 },
11401 {
11402 .cmd = NL80211_CMD_LEAVE_MESH,
11403 .doit = nl80211_leave_mesh,
11404 .policy = nl80211_policy,
11405 .flags = GENL_ADMIN_PERM,
11406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11407 NL80211_FLAG_NEED_RTNL,
11408 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011409 {
11410 .cmd = NL80211_CMD_JOIN_OCB,
11411 .doit = nl80211_join_ocb,
11412 .policy = nl80211_policy,
11413 .flags = GENL_ADMIN_PERM,
11414 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11415 NL80211_FLAG_NEED_RTNL,
11416 },
11417 {
11418 .cmd = NL80211_CMD_LEAVE_OCB,
11419 .doit = nl80211_leave_ocb,
11420 .policy = nl80211_policy,
11421 .flags = GENL_ADMIN_PERM,
11422 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11423 NL80211_FLAG_NEED_RTNL,
11424 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011425#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011426 {
11427 .cmd = NL80211_CMD_GET_WOWLAN,
11428 .doit = nl80211_get_wowlan,
11429 .policy = nl80211_policy,
11430 /* can be retrieved by unprivileged users */
11431 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11432 NL80211_FLAG_NEED_RTNL,
11433 },
11434 {
11435 .cmd = NL80211_CMD_SET_WOWLAN,
11436 .doit = nl80211_set_wowlan,
11437 .policy = nl80211_policy,
11438 .flags = GENL_ADMIN_PERM,
11439 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11440 NL80211_FLAG_NEED_RTNL,
11441 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011442#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011443 {
11444 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11445 .doit = nl80211_set_rekey_data,
11446 .policy = nl80211_policy,
11447 .flags = GENL_ADMIN_PERM,
11448 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011449 NL80211_FLAG_NEED_RTNL |
11450 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011451 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011452 {
11453 .cmd = NL80211_CMD_TDLS_MGMT,
11454 .doit = nl80211_tdls_mgmt,
11455 .policy = nl80211_policy,
11456 .flags = GENL_ADMIN_PERM,
11457 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11458 NL80211_FLAG_NEED_RTNL,
11459 },
11460 {
11461 .cmd = NL80211_CMD_TDLS_OPER,
11462 .doit = nl80211_tdls_oper,
11463 .policy = nl80211_policy,
11464 .flags = GENL_ADMIN_PERM,
11465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11466 NL80211_FLAG_NEED_RTNL,
11467 },
Johannes Berg28946da2011-11-04 11:18:12 +010011468 {
11469 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11470 .doit = nl80211_register_unexpected_frame,
11471 .policy = nl80211_policy,
11472 .flags = GENL_ADMIN_PERM,
11473 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11474 NL80211_FLAG_NEED_RTNL,
11475 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011476 {
11477 .cmd = NL80211_CMD_PROBE_CLIENT,
11478 .doit = nl80211_probe_client,
11479 .policy = nl80211_policy,
11480 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011481 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011482 NL80211_FLAG_NEED_RTNL,
11483 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011484 {
11485 .cmd = NL80211_CMD_REGISTER_BEACONS,
11486 .doit = nl80211_register_beacons,
11487 .policy = nl80211_policy,
11488 .flags = GENL_ADMIN_PERM,
11489 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11490 NL80211_FLAG_NEED_RTNL,
11491 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011492 {
11493 .cmd = NL80211_CMD_SET_NOACK_MAP,
11494 .doit = nl80211_set_noack_map,
11495 .policy = nl80211_policy,
11496 .flags = GENL_ADMIN_PERM,
11497 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11498 NL80211_FLAG_NEED_RTNL,
11499 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011500 {
11501 .cmd = NL80211_CMD_START_P2P_DEVICE,
11502 .doit = nl80211_start_p2p_device,
11503 .policy = nl80211_policy,
11504 .flags = GENL_ADMIN_PERM,
11505 .internal_flags = NL80211_FLAG_NEED_WDEV |
11506 NL80211_FLAG_NEED_RTNL,
11507 },
11508 {
11509 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11510 .doit = nl80211_stop_p2p_device,
11511 .policy = nl80211_policy,
11512 .flags = GENL_ADMIN_PERM,
11513 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11514 NL80211_FLAG_NEED_RTNL,
11515 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011516 {
11517 .cmd = NL80211_CMD_SET_MCAST_RATE,
11518 .doit = nl80211_set_mcast_rate,
11519 .policy = nl80211_policy,
11520 .flags = GENL_ADMIN_PERM,
11521 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11522 NL80211_FLAG_NEED_RTNL,
11523 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011524 {
11525 .cmd = NL80211_CMD_SET_MAC_ACL,
11526 .doit = nl80211_set_mac_acl,
11527 .policy = nl80211_policy,
11528 .flags = GENL_ADMIN_PERM,
11529 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11530 NL80211_FLAG_NEED_RTNL,
11531 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011532 {
11533 .cmd = NL80211_CMD_RADAR_DETECT,
11534 .doit = nl80211_start_radar_detection,
11535 .policy = nl80211_policy,
11536 .flags = GENL_ADMIN_PERM,
11537 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11538 NL80211_FLAG_NEED_RTNL,
11539 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011540 {
11541 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11542 .doit = nl80211_get_protocol_features,
11543 .policy = nl80211_policy,
11544 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011545 {
11546 .cmd = NL80211_CMD_UPDATE_FT_IES,
11547 .doit = nl80211_update_ft_ies,
11548 .policy = nl80211_policy,
11549 .flags = GENL_ADMIN_PERM,
11550 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11551 NL80211_FLAG_NEED_RTNL,
11552 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011553 {
11554 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11555 .doit = nl80211_crit_protocol_start,
11556 .policy = nl80211_policy,
11557 .flags = GENL_ADMIN_PERM,
11558 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11559 NL80211_FLAG_NEED_RTNL,
11560 },
11561 {
11562 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11563 .doit = nl80211_crit_protocol_stop,
11564 .policy = nl80211_policy,
11565 .flags = GENL_ADMIN_PERM,
11566 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11567 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011568 },
11569 {
11570 .cmd = NL80211_CMD_GET_COALESCE,
11571 .doit = nl80211_get_coalesce,
11572 .policy = nl80211_policy,
11573 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11574 NL80211_FLAG_NEED_RTNL,
11575 },
11576 {
11577 .cmd = NL80211_CMD_SET_COALESCE,
11578 .doit = nl80211_set_coalesce,
11579 .policy = nl80211_policy,
11580 .flags = GENL_ADMIN_PERM,
11581 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11582 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011583 },
11584 {
11585 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11586 .doit = nl80211_channel_switch,
11587 .policy = nl80211_policy,
11588 .flags = GENL_ADMIN_PERM,
11589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11590 NL80211_FLAG_NEED_RTNL,
11591 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011592 {
11593 .cmd = NL80211_CMD_VENDOR,
11594 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011595 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011596 .policy = nl80211_policy,
11597 .flags = GENL_ADMIN_PERM,
11598 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11599 NL80211_FLAG_NEED_RTNL,
11600 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011601 {
11602 .cmd = NL80211_CMD_SET_QOS_MAP,
11603 .doit = nl80211_set_qos_map,
11604 .policy = nl80211_policy,
11605 .flags = GENL_ADMIN_PERM,
11606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11607 NL80211_FLAG_NEED_RTNL,
11608 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011609 {
11610 .cmd = NL80211_CMD_ADD_TX_TS,
11611 .doit = nl80211_add_tx_ts,
11612 .policy = nl80211_policy,
11613 .flags = GENL_ADMIN_PERM,
11614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11615 NL80211_FLAG_NEED_RTNL,
11616 },
11617 {
11618 .cmd = NL80211_CMD_DEL_TX_TS,
11619 .doit = nl80211_del_tx_ts,
11620 .policy = nl80211_policy,
11621 .flags = GENL_ADMIN_PERM,
11622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11623 NL80211_FLAG_NEED_RTNL,
11624 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011625 {
11626 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11627 .doit = nl80211_tdls_channel_switch,
11628 .policy = nl80211_policy,
11629 .flags = GENL_ADMIN_PERM,
11630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11631 NL80211_FLAG_NEED_RTNL,
11632 },
11633 {
11634 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11635 .doit = nl80211_tdls_cancel_channel_switch,
11636 .policy = nl80211_policy,
11637 .flags = GENL_ADMIN_PERM,
11638 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11639 NL80211_FLAG_NEED_RTNL,
11640 },
Johannes Berg55682962007-09-20 13:09:35 -040011641};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011642
Johannes Berg55682962007-09-20 13:09:35 -040011643/* notification functions */
11644
Johannes Berg3bb20552014-05-26 13:52:25 +020011645void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11646 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011647{
11648 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011649 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011650
Johannes Berg3bb20552014-05-26 13:52:25 +020011651 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11652 cmd != NL80211_CMD_DEL_WIPHY);
11653
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011654 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011655 if (!msg)
11656 return;
11657
Johannes Berg3bb20552014-05-26 13:52:25 +020011658 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011659 nlmsg_free(msg);
11660 return;
11661 }
11662
Johannes Berg68eb5502013-11-19 15:19:38 +010011663 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011664 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011665}
11666
Johannes Berg362a4152009-05-24 16:43:15 +020011667static int nl80211_add_scan_req(struct sk_buff *msg,
11668 struct cfg80211_registered_device *rdev)
11669{
11670 struct cfg80211_scan_request *req = rdev->scan_req;
11671 struct nlattr *nest;
11672 int i;
11673
11674 if (WARN_ON(!req))
11675 return 0;
11676
11677 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11678 if (!nest)
11679 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011680 for (i = 0; i < req->n_ssids; i++) {
11681 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11682 goto nla_put_failure;
11683 }
Johannes Berg362a4152009-05-24 16:43:15 +020011684 nla_nest_end(msg, nest);
11685
11686 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11687 if (!nest)
11688 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011689 for (i = 0; i < req->n_channels; i++) {
11690 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11691 goto nla_put_failure;
11692 }
Johannes Berg362a4152009-05-24 16:43:15 +020011693 nla_nest_end(msg, nest);
11694
David S. Miller9360ffd2012-03-29 04:41:26 -040011695 if (req->ie &&
11696 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11697 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011698
Johannes Bergae917c92013-10-25 11:05:22 +020011699 if (req->flags &&
11700 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11701 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011702
Johannes Berg362a4152009-05-24 16:43:15 +020011703 return 0;
11704 nla_put_failure:
11705 return -ENOBUFS;
11706}
11707
Johannes Berga538e2d2009-06-16 19:56:42 +020011708static int nl80211_send_scan_msg(struct sk_buff *msg,
11709 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011710 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011711 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011712 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011713{
11714 void *hdr;
11715
Eric W. Biederman15e47302012-09-07 20:12:54 +000011716 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011717 if (!hdr)
11718 return -1;
11719
David S. Miller9360ffd2012-03-29 04:41:26 -040011720 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011721 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11722 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011723 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11724 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011725 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011726
Johannes Berg362a4152009-05-24 16:43:15 +020011727 /* ignore errors and send incomplete event anyway */
11728 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011729
Johannes Berg053c0952015-01-16 22:09:00 +010011730 genlmsg_end(msg, hdr);
11731 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011732
11733 nla_put_failure:
11734 genlmsg_cancel(msg, hdr);
11735 return -EMSGSIZE;
11736}
11737
Luciano Coelho807f8a82011-05-11 17:09:35 +030011738static int
11739nl80211_send_sched_scan_msg(struct sk_buff *msg,
11740 struct cfg80211_registered_device *rdev,
11741 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011742 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011743{
11744 void *hdr;
11745
Eric W. Biederman15e47302012-09-07 20:12:54 +000011746 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011747 if (!hdr)
11748 return -1;
11749
David S. Miller9360ffd2012-03-29 04:41:26 -040011750 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11751 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11752 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011753
Johannes Berg053c0952015-01-16 22:09:00 +010011754 genlmsg_end(msg, hdr);
11755 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011756
11757 nla_put_failure:
11758 genlmsg_cancel(msg, hdr);
11759 return -EMSGSIZE;
11760}
11761
Johannes Berga538e2d2009-06-16 19:56:42 +020011762void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011763 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011764{
11765 struct sk_buff *msg;
11766
Thomas Graf58050fc2012-06-28 03:57:45 +000011767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011768 if (!msg)
11769 return;
11770
Johannes Bergfd014282012-06-18 19:17:03 +020011771 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011772 NL80211_CMD_TRIGGER_SCAN) < 0) {
11773 nlmsg_free(msg);
11774 return;
11775 }
11776
Johannes Berg68eb5502013-11-19 15:19:38 +010011777 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011778 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011779}
11780
Johannes Bergf9d15d12014-01-22 11:14:19 +020011781struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11782 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011783{
11784 struct sk_buff *msg;
11785
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011786 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011787 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011788 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011789
Johannes Bergfd014282012-06-18 19:17:03 +020011790 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011791 aborted ? NL80211_CMD_SCAN_ABORTED :
11792 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011793 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011794 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011795 }
11796
Johannes Bergf9d15d12014-01-22 11:14:19 +020011797 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011798}
11799
Johannes Bergf9d15d12014-01-22 11:14:19 +020011800void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11801 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011802{
Johannes Berg2a519312009-02-10 21:25:55 +010011803 if (!msg)
11804 return;
11805
Johannes Berg68eb5502013-11-19 15:19:38 +010011806 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011807 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011808}
11809
Luciano Coelho807f8a82011-05-11 17:09:35 +030011810void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11811 struct net_device *netdev)
11812{
11813 struct sk_buff *msg;
11814
11815 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11816 if (!msg)
11817 return;
11818
11819 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11820 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11821 nlmsg_free(msg);
11822 return;
11823 }
11824
Johannes Berg68eb5502013-11-19 15:19:38 +010011825 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011826 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011827}
11828
11829void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11830 struct net_device *netdev, u32 cmd)
11831{
11832 struct sk_buff *msg;
11833
Thomas Graf58050fc2012-06-28 03:57:45 +000011834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011835 if (!msg)
11836 return;
11837
11838 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11839 nlmsg_free(msg);
11840 return;
11841 }
11842
Johannes Berg68eb5502013-11-19 15:19:38 +010011843 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011844 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011845}
11846
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011847static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11848 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011849{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011850 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011851 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11852 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011853
David S. Miller9360ffd2012-03-29 04:41:26 -040011854 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11855 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11856 NL80211_REGDOM_TYPE_WORLD))
11857 goto nla_put_failure;
11858 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11859 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11860 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11861 goto nla_put_failure;
11862 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11863 request->intersect) {
11864 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11865 NL80211_REGDOM_TYPE_INTERSECTION))
11866 goto nla_put_failure;
11867 } else {
11868 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11869 NL80211_REGDOM_TYPE_COUNTRY) ||
11870 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11871 request->alpha2))
11872 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011873 }
11874
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011875 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11876 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11877
11878 if (wiphy &&
11879 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11880 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011881
11882 if (wiphy &&
11883 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11884 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11885 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011886 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011887
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011888 return true;
11889
11890nla_put_failure:
11891 return false;
11892}
11893
11894/*
11895 * This can happen on global regulatory changes or device specific settings
11896 * based on custom regulatory domains.
11897 */
11898void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11899 struct regulatory_request *request)
11900{
11901 struct sk_buff *msg;
11902 void *hdr;
11903
11904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11905 if (!msg)
11906 return;
11907
11908 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11909 if (!hdr) {
11910 nlmsg_free(msg);
11911 return;
11912 }
11913
11914 if (nl80211_reg_change_event_fill(msg, request) == false)
11915 goto nla_put_failure;
11916
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011917 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011918
Johannes Bergbc43b282009-07-25 10:54:13 +020011919 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011920 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011921 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011922 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011923
11924 return;
11925
11926nla_put_failure:
11927 genlmsg_cancel(msg, hdr);
11928 nlmsg_free(msg);
11929}
11930
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011931static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11932 struct net_device *netdev,
11933 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011934 enum nl80211_commands cmd, gfp_t gfp,
11935 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011936{
11937 struct sk_buff *msg;
11938 void *hdr;
11939
Johannes Berge6d6e342009-07-01 21:26:47 +020011940 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011941 if (!msg)
11942 return;
11943
11944 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11945 if (!hdr) {
11946 nlmsg_free(msg);
11947 return;
11948 }
11949
David S. Miller9360ffd2012-03-29 04:41:26 -040011950 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11951 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11952 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11953 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011954
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011955 if (uapsd_queues >= 0) {
11956 struct nlattr *nla_wmm =
11957 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11958 if (!nla_wmm)
11959 goto nla_put_failure;
11960
11961 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11962 uapsd_queues))
11963 goto nla_put_failure;
11964
11965 nla_nest_end(msg, nla_wmm);
11966 }
11967
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011968 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011969
Johannes Berg68eb5502013-11-19 15:19:38 +010011970 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011971 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011972 return;
11973
11974 nla_put_failure:
11975 genlmsg_cancel(msg, hdr);
11976 nlmsg_free(msg);
11977}
11978
11979void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011980 struct net_device *netdev, const u8 *buf,
11981 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011982{
11983 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011984 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011985}
11986
11987void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11988 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011989 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011990{
Johannes Berge6d6e342009-07-01 21:26:47 +020011991 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011992 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011993}
11994
Jouni Malinen53b46b82009-03-27 20:53:56 +020011995void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011996 struct net_device *netdev, const u8 *buf,
11997 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011998{
11999 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012000 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012001}
12002
Jouni Malinen53b46b82009-03-27 20:53:56 +020012003void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12004 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012005 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012006{
12007 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012008 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012009}
12010
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012011void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12012 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012013{
Johannes Berg947add32013-02-22 22:05:20 +010012014 struct wireless_dev *wdev = dev->ieee80211_ptr;
12015 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012016 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012017 const struct ieee80211_mgmt *mgmt = (void *)buf;
12018 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012019
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012020 if (WARN_ON(len < 2))
12021 return;
12022
12023 if (ieee80211_is_deauth(mgmt->frame_control))
12024 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12025 else
12026 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12027
12028 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012029 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012030}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012031EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012032
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012033static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12034 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012035 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012036{
12037 struct sk_buff *msg;
12038 void *hdr;
12039
Johannes Berge6d6e342009-07-01 21:26:47 +020012040 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012041 if (!msg)
12042 return;
12043
12044 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12045 if (!hdr) {
12046 nlmsg_free(msg);
12047 return;
12048 }
12049
David S. Miller9360ffd2012-03-29 04:41:26 -040012050 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12051 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12052 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12053 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12054 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012055
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012056 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012057
Johannes Berg68eb5502013-11-19 15:19:38 +010012058 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012059 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012060 return;
12061
12062 nla_put_failure:
12063 genlmsg_cancel(msg, hdr);
12064 nlmsg_free(msg);
12065}
12066
12067void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012068 struct net_device *netdev, const u8 *addr,
12069 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012070{
12071 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012072 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012073}
12074
12075void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012076 struct net_device *netdev, const u8 *addr,
12077 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012078{
Johannes Berge6d6e342009-07-01 21:26:47 +020012079 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12080 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012081}
12082
Samuel Ortizb23aa672009-07-01 21:26:54 +020012083void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12084 struct net_device *netdev, const u8 *bssid,
12085 const u8 *req_ie, size_t req_ie_len,
12086 const u8 *resp_ie, size_t resp_ie_len,
12087 u16 status, gfp_t gfp)
12088{
12089 struct sk_buff *msg;
12090 void *hdr;
12091
Thomas Graf58050fc2012-06-28 03:57:45 +000012092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012093 if (!msg)
12094 return;
12095
12096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12097 if (!hdr) {
12098 nlmsg_free(msg);
12099 return;
12100 }
12101
David S. Miller9360ffd2012-03-29 04:41:26 -040012102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12103 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12104 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
12105 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
12106 (req_ie &&
12107 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12108 (resp_ie &&
12109 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12110 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012111
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012112 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012113
Johannes Berg68eb5502013-11-19 15:19:38 +010012114 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012115 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012116 return;
12117
12118 nla_put_failure:
12119 genlmsg_cancel(msg, hdr);
12120 nlmsg_free(msg);
12121
12122}
12123
12124void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12125 struct net_device *netdev, const u8 *bssid,
12126 const u8 *req_ie, size_t req_ie_len,
12127 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12128{
12129 struct sk_buff *msg;
12130 void *hdr;
12131
Thomas Graf58050fc2012-06-28 03:57:45 +000012132 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012133 if (!msg)
12134 return;
12135
12136 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12137 if (!hdr) {
12138 nlmsg_free(msg);
12139 return;
12140 }
12141
David S. Miller9360ffd2012-03-29 04:41:26 -040012142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12143 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12144 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12145 (req_ie &&
12146 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12147 (resp_ie &&
12148 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12149 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012150
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012151 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012152
Johannes Berg68eb5502013-11-19 15:19:38 +010012153 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012154 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012155 return;
12156
12157 nla_put_failure:
12158 genlmsg_cancel(msg, hdr);
12159 nlmsg_free(msg);
12160
12161}
12162
12163void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12164 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012165 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012166{
12167 struct sk_buff *msg;
12168 void *hdr;
12169
Thomas Graf58050fc2012-06-28 03:57:45 +000012170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012171 if (!msg)
12172 return;
12173
12174 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12175 if (!hdr) {
12176 nlmsg_free(msg);
12177 return;
12178 }
12179
David S. Miller9360ffd2012-03-29 04:41:26 -040012180 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12181 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12182 (from_ap && reason &&
12183 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12184 (from_ap &&
12185 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12186 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12187 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012188
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012189 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012190
Johannes Berg68eb5502013-11-19 15:19:38 +010012191 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012192 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012193 return;
12194
12195 nla_put_failure:
12196 genlmsg_cancel(msg, hdr);
12197 nlmsg_free(msg);
12198
12199}
12200
Johannes Berg04a773a2009-04-19 21:24:32 +020012201void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12202 struct net_device *netdev, const u8 *bssid,
12203 gfp_t gfp)
12204{
12205 struct sk_buff *msg;
12206 void *hdr;
12207
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012208 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012209 if (!msg)
12210 return;
12211
12212 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12213 if (!hdr) {
12214 nlmsg_free(msg);
12215 return;
12216 }
12217
David S. Miller9360ffd2012-03-29 04:41:26 -040012218 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12219 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12220 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12221 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012222
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012223 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012224
Johannes Berg68eb5502013-11-19 15:19:38 +010012225 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012226 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012227 return;
12228
12229 nla_put_failure:
12230 genlmsg_cancel(msg, hdr);
12231 nlmsg_free(msg);
12232}
12233
Johannes Berg947add32013-02-22 22:05:20 +010012234void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12235 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012236{
Johannes Berg947add32013-02-22 22:05:20 +010012237 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012238 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012239 struct sk_buff *msg;
12240 void *hdr;
12241
Johannes Berg947add32013-02-22 22:05:20 +010012242 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12243 return;
12244
12245 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12246
Javier Cardonac93b5e72011-04-07 15:08:34 -070012247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12248 if (!msg)
12249 return;
12250
12251 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12252 if (!hdr) {
12253 nlmsg_free(msg);
12254 return;
12255 }
12256
David S. Miller9360ffd2012-03-29 04:41:26 -040012257 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012258 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12259 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012260 (ie_len && ie &&
12261 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12262 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012263
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012264 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012265
Johannes Berg68eb5502013-11-19 15:19:38 +010012266 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012267 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012268 return;
12269
12270 nla_put_failure:
12271 genlmsg_cancel(msg, hdr);
12272 nlmsg_free(msg);
12273}
Johannes Berg947add32013-02-22 22:05:20 +010012274EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012275
Jouni Malinena3b8b052009-03-27 21:59:49 +020012276void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12277 struct net_device *netdev, const u8 *addr,
12278 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012279 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012280{
12281 struct sk_buff *msg;
12282 void *hdr;
12283
Johannes Berge6d6e342009-07-01 21:26:47 +020012284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012285 if (!msg)
12286 return;
12287
12288 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12289 if (!hdr) {
12290 nlmsg_free(msg);
12291 return;
12292 }
12293
David S. Miller9360ffd2012-03-29 04:41:26 -040012294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12295 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12296 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12297 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12298 (key_id != -1 &&
12299 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12300 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12301 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012302
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012303 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012304
Johannes Berg68eb5502013-11-19 15:19:38 +010012305 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012306 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012307 return;
12308
12309 nla_put_failure:
12310 genlmsg_cancel(msg, hdr);
12311 nlmsg_free(msg);
12312}
12313
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012314void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12315 struct ieee80211_channel *channel_before,
12316 struct ieee80211_channel *channel_after)
12317{
12318 struct sk_buff *msg;
12319 void *hdr;
12320 struct nlattr *nl_freq;
12321
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012322 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012323 if (!msg)
12324 return;
12325
12326 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12327 if (!hdr) {
12328 nlmsg_free(msg);
12329 return;
12330 }
12331
12332 /*
12333 * Since we are applying the beacon hint to a wiphy we know its
12334 * wiphy_idx is valid
12335 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012336 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12337 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012338
12339 /* Before */
12340 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12341 if (!nl_freq)
12342 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012343 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012344 goto nla_put_failure;
12345 nla_nest_end(msg, nl_freq);
12346
12347 /* After */
12348 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12349 if (!nl_freq)
12350 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012351 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012352 goto nla_put_failure;
12353 nla_nest_end(msg, nl_freq);
12354
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012355 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012356
Johannes Berg463d0182009-07-14 00:33:35 +020012357 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012358 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012359 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012360 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012361
12362 return;
12363
12364nla_put_failure:
12365 genlmsg_cancel(msg, hdr);
12366 nlmsg_free(msg);
12367}
12368
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012369static void nl80211_send_remain_on_chan_event(
12370 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012371 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012372 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012373 unsigned int duration, gfp_t gfp)
12374{
12375 struct sk_buff *msg;
12376 void *hdr;
12377
12378 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12379 if (!msg)
12380 return;
12381
12382 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12383 if (!hdr) {
12384 nlmsg_free(msg);
12385 return;
12386 }
12387
David S. Miller9360ffd2012-03-29 04:41:26 -040012388 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012389 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12390 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012391 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12392 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012393 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012394 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12395 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012396 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12397 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012398 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012399
David S. Miller9360ffd2012-03-29 04:41:26 -040012400 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12401 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12402 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012403
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012404 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012405
Johannes Berg68eb5502013-11-19 15:19:38 +010012406 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012407 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012408 return;
12409
12410 nla_put_failure:
12411 genlmsg_cancel(msg, hdr);
12412 nlmsg_free(msg);
12413}
12414
Johannes Berg947add32013-02-22 22:05:20 +010012415void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12416 struct ieee80211_channel *chan,
12417 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012418{
Johannes Berg947add32013-02-22 22:05:20 +010012419 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012420 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012421
12422 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012423 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012424 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012425 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012426}
Johannes Berg947add32013-02-22 22:05:20 +010012427EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012428
Johannes Berg947add32013-02-22 22:05:20 +010012429void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12430 struct ieee80211_channel *chan,
12431 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012432{
Johannes Berg947add32013-02-22 22:05:20 +010012433 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012434 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012435
12436 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012437 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012438 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012439}
Johannes Berg947add32013-02-22 22:05:20 +010012440EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012441
Johannes Berg947add32013-02-22 22:05:20 +010012442void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12443 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012444{
Johannes Berg947add32013-02-22 22:05:20 +010012445 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012446 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012447 struct sk_buff *msg;
12448
Johannes Berg947add32013-02-22 22:05:20 +010012449 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12450
Thomas Graf58050fc2012-06-28 03:57:45 +000012451 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012452 if (!msg)
12453 return;
12454
Johannes Bergcf5ead82014-11-14 17:14:00 +010012455 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012456 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012457 nlmsg_free(msg);
12458 return;
12459 }
12460
Johannes Berg68eb5502013-11-19 15:19:38 +010012461 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012462 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012463}
Johannes Berg947add32013-02-22 22:05:20 +010012464EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012465
Johannes Bergcf5ead82014-11-14 17:14:00 +010012466void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12467 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012468{
Johannes Berg947add32013-02-22 22:05:20 +010012469 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012470 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012471 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012472 struct station_info empty_sinfo = {};
12473
12474 if (!sinfo)
12475 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012476
Johannes Berg947add32013-02-22 22:05:20 +010012477 trace_cfg80211_del_sta(dev, mac_addr);
12478
Thomas Graf58050fc2012-06-28 03:57:45 +000012479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012480 if (!msg)
12481 return;
12482
Johannes Bergcf5ead82014-11-14 17:14:00 +010012483 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012484 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012485 nlmsg_free(msg);
12486 return;
12487 }
12488
Johannes Berg68eb5502013-11-19 15:19:38 +010012489 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012490 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012491}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012492EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012493
Johannes Berg947add32013-02-22 22:05:20 +010012494void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12495 enum nl80211_connect_failed_reason reason,
12496 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012497{
Johannes Berg947add32013-02-22 22:05:20 +010012498 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012499 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012500 struct sk_buff *msg;
12501 void *hdr;
12502
12503 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12504 if (!msg)
12505 return;
12506
12507 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12508 if (!hdr) {
12509 nlmsg_free(msg);
12510 return;
12511 }
12512
12513 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12514 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12515 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12516 goto nla_put_failure;
12517
12518 genlmsg_end(msg, hdr);
12519
Johannes Berg68eb5502013-11-19 15:19:38 +010012520 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012521 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012522 return;
12523
12524 nla_put_failure:
12525 genlmsg_cancel(msg, hdr);
12526 nlmsg_free(msg);
12527}
Johannes Berg947add32013-02-22 22:05:20 +010012528EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012529
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012530static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12531 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012532{
12533 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012534 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012535 struct sk_buff *msg;
12536 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012537 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012538
Eric W. Biederman15e47302012-09-07 20:12:54 +000012539 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012540 return false;
12541
12542 msg = nlmsg_new(100, gfp);
12543 if (!msg)
12544 return true;
12545
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012546 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012547 if (!hdr) {
12548 nlmsg_free(msg);
12549 return true;
12550 }
12551
David S. Miller9360ffd2012-03-29 04:41:26 -040012552 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12553 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12554 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12555 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012556
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012557 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012558 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012559 return true;
12560
12561 nla_put_failure:
12562 genlmsg_cancel(msg, hdr);
12563 nlmsg_free(msg);
12564 return true;
12565}
12566
Johannes Berg947add32013-02-22 22:05:20 +010012567bool cfg80211_rx_spurious_frame(struct net_device *dev,
12568 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012569{
Johannes Berg947add32013-02-22 22:05:20 +010012570 struct wireless_dev *wdev = dev->ieee80211_ptr;
12571 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012572
Johannes Berg947add32013-02-22 22:05:20 +010012573 trace_cfg80211_rx_spurious_frame(dev, addr);
12574
12575 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12576 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12577 trace_cfg80211_return_bool(false);
12578 return false;
12579 }
12580 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12581 addr, gfp);
12582 trace_cfg80211_return_bool(ret);
12583 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012584}
Johannes Berg947add32013-02-22 22:05:20 +010012585EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12586
12587bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12588 const u8 *addr, gfp_t gfp)
12589{
12590 struct wireless_dev *wdev = dev->ieee80211_ptr;
12591 bool ret;
12592
12593 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12594
12595 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12596 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12597 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12598 trace_cfg80211_return_bool(false);
12599 return false;
12600 }
12601 ret = __nl80211_unexpected_frame(dev,
12602 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12603 addr, gfp);
12604 trace_cfg80211_return_bool(ret);
12605 return ret;
12606}
12607EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012608
Johannes Berg2e161f72010-08-12 15:38:38 +020012609int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012610 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012611 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012612 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012613{
Johannes Berg71bbc992012-06-15 15:30:18 +020012614 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012615 struct sk_buff *msg;
12616 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012617
12618 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12619 if (!msg)
12620 return -ENOMEM;
12621
Johannes Berg2e161f72010-08-12 15:38:38 +020012622 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012623 if (!hdr) {
12624 nlmsg_free(msg);
12625 return -ENOMEM;
12626 }
12627
David S. Miller9360ffd2012-03-29 04:41:26 -040012628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012629 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12630 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012631 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12632 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012633 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12634 (sig_dbm &&
12635 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012636 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12637 (flags &&
12638 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012639 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012640
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012641 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012642
Eric W. Biederman15e47302012-09-07 20:12:54 +000012643 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012644
12645 nla_put_failure:
12646 genlmsg_cancel(msg, hdr);
12647 nlmsg_free(msg);
12648 return -ENOBUFS;
12649}
12650
Johannes Berg947add32013-02-22 22:05:20 +010012651void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12652 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012653{
Johannes Berg947add32013-02-22 22:05:20 +010012654 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012655 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012656 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012657 struct sk_buff *msg;
12658 void *hdr;
12659
Johannes Berg947add32013-02-22 22:05:20 +010012660 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12661
Jouni Malinen026331c2010-02-15 12:53:10 +020012662 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12663 if (!msg)
12664 return;
12665
Johannes Berg2e161f72010-08-12 15:38:38 +020012666 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012667 if (!hdr) {
12668 nlmsg_free(msg);
12669 return;
12670 }
12671
David S. Miller9360ffd2012-03-29 04:41:26 -040012672 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012673 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12674 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012675 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12676 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012677 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012678 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12679 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012680 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12681 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012682
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012683 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012684
Johannes Berg68eb5502013-11-19 15:19:38 +010012685 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012686 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012687 return;
12688
12689 nla_put_failure:
12690 genlmsg_cancel(msg, hdr);
12691 nlmsg_free(msg);
12692}
Johannes Berg947add32013-02-22 22:05:20 +010012693EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012694
Johannes Berg5b97f492014-11-26 12:37:43 +010012695static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12696 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012697{
Johannes Berg947add32013-02-22 22:05:20 +010012698 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012699 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12700 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12701 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012702
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012703 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012704 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012705
Johannes Berg5b97f492014-11-26 12:37:43 +010012706 cb = (void **)msg->cb;
12707
12708 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12709 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012710 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012711 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012712 }
12713
David S. Miller9360ffd2012-03-29 04:41:26 -040012714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012716 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012717
Johannes Berg5b97f492014-11-26 12:37:43 +010012718 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012719 goto nla_put_failure;
12720
Johannes Berg5b97f492014-11-26 12:37:43 +010012721 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12722 if (!cb[1])
12723 goto nla_put_failure;
12724
12725 cb[2] = rdev;
12726
12727 return msg;
12728 nla_put_failure:
12729 nlmsg_free(msg);
12730 return NULL;
12731}
12732
12733static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12734{
12735 void **cb = (void **)msg->cb;
12736 struct cfg80211_registered_device *rdev = cb[2];
12737
12738 nla_nest_end(msg, cb[1]);
12739 genlmsg_end(msg, cb[0]);
12740
12741 memset(msg->cb, 0, sizeof(msg->cb));
12742
12743 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12744 NL80211_MCGRP_MLME, gfp);
12745}
12746
12747void cfg80211_cqm_rssi_notify(struct net_device *dev,
12748 enum nl80211_cqm_rssi_threshold_event rssi_event,
12749 gfp_t gfp)
12750{
12751 struct sk_buff *msg;
12752
12753 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12754
Johannes Berg98f03342014-11-26 12:42:02 +010012755 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12756 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12757 return;
12758
Johannes Berg5b97f492014-11-26 12:37:43 +010012759 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12760 if (!msg)
12761 return;
12762
David S. Miller9360ffd2012-03-29 04:41:26 -040012763 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12764 rssi_event))
12765 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012766
Johannes Berg5b97f492014-11-26 12:37:43 +010012767 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012768
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012769 return;
12770
12771 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012772 nlmsg_free(msg);
12773}
Johannes Berg947add32013-02-22 22:05:20 +010012774EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012775
Johannes Berg5b97f492014-11-26 12:37:43 +010012776void cfg80211_cqm_txe_notify(struct net_device *dev,
12777 const u8 *peer, u32 num_packets,
12778 u32 rate, u32 intvl, gfp_t gfp)
12779{
12780 struct sk_buff *msg;
12781
12782 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12783 if (!msg)
12784 return;
12785
12786 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12787 goto nla_put_failure;
12788
12789 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12790 goto nla_put_failure;
12791
12792 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12793 goto nla_put_failure;
12794
12795 cfg80211_send_cqm(msg, gfp);
12796 return;
12797
12798 nla_put_failure:
12799 nlmsg_free(msg);
12800}
12801EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12802
12803void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12804 const u8 *peer, u32 num_packets, gfp_t gfp)
12805{
12806 struct sk_buff *msg;
12807
12808 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12809
12810 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12811 if (!msg)
12812 return;
12813
12814 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12815 goto nla_put_failure;
12816
12817 cfg80211_send_cqm(msg, gfp);
12818 return;
12819
12820 nla_put_failure:
12821 nlmsg_free(msg);
12822}
12823EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12824
Johannes Berg98f03342014-11-26 12:42:02 +010012825void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12826{
12827 struct sk_buff *msg;
12828
12829 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12830 if (!msg)
12831 return;
12832
12833 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12834 goto nla_put_failure;
12835
12836 cfg80211_send_cqm(msg, gfp);
12837 return;
12838
12839 nla_put_failure:
12840 nlmsg_free(msg);
12841}
12842EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12843
Johannes Berg947add32013-02-22 22:05:20 +010012844static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12845 struct net_device *netdev, const u8 *bssid,
12846 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012847{
12848 struct sk_buff *msg;
12849 struct nlattr *rekey_attr;
12850 void *hdr;
12851
Thomas Graf58050fc2012-06-28 03:57:45 +000012852 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012853 if (!msg)
12854 return;
12855
12856 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12857 if (!hdr) {
12858 nlmsg_free(msg);
12859 return;
12860 }
12861
David S. Miller9360ffd2012-03-29 04:41:26 -040012862 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12863 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12864 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12865 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012866
12867 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12868 if (!rekey_attr)
12869 goto nla_put_failure;
12870
David S. Miller9360ffd2012-03-29 04:41:26 -040012871 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12872 NL80211_REPLAY_CTR_LEN, replay_ctr))
12873 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012874
12875 nla_nest_end(msg, rekey_attr);
12876
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012877 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012878
Johannes Berg68eb5502013-11-19 15:19:38 +010012879 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012880 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012881 return;
12882
12883 nla_put_failure:
12884 genlmsg_cancel(msg, hdr);
12885 nlmsg_free(msg);
12886}
12887
Johannes Berg947add32013-02-22 22:05:20 +010012888void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12889 const u8 *replay_ctr, gfp_t gfp)
12890{
12891 struct wireless_dev *wdev = dev->ieee80211_ptr;
12892 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012893 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012894
12895 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12896 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12897}
12898EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12899
12900static void
12901nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12902 struct net_device *netdev, int index,
12903 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012904{
12905 struct sk_buff *msg;
12906 struct nlattr *attr;
12907 void *hdr;
12908
Thomas Graf58050fc2012-06-28 03:57:45 +000012909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012910 if (!msg)
12911 return;
12912
12913 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12914 if (!hdr) {
12915 nlmsg_free(msg);
12916 return;
12917 }
12918
David S. Miller9360ffd2012-03-29 04:41:26 -040012919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12920 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12921 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012922
12923 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12924 if (!attr)
12925 goto nla_put_failure;
12926
David S. Miller9360ffd2012-03-29 04:41:26 -040012927 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12928 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12929 (preauth &&
12930 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12931 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012932
12933 nla_nest_end(msg, attr);
12934
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012935 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012936
Johannes Berg68eb5502013-11-19 15:19:38 +010012937 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012938 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012939 return;
12940
12941 nla_put_failure:
12942 genlmsg_cancel(msg, hdr);
12943 nlmsg_free(msg);
12944}
12945
Johannes Berg947add32013-02-22 22:05:20 +010012946void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12947 const u8 *bssid, bool preauth, gfp_t gfp)
12948{
12949 struct wireless_dev *wdev = dev->ieee80211_ptr;
12950 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012951 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012952
12953 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12954 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12955}
12956EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12957
12958static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12959 struct net_device *netdev,
12960 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012961 gfp_t gfp,
12962 enum nl80211_commands notif,
12963 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012964{
12965 struct sk_buff *msg;
12966 void *hdr;
12967
Thomas Graf58050fc2012-06-28 03:57:45 +000012968 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012969 if (!msg)
12970 return;
12971
Luciano Coelhof8d75522014-11-07 14:31:35 +020012972 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012973 if (!hdr) {
12974 nlmsg_free(msg);
12975 return;
12976 }
12977
Johannes Berg683b6d32012-11-08 21:25:48 +010012978 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12979 goto nla_put_failure;
12980
12981 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012982 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012983
Luciano Coelhof8d75522014-11-07 14:31:35 +020012984 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12985 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12986 goto nla_put_failure;
12987
Thomas Pedersen53145262012-04-06 13:35:47 -070012988 genlmsg_end(msg, hdr);
12989
Johannes Berg68eb5502013-11-19 15:19:38 +010012990 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012991 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012992 return;
12993
12994 nla_put_failure:
12995 genlmsg_cancel(msg, hdr);
12996 nlmsg_free(msg);
12997}
12998
Johannes Berg947add32013-02-22 22:05:20 +010012999void cfg80211_ch_switch_notify(struct net_device *dev,
13000 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013001{
Johannes Berg947add32013-02-22 22:05:20 +010013002 struct wireless_dev *wdev = dev->ieee80211_ptr;
13003 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013004 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013005
Simon Wunderliche487eae2013-11-21 18:19:51 +010013006 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013007
Simon Wunderliche487eae2013-11-21 18:19:51 +010013008 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013009
Michal Kazior9e0e2962014-01-29 14:22:27 +010013010 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013011 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013012 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13013 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013014}
13015EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13016
Luciano Coelhof8d75522014-11-07 14:31:35 +020013017void cfg80211_ch_switch_started_notify(struct net_device *dev,
13018 struct cfg80211_chan_def *chandef,
13019 u8 count)
13020{
13021 struct wireless_dev *wdev = dev->ieee80211_ptr;
13022 struct wiphy *wiphy = wdev->wiphy;
13023 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13024
13025 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13026
13027 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13028 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13029}
13030EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13031
Thomas Pedersen84f10702012-07-12 16:17:33 -070013032void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013033nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013034 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013035 enum nl80211_radar_event event,
13036 struct net_device *netdev, gfp_t gfp)
13037{
13038 struct sk_buff *msg;
13039 void *hdr;
13040
13041 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13042 if (!msg)
13043 return;
13044
13045 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13046 if (!hdr) {
13047 nlmsg_free(msg);
13048 return;
13049 }
13050
13051 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13052 goto nla_put_failure;
13053
13054 /* NOP and radar events don't need a netdev parameter */
13055 if (netdev) {
13056 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13057
13058 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013059 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13060 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013061 goto nla_put_failure;
13062 }
13063
13064 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13065 goto nla_put_failure;
13066
13067 if (nl80211_send_chandef(msg, chandef))
13068 goto nla_put_failure;
13069
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013070 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013071
Johannes Berg68eb5502013-11-19 15:19:38 +010013072 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013073 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013074 return;
13075
13076 nla_put_failure:
13077 genlmsg_cancel(msg, hdr);
13078 nlmsg_free(msg);
13079}
13080
Johannes Berg7f6cf312011-11-04 11:18:15 +010013081void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13082 u64 cookie, bool acked, gfp_t gfp)
13083{
13084 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013085 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013086 struct sk_buff *msg;
13087 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013088
Beni Lev4ee3e062012-08-27 12:49:39 +030013089 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13090
Thomas Graf58050fc2012-06-28 03:57:45 +000013091 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013092
Johannes Berg7f6cf312011-11-04 11:18:15 +010013093 if (!msg)
13094 return;
13095
13096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13097 if (!hdr) {
13098 nlmsg_free(msg);
13099 return;
13100 }
13101
David S. Miller9360ffd2012-03-29 04:41:26 -040013102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13103 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13104 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013105 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13106 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013107 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13108 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013109
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013110 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013111
Johannes Berg68eb5502013-11-19 15:19:38 +010013112 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013113 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013114 return;
13115
13116 nla_put_failure:
13117 genlmsg_cancel(msg, hdr);
13118 nlmsg_free(msg);
13119}
13120EXPORT_SYMBOL(cfg80211_probe_status);
13121
Johannes Berg5e7602302011-11-04 11:18:17 +010013122void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13123 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013124 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013125{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013126 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013127 struct sk_buff *msg;
13128 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013129 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013130
Beni Lev4ee3e062012-08-27 12:49:39 +030013131 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13132
Ben Greear37c73b52012-10-26 14:49:25 -070013133 spin_lock_bh(&rdev->beacon_registrations_lock);
13134 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13135 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13136 if (!msg) {
13137 spin_unlock_bh(&rdev->beacon_registrations_lock);
13138 return;
13139 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013140
Ben Greear37c73b52012-10-26 14:49:25 -070013141 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13142 if (!hdr)
13143 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013144
Ben Greear37c73b52012-10-26 14:49:25 -070013145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13146 (freq &&
13147 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13148 (sig_dbm &&
13149 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13150 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13151 goto nla_put_failure;
13152
13153 genlmsg_end(msg, hdr);
13154
13155 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013156 }
Ben Greear37c73b52012-10-26 14:49:25 -070013157 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013158 return;
13159
13160 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013161 spin_unlock_bh(&rdev->beacon_registrations_lock);
13162 if (hdr)
13163 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013164 nlmsg_free(msg);
13165}
13166EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13167
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013168#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013169static int cfg80211_net_detect_results(struct sk_buff *msg,
13170 struct cfg80211_wowlan_wakeup *wakeup)
13171{
13172 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13173 struct nlattr *nl_results, *nl_match, *nl_freqs;
13174 int i, j;
13175
13176 nl_results = nla_nest_start(
13177 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13178 if (!nl_results)
13179 return -EMSGSIZE;
13180
13181 for (i = 0; i < nd->n_matches; i++) {
13182 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13183
13184 nl_match = nla_nest_start(msg, i);
13185 if (!nl_match)
13186 break;
13187
13188 /* The SSID attribute is optional in nl80211, but for
13189 * simplicity reasons it's always present in the
13190 * cfg80211 structure. If a driver can't pass the
13191 * SSID, that needs to be changed. A zero length SSID
13192 * is still a valid SSID (wildcard), so it cannot be
13193 * used for this purpose.
13194 */
13195 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13196 match->ssid.ssid)) {
13197 nla_nest_cancel(msg, nl_match);
13198 goto out;
13199 }
13200
13201 if (match->n_channels) {
13202 nl_freqs = nla_nest_start(
13203 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13204 if (!nl_freqs) {
13205 nla_nest_cancel(msg, nl_match);
13206 goto out;
13207 }
13208
13209 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013210 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013211 nla_nest_cancel(msg, nl_freqs);
13212 nla_nest_cancel(msg, nl_match);
13213 goto out;
13214 }
13215 }
13216
13217 nla_nest_end(msg, nl_freqs);
13218 }
13219
13220 nla_nest_end(msg, nl_match);
13221 }
13222
13223out:
13224 nla_nest_end(msg, nl_results);
13225 return 0;
13226}
13227
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013228void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13229 struct cfg80211_wowlan_wakeup *wakeup,
13230 gfp_t gfp)
13231{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013232 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013233 struct sk_buff *msg;
13234 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013235 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013236
13237 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13238
13239 if (wakeup)
13240 size += wakeup->packet_present_len;
13241
13242 msg = nlmsg_new(size, gfp);
13243 if (!msg)
13244 return;
13245
13246 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13247 if (!hdr)
13248 goto free_msg;
13249
13250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013251 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13252 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013253 goto free_msg;
13254
13255 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13256 wdev->netdev->ifindex))
13257 goto free_msg;
13258
13259 if (wakeup) {
13260 struct nlattr *reasons;
13261
13262 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013263 if (!reasons)
13264 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013265
13266 if (wakeup->disconnect &&
13267 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13268 goto free_msg;
13269 if (wakeup->magic_pkt &&
13270 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13271 goto free_msg;
13272 if (wakeup->gtk_rekey_failure &&
13273 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13274 goto free_msg;
13275 if (wakeup->eap_identity_req &&
13276 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13277 goto free_msg;
13278 if (wakeup->four_way_handshake &&
13279 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13280 goto free_msg;
13281 if (wakeup->rfkill_release &&
13282 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13283 goto free_msg;
13284
13285 if (wakeup->pattern_idx >= 0 &&
13286 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13287 wakeup->pattern_idx))
13288 goto free_msg;
13289
Johannes Bergae917c92013-10-25 11:05:22 +020013290 if (wakeup->tcp_match &&
13291 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13292 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013293
Johannes Bergae917c92013-10-25 11:05:22 +020013294 if (wakeup->tcp_connlost &&
13295 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13296 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013297
Johannes Bergae917c92013-10-25 11:05:22 +020013298 if (wakeup->tcp_nomoretokens &&
13299 nla_put_flag(msg,
13300 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13301 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013302
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013303 if (wakeup->packet) {
13304 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13305 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13306
13307 if (!wakeup->packet_80211) {
13308 pkt_attr =
13309 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13310 len_attr =
13311 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13312 }
13313
13314 if (wakeup->packet_len &&
13315 nla_put_u32(msg, len_attr, wakeup->packet_len))
13316 goto free_msg;
13317
13318 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13319 wakeup->packet))
13320 goto free_msg;
13321 }
13322
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013323 if (wakeup->net_detect &&
13324 cfg80211_net_detect_results(msg, wakeup))
13325 goto free_msg;
13326
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013327 nla_nest_end(msg, reasons);
13328 }
13329
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013330 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013331
Johannes Berg68eb5502013-11-19 15:19:38 +010013332 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013333 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013334 return;
13335
13336 free_msg:
13337 nlmsg_free(msg);
13338}
13339EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13340#endif
13341
Jouni Malinen3475b092012-11-16 22:49:57 +020013342void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13343 enum nl80211_tdls_operation oper,
13344 u16 reason_code, gfp_t gfp)
13345{
13346 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013347 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013348 struct sk_buff *msg;
13349 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013350
13351 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13352 reason_code);
13353
13354 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13355 if (!msg)
13356 return;
13357
13358 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13359 if (!hdr) {
13360 nlmsg_free(msg);
13361 return;
13362 }
13363
13364 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13365 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13366 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13367 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13368 (reason_code > 0 &&
13369 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13370 goto nla_put_failure;
13371
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013372 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013373
Johannes Berg68eb5502013-11-19 15:19:38 +010013374 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013375 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013376 return;
13377
13378 nla_put_failure:
13379 genlmsg_cancel(msg, hdr);
13380 nlmsg_free(msg);
13381}
13382EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13383
Jouni Malinen026331c2010-02-15 12:53:10 +020013384static int nl80211_netlink_notify(struct notifier_block * nb,
13385 unsigned long state,
13386 void *_notify)
13387{
13388 struct netlink_notify *notify = _notify;
13389 struct cfg80211_registered_device *rdev;
13390 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013391 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013392
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013393 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013394 return NOTIFY_DONE;
13395
13396 rcu_read_lock();
13397
Johannes Berg5e7602302011-11-04 11:18:17 +010013398 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013399 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013400 bool schedule_scan_stop = false;
13401 struct cfg80211_sched_scan_request *sched_scan_req =
13402 rcu_dereference(rdev->sched_scan_req);
13403
13404 if (sched_scan_req && notify->portid &&
13405 sched_scan_req->owner_nlportid == notify->portid)
13406 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013407
13408 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013409 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013410
Johannes Berg78f22b62014-03-24 17:57:27 +010013411 if (wdev->owner_nlportid == notify->portid)
13412 schedule_destroy_work = true;
13413 }
13414
Ben Greear37c73b52012-10-26 14:49:25 -070013415 spin_lock_bh(&rdev->beacon_registrations_lock);
13416 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13417 list) {
13418 if (reg->nlportid == notify->portid) {
13419 list_del(&reg->list);
13420 kfree(reg);
13421 break;
13422 }
13423 }
13424 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013425
13426 if (schedule_destroy_work) {
13427 struct cfg80211_iface_destroy *destroy;
13428
13429 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13430 if (destroy) {
13431 destroy->nlportid = notify->portid;
13432 spin_lock(&rdev->destroy_list_lock);
13433 list_add(&destroy->list, &rdev->destroy_list);
13434 spin_unlock(&rdev->destroy_list_lock);
13435 schedule_work(&rdev->destroy_work);
13436 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013437 } else if (schedule_scan_stop) {
13438 sched_scan_req->owner_nlportid = 0;
13439
13440 if (rdev->ops->sched_scan_stop &&
13441 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13442 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013443 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013444 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013445
13446 rcu_read_unlock();
13447
Ilan peer05050752015-03-04 00:32:06 -050013448 /*
13449 * It is possible that the user space process that is controlling the
13450 * indoor setting disappeared, so notify the regulatory core.
13451 */
13452 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013453 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013454}
13455
13456static struct notifier_block nl80211_netlink_notifier = {
13457 .notifier_call = nl80211_netlink_notify,
13458};
13459
Jouni Malinen355199e2013-02-27 17:14:27 +020013460void cfg80211_ft_event(struct net_device *netdev,
13461 struct cfg80211_ft_event_params *ft_event)
13462{
13463 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013464 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013465 struct sk_buff *msg;
13466 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013467
13468 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13469
13470 if (!ft_event->target_ap)
13471 return;
13472
13473 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13474 if (!msg)
13475 return;
13476
13477 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013478 if (!hdr)
13479 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013480
Johannes Bergae917c92013-10-25 11:05:22 +020013481 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13482 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13483 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13484 goto out;
13485
13486 if (ft_event->ies &&
13487 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13488 goto out;
13489 if (ft_event->ric_ies &&
13490 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13491 ft_event->ric_ies))
13492 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013493
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013494 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013495
Johannes Berg68eb5502013-11-19 15:19:38 +010013496 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013497 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013498 return;
13499 out:
13500 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013501}
13502EXPORT_SYMBOL(cfg80211_ft_event);
13503
Arend van Spriel5de17982013-04-18 15:49:00 +020013504void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13505{
13506 struct cfg80211_registered_device *rdev;
13507 struct sk_buff *msg;
13508 void *hdr;
13509 u32 nlportid;
13510
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013511 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013512 if (!rdev->crit_proto_nlportid)
13513 return;
13514
13515 nlportid = rdev->crit_proto_nlportid;
13516 rdev->crit_proto_nlportid = 0;
13517
13518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13519 if (!msg)
13520 return;
13521
13522 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13523 if (!hdr)
13524 goto nla_put_failure;
13525
13526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013527 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13528 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013529 goto nla_put_failure;
13530
13531 genlmsg_end(msg, hdr);
13532
13533 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13534 return;
13535
13536 nla_put_failure:
13537 if (hdr)
13538 genlmsg_cancel(msg, hdr);
13539 nlmsg_free(msg);
13540
13541}
13542EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13543
Johannes Berg348baf02014-01-24 14:06:29 +010013544void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13545{
13546 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013547 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013548 struct sk_buff *msg;
13549 void *hdr;
13550
13551 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13552 if (!msg)
13553 return;
13554
13555 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13556 if (!hdr)
13557 goto out;
13558
13559 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13560 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013561 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13562 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013563 goto out;
13564
13565 genlmsg_end(msg, hdr);
13566
13567 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13568 NL80211_MCGRP_MLME, GFP_KERNEL);
13569 return;
13570 out:
13571 nlmsg_free(msg);
13572}
13573
Johannes Berg55682962007-09-20 13:09:35 -040013574/* initialisation/exit functions */
13575
13576int nl80211_init(void)
13577{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013578 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013579
Johannes Berg2a94fe42013-11-19 15:19:39 +010013580 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13581 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013582 if (err)
13583 return err;
13584
Jouni Malinen026331c2010-02-15 12:53:10 +020013585 err = netlink_register_notifier(&nl80211_netlink_notifier);
13586 if (err)
13587 goto err_out;
13588
Johannes Berg55682962007-09-20 13:09:35 -040013589 return 0;
13590 err_out:
13591 genl_unregister_family(&nl80211_fam);
13592 return err;
13593}
13594
13595void nl80211_exit(void)
13596{
Jouni Malinen026331c2010-02-15 12:53:10 +020013597 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013598 genl_unregister_family(&nl80211_fam);
13599}